Skip to content

Commit

Permalink
Do not crash for queries where no metrics are returned
Browse files Browse the repository at this point in the history
Depending on the configured query and particular timespan, it is
possible for no metrics to be returned. Which in the previous
implementation would cause a panic. This commit gracefully handles the
scenario by continuing to the next query job in this particular case.
  • Loading branch information
lwalter committed Nov 26, 2024
1 parent cbde5e4 commit 363e221
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func runAPIPolling(done chan error, url, token string, yamlConfig YamlConfig, re
return
}

// Handle cases where the metric may be missing for the given time range
if len(poll.Events) < 1 {
zap.L().Sugar().Debugf("No Events returned by query. Timespan: %v, MetricName: %s", job.Timespan, job.MetricName)
continue
}

var floatValue float64
for _, f := range supportedFunctions {
value, ok := poll.Events[0][f]
Expand Down

0 comments on commit 363e221

Please sign in to comment.