@@ -96,7 +96,7 @@ func main() {
96
96
97
97
failures ++
98
98
} else {
99
- if value == nil || value . Get () == nil {
99
+ if value == nil {
100
100
slog .Warn ("Query returned no data; the metric might not be real or there may not be any datapoints" ,
101
101
slog .String ("file" , file ),
102
102
slog .String ("query" , query ),
@@ -105,7 +105,7 @@ func main() {
105
105
slog .Info ("Query result" ,
106
106
slog .String ("file" , file ),
107
107
slog .String ("query" , query ),
108
- slog .Float64 ("value" , * value . Get () ),
108
+ slog .Float64 ("value" , * value ),
109
109
)
110
110
}
111
111
}
@@ -161,7 +161,7 @@ func extractQuery(filePath string) (string, error) {
161
161
}
162
162
163
163
// Fetch the metric value for the specified query from the Datadog API, if possible.
164
- func fetchMetric (ctx context.Context , api * datadogV1.MetricsApi , query string ) (* datadog. NullableFloat64 , error ) {
164
+ func fetchMetric (ctx context.Context , api * datadogV1.MetricsApi , query string ) (* float64 , error ) {
165
165
fiveMinAgo := time .Now ().Add (- 1 * time .Minute ).Unix ()
166
166
metricResp , httpResp , err := api .QueryMetrics (ctx , fiveMinAgo , time .Now ().Unix (), query )
167
167
@@ -188,15 +188,17 @@ func fetchMetric(ctx context.Context, api *datadogV1.MetricsApi, query string) (
188
188
// The API call technically succeeded in that the query wasn't malformed.
189
189
// Note that this doesn't mean the metric is necessarily a real metric, just that the query succeeded.
190
190
if len (metricResp .Series ) > 0 && metricResp .Series [0 ].End != nil {
191
+ // Return the latest non-null value in the time series.
191
192
series := metricResp .Series [0 ]
192
- if len (series .Pointlist ) > 0 {
193
- // Return the value of the latest datapoint in the time series.
194
- lastestPoint := series .Pointlist [len (series .Pointlist )- 1 ]
195
- return datadog .NewNullableFloat64 (lastestPoint [1 ]), nil
193
+ for i := len (series .Pointlist ) - 1 ; i >= 0 ; i -- {
194
+ point := series .Pointlist [i ]
195
+ if point [1 ] != nil {
196
+ return point [1 ], nil
197
+ }
196
198
}
197
199
}
198
200
199
- // No time series was returned, so it's probably a metric without data or it doesn't exist.
201
+ // No time series returned or all points were null. Probably a metric w/out data or it doesn't exist.
200
202
//nolint:nilnil
201
203
return nil , nil
202
204
}
0 commit comments