Skip to content

Metrics have kind and namespace label values swapped when --group-by=resource is specified #555

@dabico

Description

@dabico

Describe the bug

When using the kor exporter, the kind and namespace labels in metrics have their values reversed. For namespaces:

$ k get namespaces
NAME         STATUS   AGE
default      Active   91d
shared-dev   Active   86d

I get the following exporter metrics

# HELP kubernetes_orphaned_resources Orphaned resources in Kubernetes
# TYPE kubernetes_orphaned_resources gauge
kubernetes_orphaned_resources{kind="default",namespace="ConfigMap",resourceName="script"} 1
# ...
kubernetes_orphaned_resources{kind="shared-dev",namespace="Secret",resourceName="secret"} 1
# ...
kubernetes_orphaned_resources{kind="shared-dev",namespace="Service",resourceName="some-service"} 1

To Reproduce

Installed an exporter running the latest version of kor via the most recent Helm chart (0.2.1):

kor:
  serviceAccount:
    name: orphaned-resource-finder
  prometheusExporter:
    name: orphaned-resource-finder-exporter
    args:
      - exporter
      - --resources=configmap,daemonset,deployment,horizontalpodautoscaler,ingress,job,poddisruptionbudget,pod,persistentvolumeclaim,persistentvolume,replicaset,rolebinding,role,secret,service,serviceaccount,statefulset,volumeattachment
      - --exclude-labels=app.kubernetes.io/managed-by=Helm,owner=helm
      - --exclude-namespaces=cert-manager,ingress-nginx,kube-system,kuberay,kueue-system,kyverno,logging,monitoring
      - --group-by=resource
      - --older-than=720h
    deployment:
      image:
        tag: v0.6.7
      resources:
        limits:
          cpu: 100m
          memory: 128Mi
    serviceMonitor:
      enabled: false

Expected behavior

# HELP kubernetes_orphaned_resources Orphaned resources in Kubernetes
# TYPE kubernetes_orphaned_resources gauge
kubernetes_orphaned_resources{namespace="default",kind="ConfigMap",resourceName="script"} 1
# ...
kubernetes_orphaned_resources{namespace="shared-dev",kind="Secret",resourceName="secret"} 1
# ...
kubernetes_orphaned_resources{namespace="shared-dev",kind="Service",resourceName="some-service"} 1

OS version, architecture and kor version
GKE version: 1.34.1-gke.3899001
Kor version: 0.6.7
Chart version: 0.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions