Browse Source

Merge branch '3.5.x'

Closes gh-48182
pull/48469/head
Moritz Halbritter 4 weeks ago
parent
commit
3a13d07301
  1. 27
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinder.java
  2. 9
      module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinderTests.java

27
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinder.java

@ -21,9 +21,7 @@ import java.time.Duration; @@ -21,9 +21,7 @@ import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -60,6 +58,8 @@ class SslMeterBinder implements MeterBinder { @@ -60,6 +58,8 @@ class SslMeterBinder implements MeterBinder {
private final BundleMetrics bundleMetrics = new BundleMetrics();
private final Set<MeterRegistry> boundMeterRegistries = ConcurrentHashMap.newKeySet();
SslMeterBinder(SslInfo sslInfo, SslBundles sslBundles) {
this(sslInfo, sslBundles, Clock.systemDefaultZone());
}
@ -79,13 +79,14 @@ class SslMeterBinder implements MeterBinder { @@ -79,13 +79,14 @@ class SslMeterBinder implements MeterBinder {
private void onBundleChange(String bundleName) {
BundleInfo bundle = this.sslInfo.getBundle(bundleName);
this.bundleMetrics.updateBundle(bundle);
for (MeterRegistry meterRegistry : this.bundleMetrics.getMeterRegistries()) {
for (MeterRegistry meterRegistry : this.boundMeterRegistries) {
createOrUpdateBundleMetrics(meterRegistry, bundle);
}
}
@Override
public void bindTo(MeterRegistry meterRegistry) {
this.boundMeterRegistries.add(meterRegistry);
for (BundleInfo bundle : this.sslInfo.getBundles()) {
createOrUpdateBundleMetrics(meterRegistry, bundle);
}
@ -148,18 +149,6 @@ class SslMeterBinder implements MeterBinder { @@ -148,18 +149,6 @@ class SslMeterBinder implements MeterBinder {
return gauges.getGauge(meterRegistry);
}
/**
* Returns all meter registries.
* @return all meter registries
*/
Collection<MeterRegistry> getMeterRegistries() {
Set<MeterRegistry> result = new HashSet<>();
for (Gauges metrics : this.gauges.values()) {
result.addAll(metrics.getMeterRegistries());
}
return result;
}
/**
* Updates the given bundle.
* @param bundle the updated bundle
@ -194,14 +183,6 @@ class SslMeterBinder implements MeterBinder { @@ -194,14 +183,6 @@ class SslMeterBinder implements MeterBinder {
return new Gauges(bundle, this.multiGauges);
}
/**
* Returns all meter registries.
* @return all meter registries
*/
Set<MeterRegistry> getMeterRegistries() {
return this.multiGauges.keySet();
}
private MultiGauge createGauge(MeterRegistry meterRegistry) {
return MultiGauge.builder(CHAIN_EXPIRY_METRIC_NAME)
.baseUnit("seconds")

9
module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinderTests.java

@ -90,6 +90,15 @@ class SslMeterBinderTests { @@ -90,6 +90,15 @@ class SslMeterBinderTests {
.hasDays(36889);
}
@Test
void shouldRegisterMetricsIfNoBundleExistsAtBindTime() {
DefaultSslBundleRegistry sslBundleRegistry = new DefaultSslBundleRegistry();
MeterRegistry meterRegistry = bindToRegistry(sslBundleRegistry);
sslBundleRegistry.registerBundle("dummy",
SslBundle.of(createSslStoreBundle("classpath:certificates/chains.p12")));
assertThat(meterRegistry.getMeters()).isNotEmpty();
}
private long findExpiryGauge(MeterRegistry meterRegistry, String chain, String certificateSerialNumber) {
return (long) meterRegistry.get("ssl.chain.expiry")
.tag("bundle", "test-0")

Loading…
Cancel
Save