Skip to content

Commit

Permalink
feat: PC-14184 Add sourceSLO field in replay config file (#213)
Browse files Browse the repository at this point in the history
## Motivation

Run replay using an SLO as a data source.

## Summary

* Added `sourceSLO` field to replay configuration file.
```
- slo: a-prometheus-http-requests-goodtotal-ratio
  project: pkw-test
  from: 2024-09-12T00:00:00+02:00
  sourceSLO:
    slo: prometheus-http-requests-goodtotal-ratio
    project: amazon-prometheus
    objectivesMap:
      - source: objective-1
        target: objective-2
```
* All `sourceSLO` slos are added to the initial sloctl request that
checks if the user has permissions to all SLOs and if they exist.

## Related changes

* n9: nobl9/n9#15419
* nobl9-go: nobl9/nobl9-go#543

## Testing

- Added unit tests for `sourceSLO` validation in nobl9-go

## Release Notes

Replaying SLOs using file configuration now allows for replays to be run
using another SLO as a data source. This can be done by specifying the
`sourceSLO` field in a replayed SLO. The field must provide the slo
name, its project, and a mapping for objectives to match the source and
target SLO objectives.

---------

Co-authored-by: Jakub Gruszecki <[email protected]>
  • Loading branch information
piotrkwarcinski and ditrytus authored Oct 7, 2024
1 parent abf97f8 commit e502ae2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/go-playground/validator/v10 v10.22.1
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
github.com/nobl9/go-yaml v1.0.1
github.com/nobl9/nobl9-go v0.86.0
github.com/nobl9/nobl9-go v0.87.1-0.20241003100141-13a5a306624d
github.com/pkg/errors v0.9.1
github.com/schollz/progressbar/v3 v3.16.1
github.com/spf13/cobra v1.8.1
Expand All @@ -33,7 +33,7 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/nobl9/govy v0.2.0 // indirect
github.com/nobl9/govy v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2Em
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/nobl9/go-yaml v1.0.1 h1:Aj1kSaYdRQTKlvS6ihvXzQJhCpoHhtf9nfA95zqWH4Q=
github.com/nobl9/go-yaml v1.0.1/go.mod h1:t7vCO8ctYdBweZxU5lUgxzAw31+ZcqJYeqRtrv+5RHI=
github.com/nobl9/govy v0.2.0 h1:KXZRzHte3uJSpB2i0wBD+3fUoON5ptvlfMrkvtRO8Sc=
github.com/nobl9/govy v0.2.0/go.mod h1:O+xSiKwZ6gs/orRvH5qLkfkgyT7CkuXprRIq3C5uNXQ=
github.com/nobl9/nobl9-go v0.86.0 h1:TpBjVgcluHwgBHtTUuyJF9UCcTiGtHQN5VrFKSjfL00=
github.com/nobl9/nobl9-go v0.86.0/go.mod h1:DPGLjkUkf2BHDj72BbKFuJzD/gxO/qTLtgFU9wKtqzE=
github.com/nobl9/govy v0.3.0 h1:OokgZ9PHfFNt2TkX8h/9rF0Y3doj/nnr0BlPo1BsasY=
github.com/nobl9/govy v0.3.0/go.mod h1:O+xSiKwZ6gs/orRvH5qLkfkgyT7CkuXprRIq3C5uNXQ=
github.com/nobl9/nobl9-go v0.87.1-0.20241003100141-13a5a306624d h1:jDCIdJPMEOW3cSDHajeX9mxAm/kuBxeI6ifC9xRU1ck=
github.com/nobl9/nobl9-go v0.87.1-0.20241003100141-13a5a306624d/go.mod h1:jICYB6/RFcKs/Mqm3ltGbsD2Ign64/uy8JMaHxpYQ5o=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
16 changes: 11 additions & 5 deletions internal/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ func (r *ReplayCmd) RunReplays(cmd *cobra.Command, replays []ReplayConfig) (fail
}

type ReplayConfig struct {
Project string `json:"project" validate:"required"`
SLO string `json:"slo" validate:"required"`
From time.Time `json:"from" validate:"required"`
Project string `json:"project" validate:"required"`
SLO string `json:"slo" validate:"required"`
From time.Time `json:"from" validate:"required"`
SourceSLO *sdkModels.ReplaySourceSLO `json:"sourceSLO,omitempty"`

metricSource v1alphaSLO.MetricSourceSpec
}
Expand All @@ -140,6 +141,7 @@ func (r ReplayConfig) ToReplay(timeNow time.Time) sdkModels.Replay {
Unit: sdkModels.DurationUnitMinute,
Value: startOffsetMinutes + int(windowDuration.Minutes()),
},
SourceSLO: r.SourceSLO,
}
}

Expand Down Expand Up @@ -256,8 +258,12 @@ const averageReplayDuration = 20 * time.Minute

func (r *ReplayCmd) verifySLOs(ctx context.Context, replays []ReplayConfig) error {
sloNames := make([]string, 0, len(replays))
for i := range replays {
sloNames = append(sloNames, replays[i].SLO)
for _, r := range replays {
sloNames = append(sloNames, r.SLO)
if r.SourceSLO != nil {
// Add source SLOs to the list of SLOs to check for existence and permissions.
sloNames = append(sloNames, r.SourceSLO.Slo)
}
}
if r.client.Config.Project == "" {
r.client.Config.Project = sdk.ProjectsWildcard
Expand Down

0 comments on commit e502ae2

Please sign in to comment.