@@ -30,7 +30,7 @@ import (
30
30
var (
31
31
operation = []string {"controller_namespace" , "controller_class" , "controller_pod" }
32
32
ingressOperation = []string {"controller_namespace" , "controller_class" , "controller_pod" , "namespace" , "ingress" }
33
- sslLabelHost = []string {"namespace" , "class" , "host" , "secret_name" }
33
+ sslLabelHost = []string {"namespace" , "class" , "host" , "secret_name" , "identifier" }
34
34
sslInfoLabels = []string {"namespace" , "class" , "host" , "secret_name" , "identifier" , "issuer_organization" , "issuer_common_name" , "serial_number" , "public_key_algorithm" }
35
35
orphanityLabels = []string {"controller_namespace" , "controller_class" , "controller_pod" , "namespace" , "ingress" , "type" }
36
36
)
@@ -305,6 +305,7 @@ func (cm *Controller) SetSSLExpireTime(servers []*ingress.Server) {
305
305
}
306
306
labels ["host" ] = s .Hostname
307
307
labels ["secret_name" ] = s .SSLCert .Name
308
+ labels ["identifier" ] = s .SSLCert .Identifier ()
308
309
309
310
cm .sslExpireTime .With (labels ).Set (float64 (s .SSLCert .ExpireTime .Unix ()))
310
311
}
@@ -337,9 +338,9 @@ func (cm *Controller) SetSSLInfo(servers []*ingress.Server) {
337
338
}
338
339
}
339
340
340
- // RemoveMetrics removes metrics for hostnames not available anymore
341
- func (cm * Controller ) RemoveMetrics (hosts , certificates []string , registry prometheus.Gatherer ) {
342
- cm .removeSSLExpireMetrics (true , hosts , registry )
341
+ // RemoveMetrics removes metrics for certificates not available anymore by identifier
342
+ func (cm * Controller ) RemoveMetrics (certificates []string , registry prometheus.Gatherer ) {
343
+ cm .removeSSLExpireMetrics (true , certificates , registry )
343
344
cm .removeCertificatesMetrics (true , certificates , registry )
344
345
}
345
346
@@ -390,14 +391,14 @@ func (cm *Controller) removeCertificatesMetrics(onlyDefinedHosts bool, certifica
390
391
}
391
392
}
392
393
393
- func (cm * Controller ) removeSSLExpireMetrics (onlyDefinedHosts bool , hosts []string , registry prometheus.Gatherer ) {
394
+ func (cm * Controller ) removeSSLExpireMetrics (onlyDefinedCerts bool , certificates []string , registry prometheus.Gatherer ) {
394
395
mfs , err := registry .Gather ()
395
396
if err != nil {
396
397
klog .ErrorS (err , "Error gathering metrics" )
397
398
return
398
399
}
399
400
400
- toRemove := sets .NewString (hosts ... )
401
+ toRemove := sets .NewString (certificates ... )
401
402
402
403
for _ , mf := range mfs {
403
404
metricName := mf .GetName ()
@@ -414,19 +415,24 @@ func (cm *Controller) removeSSLExpireMetrics(onlyDefinedHosts bool, hosts []stri
414
415
// remove labels that are constant
415
416
deleteConstants (labels )
416
417
418
+ identifier , ok := labels ["identifier" ]
419
+ if ! ok {
420
+ continue
421
+ }
422
+
417
423
host , ok := labels ["host" ]
418
424
if ! ok {
419
425
continue
420
426
}
421
427
422
- if onlyDefinedHosts && ! toRemove .Has (host ) {
428
+ if onlyDefinedCerts && ! toRemove .Has (identifier ) {
423
429
continue
424
430
}
425
431
426
- klog .V (2 ).InfoS ("Removing prometheus metric" , "gauge" , metricName , "host" , host )
432
+ klog .V (2 ).InfoS ("Removing prometheus metric" , "gauge" , metricName , "host" , host , "identifier" , identifier )
427
433
removed := cm .sslExpireTime .Delete (labels )
428
434
if ! removed {
429
- klog .V (2 ).InfoS ("metric removed" , "metric" , metricName , "host" , host , "labels" , labels )
435
+ klog .V (2 ).InfoS ("metric removed" , "metric" , metricName , "host" , host , "identifier" , identifier , " labels" , labels )
430
436
}
431
437
}
432
438
}
0 commit comments