Skip to content

Commit

Permalink
Adding missing functionality to convert Threshold metrics to RawMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-bartholomew committed Sep 28, 2022
1 parent 13848fd commit e689760
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions internal/pkg/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,52 @@ func getN9Thresholds(o []v1.Objective, indicator v1.SLISpec) ([]nobl9v1alpha.Thr
value = 1
}

// start building our object
th := nobl9v1alpha.Threshold{
ThresholdBase: nobl9v1alpha.ThresholdBase{
DisplayName: v.DisplayName,
Value: value,
},
Operator: operator,
BudgetTarget: &v.Target,
}

// Get CountMetrics if we have a ratioMetric
var cm nobl9v1alpha.CountMetricsSpec
if indicator.RatioMetric != nil {
c, err := getN9CountMetrics(*indicator.RatioMetric)
if err != nil {
return nil, fmt.Errorf("issue getting count metrics: %w", err)
}
cm = c
th.CountMetrics = &c
}

t = append(t, nobl9v1alpha.Threshold{
ThresholdBase: nobl9v1alpha.ThresholdBase{
DisplayName: v.DisplayName,
Value: value,
},
Operator: operator,
BudgetTarget: &v.Target,
CountMetrics: &cm,
})
// Get thresholdMetrics
if indicator.ThresholdMetric != nil {
r, err := getN9RawMetrics(*indicator.ThresholdMetric)
if err != nil {
return nil, fmt.Errorf("issue getting raw metrics: %w", err)
}
th.RawMetric = &r
}

t = append(t, th)
}
return t, nil
}

func getN9RawMetrics(r v1.MetricSourceHolder) (nobl9v1alpha.RawMetricSpec, error) {
raw, err := getN9MetricSource(r.MetricSource)
if err != nil {
return nobl9v1alpha.RawMetricSpec{}, fmt.Errorf("issue getting raw metric source: %w", err)
}

rm := nobl9v1alpha.RawMetricSpec{
MetricQuery: &raw,
}

return rm, nil
}

func getN9CountMetrics(r v1.RatioMetric) (nobl9v1alpha.CountMetricsSpec, error) {
// Error if Bad is not nil, since Nobl9 doesn't support it.
if r.Bad != nil {
Expand Down

0 comments on commit e689760

Please sign in to comment.