Unregister the metric fully when last labelled metric is unregistered #110
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.
Motivation
The registry is designed to return the same metric instance for a previously registered metric with the same name if, and only if:
By design, it throws a fatal error if these conditions do not hold for the metric name.
However, the registry also provides methods for unregistering metrics, such that they will not be emitted. A consequence of this unregistration is it allows for the metric name to be reused:
But the API has some unexpected behaviour when unregistering metrics that were registered with labels:
This is because the unregister APIs currently only remove the dimensions but do not go as far as to unregister the whole metric once the last such dimension has been unregistered.
Modifications
testUnregisterReregisterWithoutLabels
, which passed before this patch.testUnregisterReregisterWithLabels
, which failed before this patch, but now passes.Result
Unregistering a metric with a label will unregister the metric name if this was the only remaining dimension for that metric.