Skip to content

Commit

Permalink
fix(metricprovider): fix handling null values in datadog
Browse files Browse the repository at this point in the history
Signed-off-by: Youssef Rabie <[email protected]>
  • Loading branch information
y-rabie committed Oct 13, 2024
1 parent b0d74e5 commit f1dfbc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions metricproviders/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type datadogResponseV2 struct {
Data struct {
Attributes struct {
Columns []struct {
Values []float64
Values []*float64
}
}
Errors string
Expand Down Expand Up @@ -320,7 +320,7 @@ func (p *Provider) parseResponseV2(metric v1alpha1.Metric, response *http.Respon
}

// Handle an empty query result
if reflect.ValueOf(res.Data.Attributes).IsZero() || len(res.Data.Attributes.Columns) == 0 || len(res.Data.Attributes.Columns[0].Values) == 0 {
if reflect.ValueOf(res.Data.Attributes).IsZero() || len(res.Data.Attributes.Columns) == 0 || len(res.Data.Attributes.Columns[0].Values) == 0 || res.Data.Attributes.Columns[0].Values[0] == nil {
var nilFloat64 *float64
status, err := evaluate.EvaluateResult(nilFloat64, metric, p.logCtx)

Expand All @@ -343,7 +343,7 @@ func (p *Provider) parseResponseV2(metric v1alpha1.Metric, response *http.Respon

// Handle a populated query result
column := res.Data.Attributes.Columns[0]
value := column.Values[0]
value := *column.Values[0]
status, err := evaluate.EvaluateResult(value, metric, p.logCtx)
return strconv.FormatFloat(value, 'f', -1, 64), status, err
}
Expand Down
2 changes: 1 addition & 1 deletion metricproviders/datadog/datadogV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestRunSuiteV2(t *testing.T) {
},
expectedIntervalSeconds: 300,
expectedPhase: v1alpha1.AnalysisPhaseError,
expectedErrorMessage: "Could not parse JSON body: json: cannot unmarshal string into Go struct field .Data.Attributes.Columns.Values of type []float64",
expectedErrorMessage: "Could not parse JSON body: json: cannot unmarshal string into Go struct field .Data.Attributes.Columns.Values of type []*float64",
useEnvVarForKeys: false,
},

Expand Down

0 comments on commit f1dfbc7

Please sign in to comment.