Skip to content

Commit

Permalink
Remove early returns when termination not imminent
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtempleton committed Oct 5, 2021
1 parent ae83b3a commit 19cef23
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ func (c *terminationCollector) Collect(ch chan<- prometheus.Metric) {
if err != nil {
log.Errorf("Failed to fetch data from metadata service: %s", err)
ch <- prometheus.MustNewConstMetric(c.scrapeSuccessful, prometheus.GaugeValue, 0, instanceId)
return
} else {
ch <- prometheus.MustNewConstMetric(c.scrapeSuccessful, prometheus.GaugeValue, 1, instanceId)

if resp.StatusCode == 404 {
log.Debug("instance-action endpoint not found")
ch <- prometheus.MustNewConstMetric(c.terminationIndicator, prometheus.GaugeValue, 0, "", instanceId, instanceType)
return
} else {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
Expand Down Expand Up @@ -120,13 +118,15 @@ func (c *terminationCollector) Collect(ch chan<- prometheus.Metric) {
if err != nil {
log.Errorf("Failed to fetch events data from metadata service: %s", err)
ch <- prometheus.MustNewConstMetric(c.rebalanceScrapeSuccessful, prometheus.GaugeValue, 0, instanceId)
// Return early as this is the last metric/metadata scrape attempt
return
} else {
ch <- prometheus.MustNewConstMetric(c.rebalanceScrapeSuccessful, prometheus.GaugeValue, 1, instanceId)

if eventResp.StatusCode == 404 {
log.Debug("rebalance endpoint not found")
ch <- prometheus.MustNewConstMetric(c.rebalanceIndicator, prometheus.GaugeValue, 0, instanceId, instanceType)
// Return early as this is the last metric/metadata scrape attempt
return
} else {
defer eventResp.Body.Close()
Expand Down

0 comments on commit 19cef23

Please sign in to comment.