Skip to content

Map Kubernetes secret labels to prometheus metrics labels #207

@deviarchscs

Description

@deviarchscs

First of all, thank you for this project!

I have a use case where I need to attach additional info on metrics exposed by ssl-exporter. So far I'm doing a workaround by doing leveraging the relabeling feature of prometheus on the name of the secret, this works but is kind of ugly and I think it would be a real added value of having a way to directly generate prometheus metrics label based on secret labels. See the example below:

Example of secret read by ssl-exporter:

apiVersion: v1
kind: Secret
metadata:
  name: my-secret-tls
  labels:
    ssl-exporter.env: DEV
    ssl-exporter.app: myapp
    ssl-exporter.otherlabel: myotherlabelvalue
type: kubernetes.io/tls
stringData:
  tls.crt: |
    -----BEGIN CERTIFICATE-----
    (...)
    -----END CERTIFICATE-----
  tls.key: ""

I excpect above k8s secret to generate following prometheus metric:

ssl_kubernetes_cert_not_after{env="DEV", app="myapp", otherlabel="myotherlabelvalue", job="...", cn="...", (...)}

Notice how secret labels are transformed into prometheus metrics labels.

I guess the implementation would be done somewhere here:

func collectKubernetesSecretMetrics(secrets []v1.Secret, registry *prometheus.Registry) error {

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions