kube-state-metrics icon indicating copy to clipboard operation
kube-state-metrics copied to clipboard

Custom Resource Metrics - Ability to just count unique CRs by fields...

Open diranged opened this issue 1 year ago • 10 comments

What would you like to be added:

I'd like to see a way for us to count Custom Resources in an absolute way - just the count of the resources, split up by whatever labels we've selected.

Why is this needed:

Currently the https://github.com/kubernetes/kube-state-metrics/blob/main/docs/customresourcestate-metrics.md code allows us to query values from individual CRs and then report back those values as custom metrics. This is problematic if you have a CR that has a high cardinality rate (kyverno.io/UpdatRequest or CertificateSigningRequests for example) and you only care about the absolute count of them.

Describe the solution you'd like

Right now there is the StateSet, Gauge and Info type of metric configuration. I'd like to see Count added.

diranged avatar Nov 08 '23 19:11 diranged

There is an API server metric called 'apiserver_storage_objects' that should give you counts already.

logicalhan avatar Nov 09 '23 15:11 logicalhan

/close

dgrisonnet avatar Nov 16 '23 17:11 dgrisonnet

@dgrisonnet: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Nov 16 '23 17:11 k8s-ci-robot

/reopen

This feature is under consideration.

dgrisonnet avatar Nov 16 '23 17:11 dgrisonnet

@dgrisonnet: Reopened this issue.

In response to this:

/reopen

This feature is under consideration.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Nov 16 '23 17:11 k8s-ci-robot

/triage accepted

dgrisonnet avatar Nov 16 '23 18:11 dgrisonnet

Hello, I'm also interested in having a Count feature. I have CRDs with multiples status conditions:

status:
  conditions:
  - status: "True"
    type: Synced
  - status: "True"
    type: Ready

I would like to count the number of CRD with specific conditions. The metric result is the number of K8s ressource with the label condition:

# HELP kube_customresource_MyCRD_count_condition_true Count of resource with a true condition
# TYPE kube_customresource_MyCRD_ready gauge
kube_customresource_MyCRD_count_condition_true{type="Ready"} 12
kube_customresource_MyCRD_count_condition_true{type="Synced"} 6
# HELP kube_customresource_MyCRD_count_condition_false Count of resource with a false condition
# TYPE kube_customresource_MyCRD_ready gauge
kube_customresource_MyCRD_count_condition_false{type="Ready"} 0
kube_customresource_MyCRD_count_condition_false{type="Synced"} 1

For the moment I have only been able to create one metric duplicate for each individual K8s resource. I want to group by this metrics into only one line: Output of kube-state-metrics:8080/metrics:

kube_customresource_test_status{customresource_group="****",customresource_kind="***",customresource_version="***",type="Ready"} 1
kube_customresource_test_status{customresource_group="***",customresource_kind="***",customresource_version="***",type="Synced"} 1
kube_customresource_test_status{customresource_group="****",customresource_kind="***",customresource_version="***",type="Ready"} 1
kube_customresource_test_status{customresource_group="***",customresource_kind="***",customresource_version="***",type="Synced"} 1
kube_customresource_test_status{customresource_group="****",customresource_kind="***",customresource_version="***",type="Ready"} 1
kube_customresource_test_status{customresource_group="***",customresource_kind="***",customresource_version="***",type="Synced"} 0

The metric is duplicate three time, because I have three objets.

arfevrier avatar Jan 03 '24 10:01 arfevrier

Hello, I'm also interested in having a Count feature. I have CRDs with multiples status conditions:

status:
  conditions:
  - status: "True"
    type: Synced
  - status: "True"
    type: Ready

I would like to count the number of CRD with specific conditions. The metric result is the number of K8s ressource with the label condition:

# HELP kube_customresource_MyCRD_count_condition_true Count of resource with a true condition
# TYPE kube_customresource_MyCRD_ready gauge
kube_customresource_MyCRD_count_condition_true{type="Ready"} 12
kube_customresource_MyCRD_count_condition_true{type="Synced"} 6
# HELP kube_customresource_MyCRD_count_condition_false Count of resource with a false condition
# TYPE kube_customresource_MyCRD_ready gauge
kube_customresource_MyCRD_count_condition_false{type="Ready"} 0
kube_customresource_MyCRD_count_condition_false{type="Synced"} 1

For the moment I have only been able to create one metric duplicate for each individual K8s resource. I want to group by this metrics into only one line: Output of kube-state-metrics:8080/metrics:

kube_customresource_test_status{customresource_group="****",customresource_kind="***",customresource_version="***",type="Ready"} 1
kube_customresource_test_status{customresource_group="***",customresource_kind="***",customresource_version="***",type="Synced"} 1
kube_customresource_test_status{customresource_group="****",customresource_kind="***",customresource_version="***",type="Ready"} 1
kube_customresource_test_status{customresource_group="***",customresource_kind="***",customresource_version="***",type="Synced"} 1
kube_customresource_test_status{customresource_group="****",customresource_kind="***",customresource_version="***",type="Ready"} 1
kube_customresource_test_status{customresource_group="***",customresource_kind="***",customresource_version="***",type="Synced"} 0

The metric is duplicate three time, because I have three objets.

How did you get this to do counting? What was your each condition

ManziBryan avatar Feb 19 '24 23:02 ManziBryan