Fix bug corrupting Prometheus timeseries __name__ label #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have also been experiencing issues like the ones described in #259 and #169 where Prometheus outputs are sometimes dropped or incorrect.
I believe this is due to a bug with how the
__name__
label gets added to the list of labels when constructing a timeseries. The__name__
label is appended without a copy or assignment, meaning it will overwrite whatever was appended previously, so long as there is space remaining in the array. If GetLabels returns a slice with length == capacity, the bug does not seem to occur because append forces a copy.A consequence of this bug is that a value can get written to the wrong timeseries.
I've written a test that reproduces this behavior. The test fails without the fix and passes with the fix.
I don't write a lot of Go, so let me know if I've gotten anything wrong here or there's a better way to solve this. I stumbled upon this issue while investigating incorrect gNMIC Prometheus writes that I was observing.