Closed lgfa29 closed 11 months ago
@lgfa29 as an alternative because this seems like such a weird case and a programmer error rather than a runtime error, what would you think about shipping a version of Nomad pinned to this branch to see if we can get reports on the error to fix the underlying cause?
Ah good idea. I will open a PR with this dependency update on Nomad tomorrow. I will probably rebase this as branch to v0.4.1
to make sure this is the only code change.
The Prometheus Counter.Add() method panics if the value being added is negative. Even if care is taken by consumers to never pass a negative value the panic could still happen due to float conversion or overflow.
This change prevents go-metrics from causing consumers to crash.
A panic like this has been reported in https://github.com/hashicorp/nomad/issues/15861, but, as far as I can tell, Nomad only calls
IncrCounter
andIncrCounterWithLabels
using positive values.