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.2k stars 1.92k forks source link

Using k8s labels in prometheus rules expr #2338

Open vlogachev-bd opened 3 months ago

vlogachev-bd commented 3 months ago

Hello,

I am new to Prometheus so I would ask for some advice.

I am trying to use custom labels from k8s deployment in the prometheus rules expression.

Here is my setup:

k8s labels:

labels: app: nginx-test ignore-desired-replicas: "true" ignore-ram-usage: "true" ignore-cpu-usage: "true" ignore-container-restarts: "true" team: xxx

kube-state-metrics deployment.

args:

Prometheus rule expr: kube_deployment_labels * on (deployment, namespace) group_right(label_team) ((kube_deployment_status_replicas_available / kube_deployment_spec_replicas) < 1 )

I also tried to add group_right(label_team, ignore-desired-replicas) and ( (label_team, label_ignore-desired-replicas), but I am not even able to startup the container, I assume due to the fact that it does not recognize the label.

It looks to me that I am making a mistake somewhere in the kube-state-metrics configuration.

Currently, when I receive an alert I can see that it groups only be team and it is ignoring my second label ignore-desired-replicas.

Any thoughts, folks?

k8s-ci-robot commented 3 months ago

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.
k8s-triage-robot commented 2 weeks ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale