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

Allow Custom Resource State mode to filter on resource labels

Open blezoray opened this issue 11 months ago • 2 comments

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/tools/cache/reflector.go:229: Watch close - apps/v1, Kind=StatefulSet total 10 items received

Is it supported ?

Rgds.

blezoray avatar Mar 22 '24 11:03 blezoray

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. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 22 '24 11:03 k8s-ci-robot

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

This bot triages un-triaged 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:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Jun 20 '24 14:06 k8s-triage-robot

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:

  • 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:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle rotten

k8s-triage-robot avatar Jul 20 '24 14:07 k8s-triage-robot

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

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

/close not-planned

k8s-triage-robot avatar Aug 19 '24 15:08 k8s-triage-robot

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

In response to this:

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

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

/close not-planned

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-sigs/prow repository.

k8s-ci-robot avatar Aug 19 '24 15:08 k8s-ci-robot