Do not expose info metric for nil objects #1809
Merged
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.
What this PR does / why we need it:
Small follow-up to #1777 .
The current code exposes info metrics independent of the value of the object referenced by
path
.With this change, it won't expose an info metric, if the object's value at
path
is nil. Ifpath
is not set, it will always expose a metric because we at least have metadata at the object.Use case is the following:
In Cluster API there is an annotation which is used to pause objects (
cluster.x-k8s.io/paused
). The value of the annotation could be the empty string.A use case is to have a metric to see if objects are paused (
cluster.x-k8s.io/paused
label exists, independent of the value, which includes the empty string""
as value).So the challenge here is to determine if the label exists or not.
Currently we could expose the label as label on the metric, but the empty string would be semantically equal to the label not being set at all when querying using prometheus.
An example:
Consider the following objects:
And the following CR configuration:
Without this change, the created metrics would be as follows (I removed the
namespace
anduid
labels):PromQL queries will result in the following, which makes it impossible to see if
paused-1
is really paused:With this change, the created metrics wqould be as follows (again, I removed the
namespace
anduid
labels):How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
May decrease number of metrics for CR configured Info metrics which define a path.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #