Keep a strong reference to expiration in Gauge

This commit is contained in:
Chris Eager 2025-04-07 10:29:13 -05:00 committed by Chris Eager
parent ffa98e5b34
commit 37038c4a63
1 changed files with 8 additions and 5 deletions

View File

@ -8,8 +8,8 @@ package org.whispersystems.textsecuregcm.metrics;
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
import com.google.common.annotations.VisibleForTesting;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tags;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.Certificate;
@ -45,10 +45,13 @@ public class TlsCertificateExpirationUtil {
}
getIdentifiersAndExpirations(keyStore, keyStorePassword)
.forEach((id, expiration) -> {
Metrics.gauge(CERTIFICATE_EXPIRATION_GAUGE_NAME,
Tags.of("id", id), expiration, then -> Duration.between(Instant.now(), then).toSeconds());
});
.forEach((id, expiration) ->
Gauge.builder(CERTIFICATE_EXPIRATION_GAUGE_NAME, expiration,
then -> Duration.between(Instant.now(), then).toSeconds())
.tags("id", id)
.strongReference(true)
.register(Metrics.globalRegistry)
);
}
@VisibleForTesting