Skip to content

Commit 3d5af37

Browse files
Merge branch '117-observe' into 'master'
feat: CI observer, PoC ("dblab clone observe", "dblab clone observe-summary") See merge request postgres-ai/database-lab!91
2 parents 2ed0bb8 + 236ef63 commit 3d5af37

File tree

8 files changed

+472
-2
lines changed

8 files changed

+472
-2
lines changed

.gitlab-ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build-binary-generic:
3333
stage: build-binary
3434
only:
3535
refs:
36-
- master
36+
- branches
3737
- tags
3838
artifacts:
3939
paths:
@@ -100,6 +100,19 @@ build-image-feature-client:
100100
before_script:
101101
- cp ./bin/dblab-alpine ./bin/dblab
102102

103+
build-image-feature-client-extended:
104+
<<: *build_image_definition
105+
<<: *only_feature
106+
variables:
107+
REGISTRY_USER: "${CI_REGISTRY_USER}"
108+
REGISTRY_PASSWORD: "${CI_REGISTRY_PASSWORD}"
109+
REGISTRY: "${CI_REGISTRY}"
110+
DOCKER_FILE: "Dockerfile.dblab-extended"
111+
DOCKER_NAME: "registry.gitlab.com/postgres-ai/database-lab/dblab-extended"
112+
TAGS: "${DOCKER_NAME}:${CI_COMMIT_REF_SLUG}"
113+
before_script:
114+
- cp ./bin/dblab-linux-amd64 ./bin/dblab
115+
103116
build-image-master-server:
104117
<<: *build_image_definition
105118
<<: *only_master

Dockerfile.dblab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM docker:19
22

3-
# Install dependecies.
3+
# Install dependencies.
44
RUN apk update && apk add --no-cache bash jq
55

66
WORKDIR /home/dblab

Dockerfile.dblab-extended

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Currently (at PoC stage), the only DB migration tool that is supported is sqitch.org
2+
# This "extended" image is supposed to have many other tools in the future (liqubase, flyway, etc.)
3+
FROM sqitch/sqitch:1.0.0
4+
5+
USER root
6+
7+
# Install dependencies.
8+
RUN apt-get update && apt-get -y install bash jq
9+
10+
WORKDIR /home/dblab
11+
COPY ./bin/dblab ./bin/dblab
12+
RUN mv ./bin/dblab /usr/local/bin/dblab 2> /dev/null
13+
14+
ENTRYPOINT []
15+
CMD ./bin/dblab

cmd/cli/commands/clone/actions.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ package clone
88
import (
99
"encoding/json"
1010
"fmt"
11+
"os"
1112

1213
"github.com/urfave/cli/v2"
1314

1415
"gitlab.com/postgres-ai/database-lab/cmd/cli/commands"
1516
"gitlab.com/postgres-ai/database-lab/pkg/client/dblabapi/types"
1617
"gitlab.com/postgres-ai/database-lab/pkg/models"
18+
"gitlab.com/postgres-ai/database-lab/pkg/observer"
19+
)
20+
21+
const (
22+
errorExitStatus = 1
1723
)
1824

1925
// list runs a request to list clones of an instance.
@@ -190,3 +196,56 @@ func destroy() func(*cli.Context) error {
190196
return err
191197
}
192198
}
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+
}

cmd/cli/commands/clone/command_list.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,52 @@ func CommandList() []*cli.Command {
109109
},
110110
},
111111
},
112+
{
113+
Name: "observe",
114+
Usage: "[EXPERIMENTAL] monitor clone state",
115+
ArgsUsage: "CLONE_ID",
116+
Before: checkCloneIDBefore,
117+
Action: observe(),
118+
Flags: []cli.Flag{
119+
&cli.StringFlag{
120+
Name: "password",
121+
Usage: "clone database password",
122+
EnvVars: []string{"CLONE_PASSWORD"},
123+
Required: true,
124+
},
125+
&cli.StringFlag{
126+
Name: "sslmode",
127+
Usage: "connection SSL mode",
128+
EnvVars: []string{"SSLMODE"},
129+
Value: "disable",
130+
},
131+
&cli.BoolFlag{
132+
Name: "follow",
133+
Usage: "follow state monitor output",
134+
Aliases: []string{"f"},
135+
},
136+
&cli.IntFlag{
137+
Name: "interval-seconds",
138+
Usage: "interval of metric gathering and output",
139+
EnvVars: []string{"DBLAB_INTERVAL_SECONDS"},
140+
},
141+
&cli.IntFlag{
142+
Name: "max-lock-duration-seconds",
143+
Usage: "maximum allowed duration for locks",
144+
EnvVars: []string{"DBLAB_MAX_LOCK_DURATION_SECONDS"},
145+
},
146+
&cli.IntFlag{
147+
Name: "max-duration-seconds",
148+
Usage: "maximum allowed duration for operation",
149+
EnvVars: []string{"DBLAB_MAX_DURATION_SECONDS"},
150+
},
151+
},
152+
},
153+
{
154+
Name: "observe-summary",
155+
Usage: "[EXPERIMENTAL] summarize clone monitoring and check results",
156+
Action: observeSummary(),
157+
},
112158
},
113159
}}
114160
}

0 commit comments

Comments
 (0)