Skip to content

Commit d88a63f

Browse files
committed
Wait for all sources to wake up before querying them
1 parent 613957d commit d88a63f

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

cmd/auth_client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ func AuthenticatedChangesClient(ctx context.Context) sdpconnect.ChangesServiceCl
6363
return sdpconnect.NewChangesServiceClient(httpClient, url)
6464
}
6565

66+
// AuthenticatedManagementClient Returns a bookmark client that uses the auth
67+
// embedded in the context and otel instrumentation
68+
func AuthenticatedManagementClient(ctx context.Context) sdpconnect.ManagementServiceClient {
69+
httpClient := NewAuthenticatedClient(ctx, otelhttp.DefaultClient)
70+
url := viper.GetString("management-url")
71+
if url == "" {
72+
url = viper.GetString("url")
73+
viper.Set("management-url", url)
74+
}
75+
log.WithContext(ctx).WithField("management-url", url).Debug("Connecting to overmind management API")
76+
return sdpconnect.NewManagementServiceClient(httpClient, url)
77+
}
78+
6679
// AuthenticatedSnapshotsClient Returns a Snapshots client that uses the auth
6780
// embedded in the context and otel instrumentation
6881
func AuthenticatedSnapshotsClient(ctx context.Context) sdpconnect.SnapshotsServiceClient {

cmd/manualchange.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ func ManualChange(signals chan os.Signal, ready chan bool) int {
123123
return 1
124124
}
125125

126+
mgmtClient := AuthenticatedManagementClient(ctx)
127+
log.WithContext(ctx).WithFields(lf).Info("Waking up sources")
128+
_, err = mgmtClient.KeepaliveSources(ctx, &connect.Request[sdp.KeepaliveSourcesRequest]{
129+
Msg: &sdp.KeepaliveSourcesRequest{
130+
WaitForHealthy: true,
131+
},
132+
})
133+
if err != nil {
134+
log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to wake up sources")
135+
return 1
136+
}
126137
u := uuid.New()
127138

128139
queries := []*sdp.Query{
@@ -372,6 +383,7 @@ func init() {
372383
rootCmd.AddCommand(manualChangeCmd)
373384

374385
manualChangeCmd.PersistentFlags().String("changes-url", "", "The changes service API endpoint (defaults to --url)")
386+
manualChangeCmd.PersistentFlags().String("management-url", "", "The management service API endpoint (defaults to --url)")
375387
manualChangeCmd.PersistentFlags().String("frontend", "https://app.overmind.tech", "The frontend base URL")
376388

377389
manualChangeCmd.PersistentFlags().String("title", "", "Short title for this change.")

cmd/request.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"syscall"
1111
"time"
1212

13+
"github.com/bufbuild/connect-go"
1314
"github.com/google/uuid"
1415
"github.com/overmindtech/ovm-cli/tracing"
1516
"github.com/overmindtech/sdp-go"
@@ -84,6 +85,18 @@ func Request(signals chan os.Signal, ready chan bool) int {
8485
ctx, cancel := context.WithTimeout(ctx, timeout)
8586
defer cancel()
8687

88+
mgmtClient := AuthenticatedManagementClient(ctx)
89+
log.WithContext(ctx).WithFields(lf).Info("Waking up sources")
90+
_, err = mgmtClient.KeepaliveSources(ctx, &connect.Request[sdp.KeepaliveSourcesRequest]{
91+
Msg: &sdp.KeepaliveSourcesRequest{
92+
WaitForHealthy: true,
93+
},
94+
})
95+
if err != nil {
96+
log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to wake up sources")
97+
return 1
98+
}
99+
87100
options := &websocket.DialOptions{
88101
HTTPClient: NewAuthenticatedClient(ctx, otelhttp.DefaultClient),
89102
}

cmd/submitplan.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,18 @@ func SubmitPlan(signals chan os.Signal, files []string, ready chan bool) int {
443443
receivedItems := make([]*sdp.Item, 0)
444444

445445
if len(planMappings.Queries()) > 0 {
446+
mgmtClient := AuthenticatedManagementClient(ctx)
447+
log.WithContext(ctx).WithFields(lf).Info("Waking up sources")
448+
_, err = mgmtClient.KeepaliveSources(ctx, &connect.Request[sdp.KeepaliveSourcesRequest]{
449+
Msg: &sdp.KeepaliveSourcesRequest{
450+
WaitForHealthy: true,
451+
},
452+
})
453+
if err != nil {
454+
log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to wake up sources")
455+
return 1
456+
}
457+
446458
options := &websocket.DialOptions{
447459
HTTPClient: NewAuthenticatedClient(ctx, otelhttp.DefaultClient),
448460
}
@@ -756,6 +768,7 @@ func init() {
756768
rootCmd.AddCommand(submitPlanCmd)
757769

758770
submitPlanCmd.PersistentFlags().String("changes-url", "", "The changes service API endpoint (defaults to --url)")
771+
submitPlanCmd.PersistentFlags().String("management-url", "", "The management service API endpoint (defaults to --url)")
759772
submitPlanCmd.PersistentFlags().String("frontend", "https://app.overmind.tech", "The frontend base URL")
760773

761774
submitPlanCmd.PersistentFlags().String("title", "", "Short title for this change. If this is not specified, ovm-cli will try to come up with one for you.")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/getsentry/sentry-go v0.23.0
88
github.com/google/uuid v1.3.1
99
github.com/mattn/go-isatty v0.0.19
10-
github.com/overmindtech/sdp-go v0.49.0
10+
github.com/overmindtech/sdp-go v0.49.3
1111
github.com/sirupsen/logrus v1.9.3
1212
github.com/spf13/cobra v1.7.0
1313
github.com/spf13/viper v1.16.0
@@ -44,7 +44,7 @@ require (
4444
github.com/magiconair/properties v1.8.7 // indirect
4545
github.com/mitchellh/mapstructure v1.5.0 // indirect
4646
github.com/nats-io/nats-server/v2 v2.9.22 // indirect
47-
github.com/nats-io/nats.go v1.28.0 // indirect
47+
github.com/nats-io/nats.go v1.29.0 // indirect
4848
github.com/nats-io/nkeys v0.4.4 // indirect
4949
github.com/nats-io/nuid v1.0.1 // indirect
5050
github.com/pelletier/go-toml/v2 v2.0.8 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ github.com/nats-io/jwt/v2 v2.5.0 h1:WQQ40AAlqqfx+f6ku+i0pOVm+ASirD4fUh+oQsiE9Ak=
243243
github.com/nats-io/jwt/v2 v2.5.0/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI=
244244
github.com/nats-io/nats-server/v2 v2.9.22 h1:rzl88pqWFFrU4G00ed+JnY+uGHSLZ+3jrxDnJxzKwGA=
245245
github.com/nats-io/nats-server/v2 v2.9.22/go.mod h1:wEjrEy9vnqIGE4Pqz4/c75v9Pmaq7My2IgFmnykc4C0=
246-
github.com/nats-io/nats.go v1.28.0 h1:Th4G6zdsz2d0OqXdfzKLClo6bOfoI/b1kInhRtFIy5c=
247-
github.com/nats-io/nats.go v1.28.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc=
246+
github.com/nats-io/nats.go v1.29.0 h1:dSXZ+SZeGyTdHVYeXimeq12FsIpb9dM8CJ2IZFiHcyE=
247+
github.com/nats-io/nats.go v1.29.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc=
248248
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
249249
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
250250
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
251251
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
252-
github.com/overmindtech/sdp-go v0.49.0 h1:m2NoNdodPM5xrcfaBP+Df67JCmEbWcwh60SWq2joiWQ=
253-
github.com/overmindtech/sdp-go v0.49.0/go.mod h1:Eg/OSql8z1N7kZej0i0AHYMoApMJHmjMBE2gWUsTsN8=
252+
github.com/overmindtech/sdp-go v0.49.3 h1:j6SwPi9Lkxv8X631/zp/mEsFOGutRN7rr2f6QxqqAYs=
253+
github.com/overmindtech/sdp-go v0.49.3/go.mod h1:q2RBDqmPidIQsYa9g/6nqOeJAyM6j3zgxn94GPCJcF8=
254254
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
255255
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
256256
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=

0 commit comments

Comments
 (0)