Skip to content

Commit

Permalink
Ensure we log errors every time there is a problem
Browse files Browse the repository at this point in the history
Move addition of metric to "Elements" until after a successful registry
with prometheus, otherwise we'll continue to increment a metric which
isn't registered
  • Loading branch information
jacksontj committed Jul 18, 2017
1 parent d9aa6e2 commit c1791d7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels) (pro
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = counter
if err := prometheus.Register(counter); err != nil {
return nil, err
}
c.Elements[hash] = counter
}
return counter, nil
}
Expand All @@ -105,10 +105,10 @@ func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) (prome
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = gauge
if err := prometheus.Register(gauge); err != nil {
return nil, err
}
c.Elements[hash] = gauge
}
return gauge, nil
}
Expand All @@ -133,10 +133,10 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels) (pro
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = summary
if err := prometheus.Register(summary); err != nil {
return nil, err
}
c.Elements[hash] = summary
}
return summary, nil
}
Expand Down

0 comments on commit c1791d7

Please sign in to comment.