Skip to content

Commit

Permalink
fix slo validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Aug 7, 2023
1 parent 29a5e1e commit 08a490a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion manifest/v1alpha/slo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha

import (
"github.com/pkg/errors"

"github.com/nobl9/nobl9-go/manifest"
)

Expand Down Expand Up @@ -145,7 +147,7 @@ type AnomalyConfigAlertMethod struct {
}

// postParse implements postParser interface.
// nolint: unparam, unused
// nolint: unused, gocognit
func (s SLO) postParse() (SLO, error) {
// to keep BC with the ThousandEyes initial implementation (that did not support passing TestType),
// we default `res.Spec.Indicator.RawMetrics.ThousandEyes.TestType` to a value that, until now, was implicitly assumed
Expand Down Expand Up @@ -177,6 +179,12 @@ func (s SLO) postParse() (SLO, error) {
// we have to make sure that old contract (with indicator defined directly on the SLO's spec) is also supported
if s.Spec.Indicator.RawMetric != nil {
for i := range s.Spec.Thresholds {
if s.Spec.Thresholds[i].RawMetric != nil {
return SLO{}, errors.New(
"raw metric definition must be provided on either" +
" indicator level ('SLO.spec.indicator.rawMetric') or" +
" objective level ('SLO.spec.objectives[*].rawMetric')")
}
s.Spec.Thresholds[i].RawMetric = &RawMetricSpec{
MetricQuery: s.Spec.Indicator.RawMetric,
}
Expand Down
13 changes: 12 additions & 1 deletion manifest/v1alpha/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,18 @@ func isBadOverTotalEnabledForDataSource(spec SLOSpec) bool {
}

func hasOnlyOneRawMetricDefinitionTypeOrNone(spec SLOSpec) bool {
return spec.ObjectivesRawMetricsCount() == 0 || !spec.containsIndicatorRawMetric()
indicatorHasRawMetric := spec.containsIndicatorRawMetric()
if indicatorHasRawMetric {
for _, threshold := range spec.Thresholds {
if !threshold.HasRawMetricQuery() {
continue
}
if !reflect.DeepEqual(threshold.RawMetric.MetricQuery, spec.Indicator.RawMetric) {
return false
}
}
}
return true
}

func areRawMetricsSetForAllThresholdsOrNone(spec SLOSpec) bool {
Expand Down

0 comments on commit 08a490a

Please sign in to comment.