aarnaud / vault-pki-exporter

Provides information about X509 certificate on HashiCorp Vault for Prometheus and InfluxDB
9 stars 12 forks source link

Fix metric labels for certcount metrics #4

Closed bchess closed 2 years ago

bchess commented 2 years ago

Fixing this panic

panic: inconsistent label cardinality: expected 8 label values but got 1 in []string{"pki/"}

goroutine 69 [running]:
github.com/prometheus/client_golang/prometheus.(*GaugeVec).WithLabelValues(0xc000053f10?, {0xc000358820?, 0xe17060?, 0x0?})
    /go/pkg/mod/github.com/prometheus/client_golang@v1.2.1/prometheus/gauge.go:217 +0x85
github.com/aarnaud/vault-pki-exporter/pkg/vault-mon.PromWatchCerts.func1()
    /go/src/vault-pki-exporter/pkg/vault-mon/prometheus.go:92 +0x547
created by github.com/aarnaud/vault-pki-exporter/pkg/vault-mon.PromWatchCerts
    /go/src/vault-pki-exporter/pkg/vault-mon/prometheus.go:67 +0x685
aarnaud commented 2 years ago

Can you provide more details ?

Vault versions ? how to reproduce ?

removing "serial", "common_name", "organization", "organizational_unit", "country", "province", "locality" it's not a solution we will lose information for Alert or Aggregation.

In fact you won't have metric for a specific cert.

bchess commented 2 years ago

The code as-is isn't setting the values for these other labels, see https://github.com/aarnaud/vault-pki-exporter/blob/master/pkg/vault-mon/prometheus.go#L92:

certcount.WithLabelValues(pkiname).Set(float64(len(pki.certs)))

Since it's the count of all certs, i.e. an aggregation, there's no "common_name" etc that'd make sense here

aarnaud commented 2 years ago

Oh, I see, It was added from a previous PR. Thanks for the fixed.