Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom resource state metrics wildcard not working #2384

Open
akselleirv opened this issue Apr 30, 2024 · 3 comments
Open

Custom resource state metrics wildcard not working #2384

akselleirv opened this issue Apr 30, 2024 · 3 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@akselleirv
Copy link

akselleirv commented Apr 30, 2024

What happened:

Metrics from custom resource is not produced when wildcard is used in kind field.

What you expected to happen:

The wildcard should produce metrics for all kinds.

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

I have the following helm chart values file

rbac:
  extraRules:
    - apiGroups: ["azure.tnnova.io"]
      resources: ["*"]
      verbs: ["get", "list", "watch"]
    - apiGroups: ["apiextensions.k8s.io"]
      resources: ["customresourcedefinitions"]
      verbs: ["get", "list", "watch"]
customResourceState:
  enabled: true
  config:
    kind: CustomResourceStateMetrics
    spec:
      resources:
        - groupVersionKind:
            group: "azure.tnnova.io"
            version: "v1alpha1"
            kind: "UserAssignedIdentity"
          labelsFromPath:
            namespace: [metadata, namespace]
          metrics:
              - name: status_conditions
                help: "The condition of the resource"
                each:
                  type: StateSet
                  stateSet:
                    path: [status, conditions, "0"]
                    labelName: status
                    valueFrom: [status]
                    list: ["True", "False", "Unknown"]
                    labelsFromPath:
                      type: [type]

It produces the following metrics:

# HELP kube_customresource_status_conditions The condition of the resource
# TYPE kube_customresource_status_conditions stateset
kube_customresource_status_conditions{customresource_group="azure.tnnova.io",customresource_kind="UserAssignedIdentity",customresource_version="v1alpha1",namespace="s01234-example-system",status="False",type="Ready"} 0
kube_customresource_status_conditions{customresource_group="azure.tnnova.io",customresource_kind="UserAssignedIdentity",customresource_version="v1alpha1",namespace="s01234-example-system",status="True",type="Ready"} 1
kube_customresource_status_conditions{customresource_group="azure.tnnova.io",customresource_kind="UserAssignedIdentity",customresource_version="v1alpha1",namespace="s01234-example-system",status="Unknown",type="Ready"} 0

However, when I replace kind="UserAssignedIdentity" to kind="*" , like:

...
        - groupVersionKind:
            group: "azure.tnnova.io"
            version: "v1alpha1"
            kind: "*"
...

Then it no longer produces any metrics. I have verified that the kube-state-metrics service account has list,watch,get on customresourcedefintions.

Anything else we need to know?:

Environment:

  • kube-state-metrics version: 2.12.0
  • Kubernetes version (use kubectl version): v1.30.0
  • Cloud provider or hardware configuration: kind
  • Other info:
@akselleirv akselleirv added the kind/bug Categorizes issue or PR as related to a bug. label Apr 30, 2024
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 30, 2024
@logicalhan
Copy link
Member

/triage accepted
/assign @rexagod

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 2, 2024
@Thib17
Copy link

Thib17 commented Aug 19, 2024

I was able to reproduce the issue inv2.12.0 but not in v2.11.0.
After looking at the changes between those two versions I believe the bug is due to the following change in v2.11.0...v2.12.0#diff-60450a33adea08c953656dd1e78a80e9f3b279bbc7656dedf31fd1a0c7fc1196R119

				if header == lastHeader {
-					writer.stores[0].headers[i] = ""
-				} else {
-					lastHeader = header
+					writer.stores[0].headers = append(writer.stores[0].headers[:i], writer.stores[0].headers[i+1:]...)
+
+					// Do not increment the index, as the next header is now at the current index.
+					continue
				}

For some reason the behavior went:

  • from [writer{stores: [store{headers:["h1"]}]}, writer{stores: [store{headers:["h1"]}]}] => [writer{stores: [store{headers:["h1"]}]}, writer{stores: [store{headers:[""]}]}]
  • to___ [writer{stores: [store{headers:["h1"]}]}, writer{stores: [store{headers:["h1"]}]}] => [writer{stores: [store{headers:["h1"]}]}, writer{stores: [store{headers:[]}]}]

Note that [""] is now []
It used to empty the string value of the headers before writing them to the output, but now it also change the number of headers.
Therefore some writers are not present in the output anymore.

I would suggest to rollback to the previous behavior by going back to writer.stores[0].headers[i] = ""
I tried this, and it appear to fix the bug, but it require to rewrite all the unitests of the function called SanitizeHeaders. The unitest are enforcing the removal of headers wich cause the bug afaik.
What do you think ?
I can prepare a PR to implement this fix.

@mrueg
Copy link
Member

mrueg commented Aug 19, 2024

@rexagod can you take a look? I believe this was introduced in #2270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

6 participants