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.43k stars 2.02k forks source link

Allow Custom Resource State mode to filter on resource labels #2348

Closed blezoray closed 2 months ago

blezoray commented 7 months ago

Hi,

I'm using KMS v2.11.0 with --custom-resource-state-only=true mode. In my custom-resource-state-config-file, I would like to filter some resources (StatefulSet, Deployment, DeploymentConfig) with specific labels. Something equivalent to:

$ kubectl get statefulsets.apps -A -l 'accounting'
NAMESPACE                        NAME                               READY   AGE
dbms-db                          myq-orange-mariadb                 1/1     106d
dbms-ops                         generic-graf-orange-grafana        1/1     35d
dbms-ops                         generic-prom-prometheus            1/1     21h
...

I try to configure my custom-resource-state-config-file like this but it doesn't return any metric.

  # StatefulSet.apps
  - metricNamePrefix: mpms
    groupVersionKind:
      group: apps
      version: v1
      kind: StatefulSet
      labels:
        accounting:
    labelsFromPath:
      name: [metadata, name]
      namespace: [metadata, namespace]
      accounting: [metadata, labels, accounting]
    metrics:
      - name: managedresources
        help: MPMS Managed Resources
        each:
          type: Gauge
          gauge:
            path: [status, conditions]
            labelsFromPath:
              type: [type]
            valueFrom: [status]

Here are the logs:

$ kubectl logs deployments/operators-accounting | grep -i stateful
I0322 07:56:59.035262       1 reflector.go:289] Starting reflector apps/v1, Kind=StatefulSet (0s) from pkg/mod/k8s.io/client-go@v0.28.4/tools/cache/reflector.go:229
I0322 07:56:59.035288       1 reflector.go:325] Listing and watching apps/v1, Kind=StatefulSet from pkg/mod/k8s.io/client-go@v0.28.4/tools/cache/reflector.go:229
I0322 07:56:59.234105       1 builder.go:282] "Active resources" activeStoreNames="apps/v1, Resource=statefulsets,cert-manager.io/v1, Resource=certificaterequests,cert-manager.io/v1, Resource=certificates,cert-manager.io/v1, Resource=clusterissuers,cert-manager.io/v1, Resource=issuers,core.strimzi.io/v1beta2, Resource=strimzipodsets,elasticsearch.k8s.elastic.co/v1, Resource=elasticsearches,enterprisesearch.k8s.elastic.co/v1, Resource=enterprisesearches,external-secrets.io/v1alpha1, Resource=pushsecrets,external-secrets.io/v1beta1, Resource=clusterexternalsecrets,external-secrets.io/v1beta1, Resource=clustersecretstores,external-secrets.io/v1beta1, Resource=externalsecrets,external-secrets.io/v1beta1, Resource=secretstores,kafka.strimzi.io/v1beta2, Resource=kafkabridges,kafka.strimzi.io/v1beta2, Resource=kafkaconnectors,kafka.strimzi.io/v1beta2, Resource=kafkaconnects,kafka.strimzi.io/v1beta2, Resource=kafkamirrormaker2s,kafka.strimzi.io/v1beta2, Resource=kafkamirrormakers,kafka.strimzi.io/v1beta2, Resource=kafkanodepools,kafka.strimzi.io/v1beta2, Resource=kafkarebalances,kafka.strimzi.io/v1beta2, Resource=kafkas,kafka.strimzi.io/v1beta2, Resource=kafkatopics,kafka.strimzi.io/v1beta2, Resource=kafkausers,kibana.k8s.elastic.co/v1, Resource=kibanas,kube-green.com/v1alpha1, Resource=sleepinfos,logstash.k8s.elastic.co/v1alpha1, Resource=logstashes,postgresql.cnpg.io/v1, Resource=clusters,postgresql.cnpg.io/v1, Resource=poolers,storage.tech.orange/v1alpha1, Resource=s3bucketclaims"
I0322 08:02:21.436082       1 reflector.go:790] pkg/mod/k8s.io/client-go@v0.28.4/tools/cache/reflector.go:229: Watch close - apps/v1, Kind=StatefulSet total 6 items received
I0322 08:11:28.437911       1 reflector.go:790] pkg/mod/k8s.io/client-go@v0.28.4/tools/cache/reflector.go:229: Watch close - apps/v1, Kind=StatefulSet total 10 items received
I0322 08:20:58.439071       1 reflector.go:790] pkg/mod/k8s.io/client-go@v0.28.4/tools/cache/reflector.go:229: Watch close - apps/v1, Kind=StatefulSet total 11 items received
I0322 08:30:28.441079       1 reflector.go:790] pkg/mod/k8s.io/client-go@v0.28.4/tools/cache/reflector.go:229: Watch close - apps/v1, Kind=StatefulSet total 10 items received

Is it supported ?

Rgds.

k8s-ci-robot commented 7 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 4 months 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

k8s-triage-robot commented 3 months ago

The Kubernetes project currently lacks enough active 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 rotten

k8s-triage-robot commented 2 months ago

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

This bot triages issues according to the following rules:

You can:

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

/close not-planned

k8s-ci-robot commented 2 months ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes/kube-state-metrics/issues/2348#issuecomment-2296915430): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ 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-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.