From d1de1cd053aaa6f5f95c3bf2351bca6b4cf40a40 Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Thu, 25 Jan 2018 21:38:57 -0800 Subject: [PATCH] Upgrade to micrometer 1.0.0-SNAPSHOT Move to the snapshots and rework changed APIs in preparation for the upcoming rc8 release. See gh-11575 --- .../amqp/RabbitMetricsConfiguration.java | 3 +- .../ganglia/GangliaExportConfiguration.java | 4 +- .../graphite/GraphiteExportConfiguration.java | 4 +- .../export/jmx/JmxExportConfiguration.java | 2 +- .../DataSourcePoolMetricsConfiguration.java | 3 +- .../metrics/MeterRegistryConfigurerTests.java | 8 +-- ...ricsAutoConfigurationIntegrationTests.java | 9 ++- .../MetricsAutoConfigurationTests.java | 18 +++--- .../amqp/RabbitMetricsConfigurationTests.java | 11 ++-- .../cache/CacheMetricsConfigurationTests.java | 20 +++---- ...RestTemplateMetricsConfigurationTests.java | 4 +- .../metrics/cache/CacheMetricsRegistrar.java | 8 +-- .../metrics/web/servlet/WebMvcMetrics.java | 10 ++-- .../metrics/amqp/RabbitMetricsTests.java | 9 ++- .../cache/CacheMetricsRegistrarTests.java | 6 +- ...ingIntegrationMetricsIntegrationTests.java | 12 ++-- .../jdbc/DataSourcePoolMetricsTests.java | 8 +-- .../MetricsRestTemplateCustomizerTests.java | 7 +-- .../WebMvcMetricsFilterAutoTimedTests.java | 5 +- .../web/servlet/WebMvcMetricsFilterTests.java | 56 +++++++++---------- .../WebMvcMetricsIntegrationTests.java | 13 ++--- .../spring-boot-dependencies/pom.xml | 2 +- 22 files changed, 102 insertions(+), 120 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java index 5eda78a281..b0664076f6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.amqp; -import java.util.List; import java.util.Map; import com.rabbitmq.client.ConnectionFactory; @@ -67,7 +66,7 @@ public class RabbitMetricsConfiguration { private void bindConnectionFactoryToRegistry(String beanName, AbstractConnectionFactory connectionFactory) { - List tags = Tags.zip("name", getConnectionFactoryName(beanName)); + Iterable tags = Tags.zip("name", getConnectionFactoryName(beanName)); new RabbitMetrics(connectionFactory.getRabbitConnectionFactory(), this.metricName, tags).bindTo(this.registry); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java index 160d56651f..6a04e7d943 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ public class GangliaExportConfiguration { @ConditionalOnProperty(value = "management.metrics.export.ganglia.enabled", matchIfMissing = true) public MetricsExporter gangliaExporter(GangliaConfig gangliaConfig, HierarchicalNameMapper nameMapper, Clock clock) { - return () -> new GangliaMeterRegistry(gangliaConfig, nameMapper, clock); + return () -> new GangliaMeterRegistry(gangliaConfig, clock, nameMapper); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java index 898799e0b7..beafe8aee7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ public class GraphiteExportConfiguration { @ConditionalOnProperty(value = "management.metrics.export.graphite.enabled", matchIfMissing = true) public MetricsExporter graphiteExporter(GraphiteConfig graphiteConfig, HierarchicalNameMapper nameMapper, Clock clock) { - return () -> new GraphiteMeterRegistry(graphiteConfig, nameMapper, clock); + return () -> new GraphiteMeterRegistry(graphiteConfig, clock, nameMapper); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxExportConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxExportConfiguration.java index de71666e55..b6be253897 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxExportConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxExportConfiguration.java @@ -50,7 +50,7 @@ public class JmxExportConfiguration { @ConditionalOnProperty(value = "management.metrics.export.jmx.enabled", matchIfMissing = true) public MetricsExporter jmxExporter(JmxConfig config, HierarchicalNameMapper nameMapper, Clock clock) { - return () -> new JmxMeterRegistry(config, nameMapper, clock); + return () -> new JmxMeterRegistry(config, clock, nameMapper); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java index 96d2e559f7..9d383cfa52 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.jdbc; import java.util.Collection; -import java.util.List; import java.util.Map; import javax.sql.DataSource; @@ -69,7 +68,7 @@ public class DataSourcePoolMetricsConfiguration { } private void bindDataSourceToRegistry(String beanName, DataSource dataSource) { - List tags = Tags.zip("name", getDataSourceName(beanName)); + Iterable tags = Tags.zip("name", getDataSourceName(beanName)); new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName, tags).bindTo(this.registry); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java index 2b3d4e98c7..3fb585ef2b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java @@ -42,8 +42,8 @@ public class MeterRegistryConfigurerTests { UserConfigurations.of(MeterRegistryConfigurerConfiguration.class)) .withPropertyValues("management.metrics.use-global-registry=false") .run((context) -> assertThat(context.getBean(MeterRegistry.class) - .find("jvm.memory.used").tags("region", "us-east-1").gauge()) - .isPresent()); + .get("jvm.memory.used").tags("region", "us-east-1").gauge()) + .isNotNull()); } @Test @@ -54,8 +54,8 @@ public class MeterRegistryConfigurerTests { UserConfigurations.of(MeterRegistryConfigurerConfiguration.class)) .withPropertyValues("management.metrics.use-global-registry=false") .run((context) -> assertThat(context.getBean(MeterRegistry.class) - .find("my.thing").tags("region", "us-east-1").gauge()) - .isPresent()); + .get("my.thing").tags("region", "us-east-1").gauge()) + .isNotNull()); } static class MeterRegistryConfigurerConfiguration { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationIntegrationTests.java index bc57384bad..cb0c965863 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationIntegrationTests.java @@ -22,7 +22,6 @@ import java.util.Set; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.Statistic; import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.logging.LogbackMetrics; @@ -94,15 +93,15 @@ public class MetricsAutoConfigurationIntegrationTests { "{\"message\": \"hello\"}", MediaType.APPLICATION_JSON)); assertThat(this.external.getForObject("/api/external", Map.class)) .containsKey("message"); - assertThat(this.registry.find("http.client.requests").value(Statistic.Count, 1.0) - .timer()).isPresent(); + assertThat(this.registry.get("http.client.requests").timer().count()) + .isEqualTo(1); } @Test public void requestMappingIsInstrumented() { this.loopback.getForObject("/api/people", Set.class); - assertThat(this.registry.find("http.server.requests").value(Statistic.Count, 1.0) - .timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").timer().count()) + .isEqualTo(1); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java index c2c520768c..4af25491bc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java @@ -54,8 +54,8 @@ public class MetricsAutoConfigurationTests { .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("data.source.max.connections") - .tags("name", "dataSource").meter()).isPresent(); + registry.get("data.source.max.connections").tags("name", "dataSource") + .meter(); }); } @@ -69,8 +69,8 @@ public class MetricsAutoConfigurationTests { .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("custom.name.max.connections") - .tags("name", "dataSource").meter()).isPresent(); + registry.get("custom.name.max.connections").tags("name", "dataSource") + .meter(); }); } @@ -85,7 +85,7 @@ public class MetricsAutoConfigurationTests { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); assertThat(registry.find("data.source.max.connections") - .tags("name", "dataSource").meter()).isNotPresent(); + .tags("name", "dataSource").meter()).isNull(); }); } @@ -100,10 +100,10 @@ public class MetricsAutoConfigurationTests { context.getBean("secondOne", DataSource.class).getConnection() .getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("data.source.max.connections") - .tags("name", "first").meter()).isPresent(); - assertThat(registry.find("data.source.max.connections") - .tags("name", "secondOne").meter()).isPresent(); + registry.get("data.source.max.connections").tags("name", "first") + .meter(); + registry.get("data.source.max.connections").tags("name", "secondOne") + .meter(); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java index d92518bb92..1372d4d89c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java @@ -46,7 +46,7 @@ public class RabbitMetricsConfigurationTests { public void autoConfiguredConnectionFactoryIsInstrumented() { this.contextRunner.run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("rabbitmq.connections").meter()).isPresent(); + registry.get("rabbitmq.connections").meter(); }); } @@ -56,10 +56,8 @@ public class RabbitMetricsConfigurationTests { .withPropertyValues("management.metrics.rabbitmq.metric-name=custom.name") .run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("custom.name.connections").meter()) - .isPresent(); - assertThat(registry.find("rabbitmq.connections").meter()) - .isNotPresent(); + registry.get("custom.name.connections").meter(); + assertThat(registry.find("rabbitmq.connections").meter()).isNull(); }); } @@ -69,8 +67,7 @@ public class RabbitMetricsConfigurationTests { .withPropertyValues("management.metrics.rabbitmq.instrument=false") .run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("rabbitmq.connections").meter()) - .isNotPresent(); + assertThat(registry.find("rabbitmq.connections").meter()).isNull(); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsConfigurationTests.java index c8e9ed97ee..c398bc68fb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsConfigurationTests.java @@ -48,10 +48,10 @@ public class CacheMetricsConfigurationTests { this.contextRunner.withPropertyValues("spring.cache.type=caffeine", "spring.cache.cache-names=cache1,cache2").run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("cache.requests").tags("name", "cache1") - .tags("cacheManager", "cacheManager").meter()).isPresent(); - assertThat(registry.find("cache.requests").tags("name", "cache2") - .tags("cacheManager", "cacheManager").meter()).isPresent(); + registry.get("cache.requests").tags("name", "cache1") + .tags("cacheManager", "cacheManager").meter(); + registry.get("cache.requests").tags("name", "cache2") + .tags("cacheManager", "cacheManager").meter(); }); } @@ -62,10 +62,8 @@ public class CacheMetricsConfigurationTests { "spring.cache.type=caffeine", "spring.cache.cache-names=cache1") .run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat( - registry.find("custom.name.requests").tags("name", "cache1") - .tags("cacheManager", "cacheManager").meter()) - .isPresent(); + registry.get("custom.name.requests").tags("name", "cache1") + .tags("cacheManager", "cacheManager").meter(); }); } @@ -75,9 +73,9 @@ public class CacheMetricsConfigurationTests { "spring.cache.cache-names=cache1,cache2").run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); assertThat(registry.find("cache.requests").tags("name", "cache1") - .tags("cacheManager", "cacheManager").meter()).isNotPresent(); + .tags("cacheManager", "cacheManager").meter()).isNull(); assertThat(registry.find("cache.requests").tags("name", "cache2") - .tags("cacheManager", "cacheManager").meter()).isNotPresent(); + .tags("cacheManager", "cacheManager").meter()).isNull(); }); } @@ -89,7 +87,7 @@ public class CacheMetricsConfigurationTests { .run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); assertThat(registry.find("cache.requests").tags("name", "cache1") - .tags("cacheManager", "cacheManager").meter()).isNotPresent(); + .tags("cacheManager", "cacheManager").meter()).isNull(); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java index 64e7467da7..4452990ba8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java @@ -74,10 +74,10 @@ public class RestTemplateMetricsConfigurationTests { private void validateRestTemplate(RestTemplate restTemplate, MeterRegistry registry) { MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate); server.expect(requestTo("/test")).andRespond(withStatus(HttpStatus.OK)); - assertThat(registry.find("http.client.requests").meter()).isNotPresent(); + assertThat(registry.find("http.client.requests").meter()).isNull(); assertThat(restTemplate.getForEntity("/test", Void.class).getStatusCode()) .isEqualTo(HttpStatus.OK); - assertThat(registry.find("http.client.requests").meter()).isPresent(); + registry.get("http.client.requests").meter(); } @Configuration diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrar.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrar.java index b23a8f845b..2c4e7972cf 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrar.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrar.java @@ -79,8 +79,8 @@ public class CacheMetricsRegistrar { } @SuppressWarnings({ "unchecked", "rawtypes" }) - private MeterBinder getMeterBinder(Cache cache, List tags) { - tags.addAll(getAdditionalTags(cache)); + private MeterBinder getMeterBinder(Cache cache, Iterable tags) { + Iterable withAdditionalTags = Tags.concat(tags, getAdditionalTags(cache)); for (CacheMeterBinderProvider binderProvider : this.binderProviders) { Class cacheType = ResolvableType .forClass(CacheMeterBinderProvider.class, binderProvider.getClass()) @@ -88,7 +88,7 @@ public class CacheMetricsRegistrar { if (cacheType.isInstance(cache)) { try { MeterBinder meterBinder = ((CacheMeterBinderProvider) binderProvider) - .getMeterBinder(cache, this.metricName, tags); + .getMeterBinder(cache, this.metricName, withAdditionalTags); if (meterBinder != null) { return meterBinder; } @@ -120,7 +120,7 @@ public class CacheMetricsRegistrar { * @param cache the cache * @return a list of additional tags to associate to that {@code cache}. */ - protected List getAdditionalTags(Cache cache) { + protected Iterable getAdditionalTags(Cache cache) { return Tags.zip("name", cache.getName()); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java index 11d0ee7cad..3a7025490b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java @@ -64,7 +64,7 @@ public class WebMvcMetrics { private static final Log logger = LogFactory.getLog(WebMvcMetrics.class); - private final Map longTaskTimerIds = Collections + private final Map longTaskTimerSamples = Collections .synchronizedMap(new IdentityHashMap<>()); private final MeterRegistry registry; @@ -103,7 +103,7 @@ public class WebMvcMetrics { logWarning(request, handler); return; } - this.longTaskTimerIds.put(request, + this.longTaskTimerSamples.put(request, longTaskTimer(config, request, handler).start()); }); } @@ -138,8 +138,10 @@ public class WebMvcMetrics { private void completeLongTimerTask(HttpServletRequest request, Object handler, TimerConfig config) { if (config.getName() != null) { - longTaskTimer(config, request, handler) - .stop(this.longTaskTimerIds.remove(request)); + LongTaskTimer.Sample sample = this.longTaskTimerSamples.remove(request); + if (sample != null) { + sample.stop(); + } } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java index 621861abba..e16bce11fc 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java @@ -36,7 +36,7 @@ public class RabbitMetricsTests { ConnectionFactory connectionFactory = mockConnectionFactory(); SimpleMeterRegistry registry = new SimpleMeterRegistry(); new RabbitMetrics(connectionFactory, "rabbit", null).bindTo(registry); - assertThat(registry.find("rabbit.connections").meter()).isPresent(); + registry.get("rabbit.connections"); } @Test @@ -45,10 +45,9 @@ public class RabbitMetricsTests { SimpleMeterRegistry registry = new SimpleMeterRegistry(); new RabbitMetrics(connectionFactory, "test", Tags.zip("env", "prod")) .bindTo(registry); - assertThat(registry.find("test.connections").tags("env", "prod").meter()) - .isPresent(); - assertThat(registry.find("test.connections").tags("env", "dev").meter()) - .isNotPresent(); + assertThat(registry.get("test.connections").tags("env", "prod").meter()) + .isNotNull(); + assertThat(registry.find("test.connections").tags("env", "dev").meter()).isNull(); } private ConnectionFactory mockConnectionFactory() { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrarTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrarTests.java index bd3fbc5430..41ebac1e17 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrarTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrarTests.java @@ -42,8 +42,8 @@ public class CacheMetricsRegistrarTests { "root", Collections.singleton(new CaffeineCacheMeterBinderProvider())); assertThat(registrar.bindCacheToRegistry( new CaffeineCache("test", Caffeine.newBuilder().build()))).isTrue(); - assertThat(this.meterRegistry.find("root.requests").tags("name", "test").meter()) - .isPresent(); + assertThat(this.meterRegistry.get("root.requests").tags("name", "test").meter()) + .isNotNull(); } @Test @@ -53,7 +53,7 @@ public class CacheMetricsRegistrarTests { assertThat(registrar.bindCacheToRegistry( new CaffeineCache("test", Caffeine.newBuilder().build()))).isFalse(); assertThat(this.meterRegistry.find("root.requests").tags("name", "test").meter()) - .isNotPresent(); + .isNull(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java index 00d8c25504..978e8a8842 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java @@ -21,7 +21,6 @@ import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Statistic; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,13 +56,10 @@ public class SpringIntegrationMetricsIntegrationTests { @Test public void springIntegrationMetrics() { this.converter.fahrenheitToCelsius(68.0); - assertThat(this.registry.find("spring.integration.channel.sends") - .tags("channel", "convert.input").value(Statistic.Count, 1).meter()) - .isPresent(); - assertThat(this.registry.find("spring.integration.handler.duration.min").meter()) - .isPresent(); - assertThat(this.registry.find("spring.integration.sourceNames").meter()) - .isPresent(); + assertThat(this.registry.get("spring.integration.channel.sends") + .tags("channel", "convert.input").functionCounter().count()).isEqualTo(1); + this.registry.get("spring.integration.handler.duration.min").gauge(); + this.registry.get("spring.integration.sourceNames").meter(); } @Configuration diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java index 62c9901a5d..1e48a31651 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for {@link DataSourcePoolMetrics}. * @@ -52,8 +50,8 @@ public class DataSourcePoolMetricsTests { "metrics.use-global-registry=false") .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); - assertThat(context.getBean(MeterRegistry.class) - .find("data.source.max.connections").meter()).isPresent(); + context.getBean(MeterRegistry.class) + .get("data.source.max.connections").meter(); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/MetricsRestTemplateCustomizerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/MetricsRestTemplateCustomizerTests.java index ef392598de..59ce80a1c4 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/MetricsRestTemplateCustomizerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/MetricsRestTemplateCustomizerTests.java @@ -20,7 +20,6 @@ import java.util.stream.StreamSupport; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.Statistic; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.simple.SimpleConfig; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -71,9 +70,9 @@ public class MetricsRestTemplateCustomizerTests { .meters()).anySatisfy((m) -> assertThat( StreamSupport.stream(m.getId().getTags().spliterator(), false) .map(Tag::getKey)).doesNotContain("bucket")); - assertThat(this.registry.find("http.client.requests") - .tags("method", "GET", "uri", "/test/{id}", "status", "200") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.client.requests") + .tags("method", "GET", "uri", "/test/{id}", "status", "200").timer() + .count()).isEqualTo(1); assertThat(result).isEqualTo("OK"); mockServer.verify(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterAutoTimedTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterAutoTimedTests.java index 2aded2c655..70f2344af5 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterAutoTimedTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterAutoTimedTests.java @@ -72,9 +72,8 @@ public class WebMvcMetricsFilterAutoTimedTests { @Test public void metricsCanBeAutoTimed() throws Exception { this.mvc.perform(get("/api/10")).andExpect(status().isOk()); - assertThat( - this.registry.find("http.server.requests").tags("status", "200").timer()) - .hasValueSatisfying((t) -> assertThat(t.count()).isEqualTo(1)); + assertThat(this.registry.get("http.server.requests").tags("status", "200").timer() + .count()).isEqualTo(1L); } @Configuration diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterTests.java index 416b0ef357..34a784855f 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterTests.java @@ -34,7 +34,6 @@ import io.micrometer.core.annotation.Timed; import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Statistic; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.composite.CompositeMeterRegistry; import io.micrometer.core.instrument.config.MeterFilter; @@ -112,38 +111,38 @@ public class WebMvcMetricsFilterTests { @Test public void timedMethod() throws Exception { this.mvc.perform(get("/api/c1/10")).andExpect(status().isOk()); - assertThat(this.registry.find("http.server.requests") - .tags("status", "200", "uri", "/api/c1/{id}", "public", "true") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests") + .tags("status", "200", "uri", "/api/c1/{id}", "public", "true").timer() + .count()).isEqualTo(1L); } @Test public void subclassedTimedMethod() throws Exception { this.mvc.perform(get("/api/c1/metaTimed/10")).andExpect(status().isOk()); - assertThat(this.registry.find("http.server.requests") - .tags("status", "200", "uri", "/api/c1/metaTimed/{id}") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests") + .tags("status", "200", "uri", "/api/c1/metaTimed/{id}").timer().count()) + .isEqualTo(1L); } @Test public void untimedMethod() throws Exception { this.mvc.perform(get("/api/c1/untimed/10")).andExpect(status().isOk()); assertThat(this.registry.find("http.server.requests") - .tags("uri", "/api/c1/untimed/10").timer()).isEmpty(); + .tags("uri", "/api/c1/untimed/10").timer()).isNull(); } @Test public void timedControllerClass() throws Exception { this.mvc.perform(get("/api/c2/10")).andExpect(status().isOk()); - assertThat(this.registry.find("http.server.requests").tags("status", "200") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").tags("status", "200").timer() + .count()).isEqualTo(1L); } @Test public void badClientRequest() throws Exception { this.mvc.perform(get("/api/c1/oops")).andExpect(status().is4xxClientError()); - assertThat(this.registry.find("http.server.requests").tags("status", "400") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").tags("status", "400").timer() + .count()).isEqualTo(1L); } @Test @@ -151,8 +150,8 @@ public class WebMvcMetricsFilterTests { this.mvc.perform(get("/api/redirect") .header(RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER, "302")) .andExpect(status().is3xxRedirection()); - assertThat(this.registry.find("http.server.requests").tags("uri", "REDIRECTION") - .tags("status", "302").timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").tags("uri", "REDIRECTION") + .tags("status", "302").timer()).isNotNull(); } @Test @@ -160,8 +159,8 @@ public class WebMvcMetricsFilterTests { this.mvc.perform(get("/api/not/found") .header(RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER, "404")) .andExpect(status().is4xxClientError()); - assertThat(this.registry.find("http.server.requests").tags("uri", "NOT_FOUND") - .tags("status", "404").timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").tags("uri", "NOT_FOUND") + .tags("status", "404").timer()).isNotNull(); } @Test @@ -169,9 +168,8 @@ public class WebMvcMetricsFilterTests { assertThatCode(() -> this.mvc.perform(get("/api/c1/unhandledError/10")) .andExpect(status().isOk())) .hasRootCauseInstanceOf(RuntimeException.class); - assertThat(this.registry.find("http.server.requests") - .tags("exception", "RuntimeException").value(Statistic.Count, 1.0) - .timer()).isPresent(); + assertThat(this.registry.get("http.server.requests") + .tags("exception", "RuntimeException").timer().count()).isEqualTo(1L); } @Test @@ -180,30 +178,30 @@ public class WebMvcMetricsFilterTests { .andExpect(request().asyncStarted()).andReturn(); // the request is not prematurely recorded as complete assertThat(this.registry.find("http.server.requests").tags("uri", "/api/c1/async") - .timer()).isNotPresent(); + .timer()).isNull(); // while the mapping is running, it contributes to the activeTasks count - assertThat(this.registry.find("my.long.request").tags("region", "test") - .value(Statistic.Count, 1.0).longTaskTimer()).isPresent(); + assertThat(this.registry.get("my.long.request").tags("region", "test") + .longTaskTimer().activeTasks()).isEqualTo(1); // once the mapping completes, we can gather information about status, etc. this.asyncLatch.countDown(); this.mvc.perform(asyncDispatch(result)).andExpect(status().isOk()); - assertThat(this.registry.find("http.server.requests").tags("status", "200") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").tags("status", "200").timer() + .count()).isEqualTo(1L); } @Test public void endpointThrowsError() throws Exception { this.mvc.perform(get("/api/c1/error/10")).andExpect(status().is4xxClientError()); - assertThat(this.registry.find("http.server.requests").tags("status", "422") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests").tags("status", "422").timer() + .count()).isEqualTo(1L); } @Test public void regexBasedRequestMapping() throws Exception { this.mvc.perform(get("/api/c1/regex/.abc")).andExpect(status().isOk()); - assertThat(this.registry.find("http.server.requests") - .tags("uri", "/api/c1/regex/{id:\\.[a-z]+}").value(Statistic.Count, 1.0) - .timer()).isPresent(); + assertThat(this.registry.get("http.server.requests") + .tags("uri", "/api/c1/regex/{id:\\.[a-z]+}").timer().count()) + .isEqualTo(1L); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsIntegrationTests.java index aa6b3da154..d783d2a34a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsIntegrationTests.java @@ -20,7 +20,6 @@ import io.micrometer.core.annotation.Timed; import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.Statistic; import io.micrometer.core.instrument.simple.SimpleConfig; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.junit.Before; @@ -79,18 +78,18 @@ public class WebMvcMetricsIntegrationTests { @Test public void handledExceptionIsRecordedInMetricTag() throws Exception { this.mvc.perform(get("/api/handledError")).andExpect(status().is5xxServerError()); - assertThat(this.registry.find("http.server.requests") - .tags("exception", "Exception1", "status", "500") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests") + .tags("exception", "Exception1", "status", "500").timer().count()) + .isEqualTo(1L); } @Test public void rethrownExceptionIsRecordedInMetricTag() { assertThatCode(() -> this.mvc.perform(get("/api/rethrownError")) .andExpect(status().is5xxServerError())); - assertThat(this.registry.find("http.server.requests") - .tags("exception", "Exception2", "status", "500") - .value(Statistic.Count, 1.0).timer()).isPresent(); + assertThat(this.registry.get("http.server.requests") + .tags("exception", "Exception2", "status", "500").timer().count()) + .isEqualTo(1L); } @Configuration diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index f2efebbbe1..4322d5c65f 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -112,7 +112,7 @@ 1.2.3 1.16.20 2.2.1 - 1.0.0-rc.7 + 1.0.0-SNAPSHOT 6.2.2.jre8 2.13.0 1.7.0