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

kube-state-metrics doesn't produce metric for Custom Resources #2453

Open
mlubanski opened this issue Jul 24, 2024 · 3 comments
Open

kube-state-metrics doesn't produce metric for Custom Resources #2453

mlubanski opened this issue Jul 24, 2024 · 3 comments
Assignees
Labels
kind/support Categorizes issue or PR as a support question. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@mlubanski
Copy link

What happened:

I defined configuration for Custom Resource State Metrics for my three CRD's (ReplicationGroup, ClusterInstance, RDSInstance)

After deploying it to cluster where I have kubernetes objects of all above types kube-state-metric is producing me expected crossplane_engine_version metric

But when I deploy same configuration to the cluster where I have only objects of RDSInstance type, crossplane_engine_version metric is missing

What you expected to happen:

Metric should be produced by kube-state-metric even if there are no real Objects of one type/kind listed in configuration below

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

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-state-metrics-crd-config
  namespace: crossplane-system
data:
  crd-config.yaml: |
    kind: CustomResourceStateMetrics
    spec:
      resources:
        - groupVersionKind:
            group: cache.aws.crossplane.io
            version: "*"
            kind: ReplicationGroup
          metricNamePrefix: crossplane
          labelsFromPath:
            managedResourceKind: [kind]
            claimKind: [metadata, ownerReferences, "[controller=true]", kind]
            cllaimName: [metadata, labels, crossplane.io/claim-name]
            claimNamespace: [metadata, labels, crossplane.io/claim-namespace]
          metrics:
            - name: "engine_version"
              help: "Engine Version"
              each:
                type: Info
                info:
                  labelsFromPath:
                    engineVersion: [spec, forProvider, engineVersion]
              commonLabels:
                custom_metric: "yes"
        - groupVersionKind:
            group: rds.aws.upbound.io
            version: "*"
            kind: ClusterInstance
          metricNamePrefix: crossplane
          labelsFromPath:
            managedResourceKind: [kind]
            claimKind: [metadata, ownerReferences, "[controller=true]", kind]
            cllaimName: [metadata, labels, crossplane.io/claim-name]
            claimNamespace: [metadata, labels, crossplane.io/claim-namespace]
          metrics:
            - name: "engine_version"
              help: "Engine Version"
              each:
                type: Info
                info:
                  labelsFromPath:
                    engineVersion: [status, atProvider, engineVersion]
              commonLabels:
                custom_metric: "yes"
        - groupVersionKind:
            group: database.aws.crossplane.io
            version: "*"
            kind: RDSInstance
          metricNamePrefix: crossplane
          labelsFromPath:
            managedResourceKind: [kind]
            claimKind: [metadata, ownerReferences, "[controller=true]", kind]
            cllaimName: [metadata, labels, crossplane.io/claim-name]
            claimNamespace: [metadata, labels, crossplane.io/claim-namespace]
          metrics:
            - name: "engine_version"
              help: "Engine Version"
              each:
                type: Info
                info:
                  labelsFromPath:
                    engineVersion: [spec, forProvider, engineVersion]
              commonLabels:
                custom_metric: "yes"

Environment:

  • kube-state-metrics version: 2.12.0
  • Kubernetes version: v1.28.9
  • Cloud provider: AWS
  • Other info:
@mlubanski mlubanski added the kind/bug Categorizes issue or PR as related to a bug. label Jul 24, 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 Jul 24, 2024
@dgrisonnet dgrisonnet added kind/support Categorizes issue or PR as a support question. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jul 25, 2024
@dgrisonnet
Copy link
Member

/assign @rexagod
/triage accepted

@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 Jul 25, 2024
@yiyang-shao
Copy link

Hi! We encountered the same issue in version 2.12.0 and 2.13.0. It works with version 2.11.0.
After a quick look, we found out that pkg/metrics_store/metrics_writer.go:120(SanitizeHeaders) is causing the problem.
In 2.12.0+, it removes the header from the slice.

// Nullify duplicate headers after the sanitization to not miss out on any new candidates.
if header == lastHeader {
	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
}

In 2.11.0, it is set to an empty string.

 writer.stores[0].headers[i] = ""

I suppose that this change probably further affects the behavior of the below loop in WriteAll function of MetricsWriter, causing that some metrics are missed in writing.

for i, help := range m.stores[0].headers {
      ...
      for _, s := range m.stores {
	for _, metricFamilies := range s.metrics {
	    _, err := w.Write(metricFamilies[i])
	    ...
	}
      }
}

@greenu
Copy link

greenu commented Aug 26, 2024

As suggested in this workaround #2366 (comment), just make help text unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. 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