Skip to content

Commit e83799e

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
# Conflicts: # go.sum # internal/replay.go
2 parents 7dd9487 + ea7646e commit e83799e

File tree

6 files changed

+45
-26
lines changed

6 files changed

+45
-26
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GOLANGCI_LINT_VERSION := v1.62.2
2121
# renovate datasource=go depName=golang.org/x/vuln/cmd/govulncheck
2222
GOVULNCHECK_VERSION := v1.1.3
2323
# renovate datasource=go depName=golang.org/x/tools/cmd/goimports
24-
GOIMPORTS_VERSION := v0.27.0
24+
GOIMPORTS_VERSION := v0.28.0
2525

2626
# Check if the program is present in $PATH and install otherwise.
2727
# ${1} - oneOf{binary,yarn}

cspell.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ words:
4444
- slos
4545
- svcs
4646
- tpng
47+
- unmarshalling
4748
- vuln
4849
- vulns
4950
- wrapf

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/schollz/progressbar/v3 v3.17.1
1212
github.com/spf13/cobra v1.8.1
1313
github.com/stretchr/testify v1.10.0
14-
golang.org/x/sync v0.9.0
14+
golang.org/x/sync v0.10.0
1515
)
1616

1717
require (

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
8686
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
8787
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
8888
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
89-
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
90-
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
89+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
90+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
9191
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9292
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9393
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=

internal/apply.go

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (a ApplyCmd) runReplay(cmd *cobra.Command, objects []manifest.Object) error
107107
return nil
108108
}
109109
replayCmd := ReplayCmd{client: a.client}
110+
replayCmd.arePlaylistEnabled(cmd.Context())
110111
replays := make([]ReplayConfig, 0, len(slos))
111112
for _, slo := range slos {
112113
replays = append(replays, ReplayConfig{

internal/replay.go

+39-22
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ import (
3131
)
3232

3333
type ReplayCmd struct {
34-
client *sdk.Client
35-
from flags.TimeValue
36-
configPaths []string
37-
sloName string
38-
project string
39-
deleteAll bool
34+
client *sdk.Client
35+
from TimeValue
36+
from flags.TimeValue
37+
configPaths []string
38+
sloName string
39+
project string
40+
deleteAll bool
41+
playlistsAvailable bool
4042
}
4143

4244
//go:embed replay_example.sh
@@ -79,6 +81,7 @@ func (r *ReplayCmd) Run(cmd *cobra.Command) error {
7981
if r.client.Config.Project == "*" {
8082
return errProjectWildcardIsNotAllowed
8183
}
84+
r.arePlaylistEnabled(cmd.Context())
8285
replays, err := r.prepareConfigs()
8386
if err != nil {
8487
return err
@@ -92,9 +95,7 @@ func (r *ReplayCmd) RunReplays(cmd *cobra.Command, replays []ReplayConfig) (fail
9295
return 0, err
9396
}
9497

95-
arePlaylistEnabled := r.arePlaylistEnabled(cmd.Context())
96-
97-
if arePlaylistEnabled {
98+
if r.playlistsAvailable {
9899
cmd.Println(colorstring.Color("[yellow]- Your organization has access to Replay queues!"))
99100
cmd.Println(colorstring.Color("[yellow]- To learn more about Replay queues, follow this link: " +
100101
"https://docs.nobl9.com/replay-canary/ [reset]"))
@@ -107,7 +108,7 @@ func (r *ReplayCmd) RunReplays(cmd *cobra.Command, replays []ReplayConfig) (fail
107108
i+1, len(replays), replay.SLO, replay.Project,
108109
replay.From.Format(flags.TimeLayout), time.Now().In(replay.From.Location()).Format(flags.TimeLayout))))
109110

110-
if arePlaylistEnabled {
111+
if r.playlistsAvailable {
111112
cmd.Println("Replay is added to the queue...")
112113
err = r.runReplay(cmd.Context(), replay)
113114

@@ -137,7 +138,12 @@ func (r *ReplayCmd) RunReplays(cmd *cobra.Command, replays []ReplayConfig) (fail
137138
return len(failedIndexes), nil
138139
}
139140

140-
func (r *ReplayCmd) arePlaylistEnabled(ctx context.Context) bool {
141+
type PlaylistConfiguration struct {
142+
EnabledPlaylists bool `json:"enabledPlaylists"`
143+
}
144+
145+
func (r *ReplayCmd) arePlaylistEnabled(ctx context.Context) {
146+
r.playlistsAvailable = true
141147
data, _, err := r.doRequest(
142148
ctx,
143149
http.MethodGet,
@@ -146,17 +152,13 @@ func (r *ReplayCmd) arePlaylistEnabled(ctx context.Context) bool {
146152
nil,
147153
nil)
148154
if err != nil {
149-
return true
155+
fmt.Printf("error checking playlist availability: %v\n", err)
150156
}
151157
var pc PlaylistConfiguration
152158
if err = json.Unmarshal(data, &pc); err != nil {
153-
return true
159+
fmt.Printf("error unmarshalling playlist configuration: %v\n", err)
154160
}
155-
return pc.EnabledPlaylists
156-
}
157-
158-
type PlaylistConfiguration struct {
159-
EnabledPlaylists bool `json:"enabledPlaylists"`
161+
r.playlistsAvailable = pc.EnabledPlaylists
160162
}
161163

162164
type ReplayConfig struct {
@@ -325,16 +327,28 @@ outer:
325327
}
326328

327329
// Check Replay availability.
330+
if err := r.checkReplayAvailability(ctx, replays); err != nil {
331+
return err
332+
}
333+
334+
return nil
335+
}
336+
337+
func (r *ReplayCmd) checkReplayAvailability(ctx context.Context, replays []ReplayConfig) error {
328338
notAvailable := make([]string, 0)
329339
mu := sync.Mutex{}
330340
eg, ctx := errgroup.WithContext(ctx)
331341
eg.SetLimit(10)
342+
332343
for i := range replays {
333344
eg.Go(func() error {
334345
c := replays[i]
335346
timeNow := time.Now()
336347
tt := c.ToReplay(timeNow)
337-
offset := i * int(averageReplayDuration.Minutes())
348+
offset := 0
349+
if !r.playlistsAvailable {
350+
offset = i * int(averageReplayDuration.Minutes())
351+
}
338352
expectedDuration := offset + tt.Duration.Value
339353
av, err := r.getReplayAvailability(ctx, c, tt.Duration.Unit, expectedDuration)
340354
if err != nil {
@@ -343,6 +357,7 @@ outer:
343357
}
344358
if !av.Available {
345359
mu.Lock()
360+
defer mu.Unlock()
346361
notAvailable = append(notAvailable,
347362
fmt.Sprintf("['%s' SLO in '%s' Project] %s",
348363
c.SLO, c.Project, r.replayUnavailabilityReasonExplanation(
@@ -351,18 +366,20 @@ outer:
351366
time.Duration(expectedDuration)*time.Minute,
352367
time.Duration(offset)*time.Minute,
353368
timeNow)))
354-
mu.Unlock()
355369
}
356370
return nil
357371
})
358372
}
359-
if err = eg.Wait(); err != nil {
373+
374+
if err := eg.Wait(); err != nil {
360375
return err
361376
}
377+
362378
if len(notAvailable) > 0 {
363379
return errors.Errorf("The following SLOs are not available for Replay: \n - %s",
364380
strings.Join(notAvailable, "\n - "))
365381
}
382+
366383
return nil
367384
}
368385

@@ -522,7 +539,7 @@ func (r *ReplayCmd) replayUnavailabilityReasonExplanation(
522539
" + %dm (start offset to ensure Replay covers the desired time window) %s."+
523540
" Edit the Data Source and run Replay once again.",
524541
replay.metricSource.Name, replay.metricSource.Project, expectedDuration.String(),
525-
timeNow.Format(flags.TimeLayout), r.from.Format(flags.TimeLayout), startOffsetMinutes, offsetNotice)
542+
timeNow.Format(flags.TimeLayout), replay.From.Format(flags.TimeLayout), startOffsetMinutes, offsetNotice)
526543
case sdkModels.ReplayConcurrentReplayRunsLimitExhausted:
527544
return "You've exceeded the limit of concurrent Replay runs. Wait until the current Replay(s) are done."
528545
case sdkModels.ReplayUnknownAgentVersion:

0 commit comments

Comments
 (0)