Move value check before metric get

If someone is emitting negative counters we shouldn't even register the
metric for them
This commit is contained in:
Thomas Jackson 2017-07-18 08:37:03 -07:00
parent 663b6a1e69
commit 22520f4c7b

View file

@ -233,10 +233,6 @@ func (b *Exporter) Listen(e <-chan Events) {
switch ev := event.(type) {
case *CounterEvent:
counter := b.Counters.Get(
b.suffix(metricName, "counter"),
prometheusLabels,
)
// We don't accept negative values for counters. Incrementing the counter with a negative number
// will cause the exporter to panic. Instead we will warn and continue to the next event.
if event.Value() < 0.0 {
@ -244,6 +240,11 @@ func (b *Exporter) Listen(e <-chan Events) {
continue
}
counter := b.Counters.Get(
b.suffix(metricName, "counter"),
prometheusLabels,
)
counter.Add(event.Value())
eventStats.WithLabelValues("counter").Inc()