Skip to content

Commit

Permalink
move post parse steps away to ingest
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Aug 8, 2023
1 parent 08a490a commit 5592074
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 74 deletions.
13 changes: 0 additions & 13 deletions manifest/v1alpha/alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import "github.com/nobl9/nobl9-go/manifest"

//go:generate go run ../../scripts/generate-object-impl.go AlertPolicy

const DefaultAlertPolicyLastsForDuration = "0m"

// AlertPolicy represents a set of conditions that can trigger an alert.
type AlertPolicy struct {
APIVersion string `json:"apiVersion"`
Expand Down Expand Up @@ -51,14 +49,3 @@ type AlertPolicyWithSLOs struct {
AlertPolicy AlertPolicy `json:"alertPolicy"`
SLOs []SLO `json:"slos"`
}

// postParse implements postParser interface.
// nolint: unparam, unused
func (a AlertPolicy) postParse() (AlertPolicy, error) {
for i, condition := range a.Spec.Conditions {
if condition.AlertingWindow == "" && condition.LastsForDuration == "" {
a.Spec.Conditions[i].LastsForDuration = DefaultAlertPolicyLastsForDuration
}
}
return a, nil
}
61 changes: 0 additions & 61 deletions manifest/v1alpha/slo.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package v1alpha

import (
"github.com/pkg/errors"

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

Expand Down Expand Up @@ -145,62 +143,3 @@ type AnomalyConfigAlertMethod struct {
Name string `json:"name" validate:"required,objectName" example:"slack-monitoring-channel"`
Project string `json:"project,omitempty" validate:"objectName" example:"default"`
}

// postParse implements postParser interface.
// 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
if s.Spec.Indicator.RawMetric != nil &&
s.Spec.Indicator.RawMetric.ThousandEyes != nil &&
s.Spec.Indicator.RawMetric.ThousandEyes.TestType == nil {
metricType := ThousandEyesNetLatency
s.Spec.Indicator.RawMetric.ThousandEyes.TestType = &metricType
}

for i, threshold := range s.Spec.Thresholds {
if threshold.RawMetric != nil &&
threshold.RawMetric.MetricQuery != nil &&
threshold.RawMetric.MetricQuery.ThousandEyes != nil &&
threshold.RawMetric.MetricQuery.ThousandEyes.TestType == nil {
metricType := ThousandEyesNetLatency
s.Spec.Thresholds[i].RawMetric.MetricQuery.ThousandEyes.TestType = &metricType
}
}

if s.Spec.Indicator.MetricSource.Project == "" {
s.Spec.Indicator.MetricSource.Project = s.Metadata.Project
}
if !s.Spec.Indicator.MetricSource.Kind.IsValid() {
s.Spec.Indicator.MetricSource.Kind = manifest.KindAgent
}

// we're moving towards the version where raw metrics are defined on each objective, but for now,
// 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,
}
}
}

// AnomalyConfig will be moved into Anomaly Rules in PC-8502.
// Set the default value of all alert methods defined in anomaly config to the same project
// that is used by SLO.
if s.Spec.AnomalyConfig != nil && s.Spec.AnomalyConfig.NoData != nil {
for i := 0; i < len(s.Spec.AnomalyConfig.NoData.AlertMethods); i++ {
if s.Spec.AnomalyConfig.NoData.AlertMethods[i].Project == "" {
s.Spec.AnomalyConfig.NoData.AlertMethods[i].Project = s.Metadata.Project
}
}
}

return s, nil
}

0 comments on commit 5592074

Please sign in to comment.