Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic for case when no metrics are returned #110

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 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 All @@ -201,7 +207,6 @@ func runAPIPolling(done chan error, url, token string, yamlConfig YamlConfig, re
}
} else {
zap.L().Sugar().Debugf("Skipped value because query isn't done. Timespan: %v, Value: %v", job.Timespan, floatValue)

}
}
time.Sleep(5000 * time.Millisecond)
Expand All @@ -223,7 +228,6 @@ func (m *MetricMap) Register() error {
}

func (m *MetricMap) UpdateMetricValue(metricName, timespan, repo string, value float64, staticLabels []MetricLabel) error {

labels := make(map[string]string)
labels[intervalLabel] = timespan
labels[repoLabel] = repo
Expand Down
Loading