kubernetes / kube-state-metrics

Add-on agent to generate and expose cluster-level metrics.
https://kubernetes.io/docs/concepts/cluster-administration/kube-state-metrics/
Apache License 2.0
5.21k stars 1.93k forks source link

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

Open diranged opened 8 months ago

diranged commented 8 months ago

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.

logicalhan commented 7 months ago

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

dgrisonnet commented 7 months ago

/close

k8s-ci-robot commented 7 months ago

@dgrisonnet: Closing this issue.

In response to [this](https://github.com/kubernetes/kube-state-metrics/issues/2238#issuecomment-1814946117): >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
dgrisonnet commented 7 months ago

/reopen

This feature is under consideration.

k8s-ci-robot commented 7 months ago

@dgrisonnet: Reopened this issue.

In response to [this](https://github.com/kubernetes/kube-state-metrics/issues/2238#issuecomment-1814962834): >/reopen > >This feature is under consideration. Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
dgrisonnet commented 7 months ago

/triage accepted

arfevrier commented 6 months ago

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.

ManziBryan commented 4 months ago

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