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

CustomResource: no metrics if CRD apply after ksm starts #2296

Open ZhangsongLee opened 9 months ago

ZhangsongLee commented 9 months ago

What happened:

There is a issues when a CRD is not applied before starting ksm

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Used Configuration:

custom-resource-state-config.yaml: |
  spec:
    resources:
    - groupVersionKind:
        group: test.demo.io
        version: "v1alpha1"
        kind: crdtest
      labelsFromPath:
        namespace: [metadata, namespace]
      metrics:
        - name: "custom_request_cpu"
          help: "request cpu metrics"
          each:
            type: Gauge
            gauge:
              path: [status, custom, containers]
              labelsFromPath:
                container_name: ["containerName"]
              valueFrom: [cpu]

Anything else we need to know?: I found a related issue https://github.com/kubernetes/kube-state-metrics/issues/2142, this issue is before starting ksm, CRD already existed.

Environment:

CatherineF-dev commented 8 months ago

Could you try KSM v2.8.2?

There are some big changes around CRD after v2.8.2.

ZhangsongLee commented 8 months ago

But I used commit(https://github.com/kubernetes/kube-state-metrics/commit/eac6d3b1c994bd7dbd76026188d2b374bf000f20) after v2.8.2

CatherineF-dev commented 8 months ago

v2.8.2+ has some bugs, you can find them in issues.

I guess this might be related as well.

Is v2.8.2 working for you?

ZhangsongLee commented 8 months ago

Unfortunately, v2.8.2 is not working :(

CatherineF-dev commented 8 months ago

This feature is working in my cluster.

Could you try examples here https://github.com/kubernetes/kube-state-metrics/blob/main/docs/customresourcestate-metrics.md?

I guess user configuration is not correct, you can add logs and rebuild KSM to debug. https://github.com/kubernetes/kube-state-metrics/pull/2299

dashpole commented 8 months ago

/assign @CatherineF-dev /triage accepted

CatherineF-dev commented 7 months ago

Hi @ZhangsongLee, is this issue resolved or not?