Don't update the notAfter Gauge with zeros (#6924)

I think ideally we'd only ever call exportMetrics
with a valid time, but that's a bit bigger of a refactor of this code.

This was the fix we lightly decided on in the discussion of #6635

Fixes #6635
This commit is contained in:
Matthew McPherrin 2023-05-31 14:19:28 -04:00 committed by GitHub
parent e72a8f9cac
commit 68e1c6bde7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -98,7 +98,9 @@ func (p TLSProbe) checkRoot(rootOrg, rootCN string) error {
// Export expiration timestamp and reason to Prometheus.
func (p TLSProbe) exportMetrics(notAfter time.Time, reason reason) {
p.notAfter.WithLabelValues(p.hostname).Set(float64(notAfter.Unix()))
if !notAfter.IsZero() {
p.notAfter.WithLabelValues(p.hostname).Set(float64(notAfter.Unix()))
}
p.reason.WithLabelValues(p.hostname, reasonToString[reason]).Inc()
}