Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not expose info metric for nil objects #1809

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

chrischdi
Copy link
Member

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. If path 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:

apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: paused-1
  labels:
    cluster.x-k8s.io/paused: ""
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: paused-2
  labels:
    cluster.x-k8s.io/paused: "foo"
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: not-paused
  labels: {}

And the following CR configuration:

kind: CustomResourceStateMetrics
spec:
  resources:
  - groupVersionKind:
      group: cluster.x-k8s.io
      kind: Cluster
      version: v1beta1
    metricNamePrefix: capi_cluster
    labelsFromPath:
      name: [metadata, name]
      namespace: [metadata, namespace]
      uid: [metadata, uid]
    metrics:
    - each:
        info:
          path:
          - metadata
          - annotations
          - cluster.x-k8s.io/paused
          labelsFromPath:
            value: []
        type: Info
      name: annotation_paused

Without this change, the created metrics would be as follows (I removed the namespace and uid labels):

capi_cluster_annotation_paused{name="paused-1",value=""} 1
capi_cluster_annotation_paused{name="paused-2",value="foo"} 1
capi_cluster_annotation_paused{name="not-paused"} 1

PromQL queries will result in the following, which makes it impossible to see if paused-1 is really paused:

capi_cluster_annotation_paused{name="paused-1"} 1
capi_cluster_annotation_paused{name="paused-2",value="foo"} 1
capi_cluster_annotation_paused{name="not-paused"} 1

With this change, the created metrics wqould be as follows (again, I removed the namespace and uid labels):

capi_cluster_annotation_paused{name="paused-1",value=""} 1
capi_cluster_annotation_paused{name="paused-2",value="foo"} 1

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 #

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 19, 2022
@mrueg
Copy link
Member

mrueg commented Aug 19, 2022

/lgtm

thanks for the follow-up PR!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 19, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrischdi, mrueg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 19, 2022
@k8s-ci-robot k8s-ci-robot merged commit f1d5653 into kubernetes:master Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants