@@ -8,12 +8,18 @@ package clone
8
8
import (
9
9
"encoding/json"
10
10
"fmt"
11
+ "os"
11
12
12
13
"github.com/urfave/cli/v2"
13
14
14
15
"gitlab.com/postgres-ai/database-lab/cmd/cli/commands"
15
16
"gitlab.com/postgres-ai/database-lab/pkg/client/dblabapi/types"
16
17
"gitlab.com/postgres-ai/database-lab/pkg/models"
18
+ "gitlab.com/postgres-ai/database-lab/pkg/observer"
19
+ )
20
+
21
+ const (
22
+ errorExitStatus = 1
17
23
)
18
24
19
25
// list runs a request to list clones of an instance.
@@ -190,3 +196,56 @@ func destroy() func(*cli.Context) error {
190
196
return err
191
197
}
192
198
}
199
+
200
+ // observe runs a request to observe clone.
201
+ func observe () func (* cli.Context ) error {
202
+ return func (cliCtx * cli.Context ) error {
203
+ dblabClient , err := commands .ClientByCLIContext (cliCtx )
204
+ if err != nil {
205
+ return err
206
+ }
207
+
208
+ cloneID := cliCtx .Args ().First ()
209
+
210
+ clone , err := dblabClient .GetClone (cliCtx .Context , cloneID )
211
+ if err != nil {
212
+ return err
213
+ }
214
+
215
+ obsConfig := observer.Config {
216
+ Follow : cliCtx .Bool ("follow" ),
217
+ IntervalSeconds : cliCtx .Uint64 ("interval-seconds" ),
218
+ MaxLockDurationSeconds : cliCtx .Uint64 ("max-lock-duration-seconds" ),
219
+ MaxDurationSeconds : cliCtx .Uint64 ("max-duration-seconds" ),
220
+ SSLMode : cliCtx .String ("sslmode" ),
221
+ }
222
+
223
+ obs := observer .NewObserver (obsConfig , cliCtx .App .Writer )
224
+
225
+ clone .DB .Password = cliCtx .String ("password" )
226
+
227
+ return obs .Start (clone )
228
+ }
229
+ }
230
+
231
+ // observeSummary shows observing summary and check satisfaction of performance requirements.
232
+ func observeSummary () func (* cli.Context ) error {
233
+ return func (cliCtx * cli.Context ) error {
234
+ obs := observer .NewObserver (observer.Config {}, cliCtx .App .Writer )
235
+
236
+ if err := obs .LoadObserverState (); err != nil {
237
+ return err
238
+ }
239
+
240
+ if err := obs .PrintSummary (); err != nil {
241
+ return err
242
+ }
243
+
244
+ if err := obs .CheckPerformanceRequirements (); err != nil {
245
+ // Exit with error status without printing additional error logs.
246
+ os .Exit (errorExitStatus )
247
+ }
248
+
249
+ return nil
250
+ }
251
+ }
0 commit comments