Skip to content

Commit d1de1cd

Browse files
jkschneiderphilwebb
authored andcommitted
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
1 parent b234501 commit d1de1cd

File tree

22 files changed

+102
-120
lines changed

22 files changed

+102
-120
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.amqp;
1818

19-
import java.util.List;
2019
import java.util.Map;
2120

2221
import com.rabbitmq.client.ConnectionFactory;
@@ -67,7 +66,7 @@ public void bindConnectionFactoriesToRegistry(
6766

6867
private void bindConnectionFactoryToRegistry(String beanName,
6968
AbstractConnectionFactory connectionFactory) {
70-
List<Tag> tags = Tags.zip("name", getConnectionFactoryName(beanName));
69+
Iterable<Tag> tags = Tags.zip("name", getConnectionFactoryName(beanName));
7170
new RabbitMetrics(connectionFactory.getRabbitConnectionFactory(), this.metricName,
7271
tags).bindTo(this.registry);
7372
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public GangliaConfig gangliaConfig(GangliaProperties gangliaProperties) {
5050
@ConditionalOnProperty(value = "management.metrics.export.ganglia.enabled", matchIfMissing = true)
5151
public MetricsExporter gangliaExporter(GangliaConfig gangliaConfig,
5252
HierarchicalNameMapper nameMapper, Clock clock) {
53-
return () -> new GangliaMeterRegistry(gangliaConfig, nameMapper, clock);
53+
return () -> new GangliaMeterRegistry(gangliaConfig, clock, nameMapper);
5454
}
5555

5656
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public GraphiteConfig graphiteConfig(GraphiteProperties graphiteProperties) {
5050
@ConditionalOnProperty(value = "management.metrics.export.graphite.enabled", matchIfMissing = true)
5151
public MetricsExporter graphiteExporter(GraphiteConfig graphiteConfig,
5252
HierarchicalNameMapper nameMapper, Clock clock) {
53-
return () -> new GraphiteMeterRegistry(graphiteConfig, nameMapper, clock);
53+
return () -> new GraphiteMeterRegistry(graphiteConfig, clock, nameMapper);
5454
}
5555

5656
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxExportConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public JmxConfig jmxConfig(JmxProperties jmxProperties) {
5050
@ConditionalOnProperty(value = "management.metrics.export.jmx.enabled", matchIfMissing = true)
5151
public MetricsExporter jmxExporter(JmxConfig config,
5252
HierarchicalNameMapper nameMapper, Clock clock) {
53-
return () -> new JmxMeterRegistry(config, nameMapper, clock);
53+
return () -> new JmxMeterRegistry(config, clock, nameMapper);
5454
}
5555

5656
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.actuate.autoconfigure.metrics.jdbc;
1818

1919
import java.util.Collection;
20-
import java.util.List;
2120
import java.util.Map;
2221

2322
import javax.sql.DataSource;
@@ -69,7 +68,7 @@ public void bindDataSourcesToRegistry(Map<String, DataSource> dataSources) {
6968
}
7069

7170
private void bindDataSourceToRegistry(String beanName, DataSource dataSource) {
72-
List<Tag> tags = Tags.zip("name", getDataSourceName(beanName));
71+
Iterable<Tag> tags = Tags.zip("name", getDataSourceName(beanName));
7372
new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName,
7473
tags).bindTo(this.registry);
7574
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public void commonTagsAreAppliedToAutoConfiguredBinders() {
4242
UserConfigurations.of(MeterRegistryConfigurerConfiguration.class))
4343
.withPropertyValues("management.metrics.use-global-registry=false")
4444
.run((context) -> assertThat(context.getBean(MeterRegistry.class)
45-
.find("jvm.memory.used").tags("region", "us-east-1").gauge())
46-
.isPresent());
45+
.get("jvm.memory.used").tags("region", "us-east-1").gauge())
46+
.isNotNull());
4747
}
4848

4949
@Test
@@ -54,8 +54,8 @@ public void commonTagsAreAppliedBeforeRegistryIsInjectableElsewhere() {
5454
UserConfigurations.of(MeterRegistryConfigurerConfiguration.class))
5555
.withPropertyValues("management.metrics.use-global-registry=false")
5656
.run((context) -> assertThat(context.getBean(MeterRegistry.class)
57-
.find("my.thing").tags("region", "us-east-1").gauge())
58-
.isPresent());
57+
.get("my.thing").tags("region", "us-east-1").gauge())
58+
.isNotNull());
5959
}
6060

6161
static class MeterRegistryConfigurerConfiguration {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationIntegrationTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import io.micrometer.core.instrument.MeterRegistry;
2424
import io.micrometer.core.instrument.MockClock;
25-
import io.micrometer.core.instrument.Statistic;
2625
import io.micrometer.core.instrument.binder.MeterBinder;
2726
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
2827
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
@@ -94,15 +93,15 @@ public void restTemplateIsInstrumented() {
9493
"{\"message\": \"hello\"}", MediaType.APPLICATION_JSON));
9594
assertThat(this.external.getForObject("/api/external", Map.class))
9695
.containsKey("message");
97-
assertThat(this.registry.find("http.client.requests").value(Statistic.Count, 1.0)
98-
.timer()).isPresent();
96+
assertThat(this.registry.get("http.client.requests").timer().count())
97+
.isEqualTo(1);
9998
}
10099

101100
@Test
102101
public void requestMappingIsInstrumented() {
103102
this.loopback.getForObject("/api/people", Set.class);
104-
assertThat(this.registry.find("http.server.requests").value(Statistic.Count, 1.0)
105-
.timer()).isPresent();
103+
assertThat(this.registry.get("http.server.requests").timer().count())
104+
.isEqualTo(1);
106105
}
107106

108107
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public void autoConfiguredDataSourceIsInstrumented() {
5454
.run((context) -> {
5555
context.getBean(DataSource.class).getConnection().getMetaData();
5656
MeterRegistry registry = context.getBean(MeterRegistry.class);
57-
assertThat(registry.find("data.source.max.connections")
58-
.tags("name", "dataSource").meter()).isPresent();
57+
registry.get("data.source.max.connections").tags("name", "dataSource")
58+
.meter();
5959
});
6060
}
6161

@@ -69,8 +69,8 @@ public void autoConfiguredDataSourceWithCustomMetricName() {
6969
.run((context) -> {
7070
context.getBean(DataSource.class).getConnection().getMetaData();
7171
MeterRegistry registry = context.getBean(MeterRegistry.class);
72-
assertThat(registry.find("custom.name.max.connections")
73-
.tags("name", "dataSource").meter()).isPresent();
72+
registry.get("custom.name.max.connections").tags("name", "dataSource")
73+
.meter();
7474
});
7575
}
7676

@@ -85,7 +85,7 @@ public void dataSourceInstrumentationCanBeDisabled() {
8585
context.getBean(DataSource.class).getConnection().getMetaData();
8686
MeterRegistry registry = context.getBean(MeterRegistry.class);
8787
assertThat(registry.find("data.source.max.connections")
88-
.tags("name", "dataSource").meter()).isNotPresent();
88+
.tags("name", "dataSource").meter()).isNull();
8989
});
9090
}
9191

@@ -100,10 +100,10 @@ public void allDataSourcesCanBeInstrumented() {
100100
context.getBean("secondOne", DataSource.class).getConnection()
101101
.getMetaData();
102102
MeterRegistry registry = context.getBean(MeterRegistry.class);
103-
assertThat(registry.find("data.source.max.connections")
104-
.tags("name", "first").meter()).isPresent();
105-
assertThat(registry.find("data.source.max.connections")
106-
.tags("name", "secondOne").meter()).isPresent();
103+
registry.get("data.source.max.connections").tags("name", "first")
104+
.meter();
105+
registry.get("data.source.max.connections").tags("name", "secondOne")
106+
.meter();
107107
});
108108
}
109109

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsConfigurationTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class RabbitMetricsConfigurationTests {
4646
public void autoConfiguredConnectionFactoryIsInstrumented() {
4747
this.contextRunner.run((context) -> {
4848
MeterRegistry registry = context.getBean(MeterRegistry.class);
49-
assertThat(registry.find("rabbitmq.connections").meter()).isPresent();
49+
registry.get("rabbitmq.connections").meter();
5050
});
5151
}
5252

@@ -56,10 +56,8 @@ public void autoConfiguredConnectionFactoryWithCustomMetricName() {
5656
.withPropertyValues("management.metrics.rabbitmq.metric-name=custom.name")
5757
.run((context) -> {
5858
MeterRegistry registry = context.getBean(MeterRegistry.class);
59-
assertThat(registry.find("custom.name.connections").meter())
60-
.isPresent();
61-
assertThat(registry.find("rabbitmq.connections").meter())
62-
.isNotPresent();
59+
registry.get("custom.name.connections").meter();
60+
assertThat(registry.find("rabbitmq.connections").meter()).isNull();
6361
});
6462
}
6563

@@ -69,8 +67,7 @@ public void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
6967
.withPropertyValues("management.metrics.rabbitmq.instrument=false")
7068
.run((context) -> {
7169
MeterRegistry registry = context.getBean(MeterRegistry.class);
72-
assertThat(registry.find("rabbitmq.connections").meter())
73-
.isNotPresent();
70+
assertThat(registry.find("rabbitmq.connections").meter()).isNull();
7471
});
7572
}
7673

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsConfigurationTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public void autoConfiguredCacheManagerIsInstrumented() {
4848
this.contextRunner.withPropertyValues("spring.cache.type=caffeine",
4949
"spring.cache.cache-names=cache1,cache2").run((context) -> {
5050
MeterRegistry registry = context.getBean(MeterRegistry.class);
51-
assertThat(registry.find("cache.requests").tags("name", "cache1")
52-
.tags("cacheManager", "cacheManager").meter()).isPresent();
53-
assertThat(registry.find("cache.requests").tags("name", "cache2")
54-
.tags("cacheManager", "cacheManager").meter()).isPresent();
51+
registry.get("cache.requests").tags("name", "cache1")
52+
.tags("cacheManager", "cacheManager").meter();
53+
registry.get("cache.requests").tags("name", "cache2")
54+
.tags("cacheManager", "cacheManager").meter();
5555
});
5656
}
5757

@@ -62,10 +62,8 @@ public void autoConfiguredCacheManagerWithCustomMetricName() {
6262
"spring.cache.type=caffeine", "spring.cache.cache-names=cache1")
6363
.run((context) -> {
6464
MeterRegistry registry = context.getBean(MeterRegistry.class);
65-
assertThat(
66-
registry.find("custom.name.requests").tags("name", "cache1")
67-
.tags("cacheManager", "cacheManager").meter())
68-
.isPresent();
65+
registry.get("custom.name.requests").tags("name", "cache1")
66+
.tags("cacheManager", "cacheManager").meter();
6967
});
7068
}
7169

@@ -75,9 +73,9 @@ public void autoConfiguredNonSupportedCacheManagerIsIgnored() {
7573
"spring.cache.cache-names=cache1,cache2").run((context) -> {
7674
MeterRegistry registry = context.getBean(MeterRegistry.class);
7775
assertThat(registry.find("cache.requests").tags("name", "cache1")
78-
.tags("cacheManager", "cacheManager").meter()).isNotPresent();
76+
.tags("cacheManager", "cacheManager").meter()).isNull();
7977
assertThat(registry.find("cache.requests").tags("name", "cache2")
80-
.tags("cacheManager", "cacheManager").meter()).isNotPresent();
78+
.tags("cacheManager", "cacheManager").meter()).isNull();
8179
});
8280
}
8381

@@ -89,7 +87,7 @@ public void cacheInstrumentationCanBeDisabled() {
8987
.run((context) -> {
9088
MeterRegistry registry = context.getBean(MeterRegistry.class);
9189
assertThat(registry.find("cache.requests").tags("name", "cache1")
92-
.tags("cacheManager", "cacheManager").meter()).isNotPresent();
90+
.tags("cacheManager", "cacheManager").meter()).isNull();
9391
});
9492
}
9593

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public void restTemplateCanBeCustomizedManually() {
7474
private void validateRestTemplate(RestTemplate restTemplate, MeterRegistry registry) {
7575
MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate);
7676
server.expect(requestTo("/test")).andRespond(withStatus(HttpStatus.OK));
77-
assertThat(registry.find("http.client.requests").meter()).isNotPresent();
77+
assertThat(registry.find("http.client.requests").meter()).isNull();
7878
assertThat(restTemplate.getForEntity("/test", Void.class).getStatusCode())
7979
.isEqualTo(HttpStatus.OK);
80-
assertThat(registry.find("http.client.requests").meter()).isPresent();
80+
registry.get("http.client.requests").meter();
8181
}
8282

8383
@Configuration

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrar.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ public boolean bindCacheToRegistry(Cache cache, Tag... tags) {
7979
}
8080

8181
@SuppressWarnings({ "unchecked", "rawtypes" })
82-
private MeterBinder getMeterBinder(Cache cache, List<Tag> tags) {
83-
tags.addAll(getAdditionalTags(cache));
82+
private MeterBinder getMeterBinder(Cache cache, Iterable<Tag> tags) {
83+
Iterable<Tag> withAdditionalTags = Tags.concat(tags, getAdditionalTags(cache));
8484
for (CacheMeterBinderProvider<?> binderProvider : this.binderProviders) {
8585
Class<?> cacheType = ResolvableType
8686
.forClass(CacheMeterBinderProvider.class, binderProvider.getClass())
8787
.resolveGeneric();
8888
if (cacheType.isInstance(cache)) {
8989
try {
9090
MeterBinder meterBinder = ((CacheMeterBinderProvider) binderProvider)
91-
.getMeterBinder(cache, this.metricName, tags);
91+
.getMeterBinder(cache, this.metricName, withAdditionalTags);
9292
if (meterBinder != null) {
9393
return meterBinder;
9494
}
@@ -120,7 +120,7 @@ private MeterBinder getMeterBinder(Cache cache, List<Tag> tags) {
120120
* @param cache the cache
121121
* @return a list of additional tags to associate to that {@code cache}.
122122
*/
123-
protected List<Tag> getAdditionalTags(Cache cache) {
123+
protected Iterable<Tag> getAdditionalTags(Cache cache) {
124124
return Tags.zip("name", cache.getName());
125125
}
126126

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class WebMvcMetrics {
6464

6565
private static final Log logger = LogFactory.getLog(WebMvcMetrics.class);
6666

67-
private final Map<HttpServletRequest, Long> longTaskTimerIds = Collections
67+
private final Map<HttpServletRequest, LongTaskTimer.Sample> longTaskTimerSamples = Collections
6868
.synchronizedMap(new IdentityHashMap<>());
6969

7070
private final MeterRegistry registry;
@@ -103,7 +103,7 @@ void preHandle(HttpServletRequest request, Object handler) {
103103
logWarning(request, handler);
104104
return;
105105
}
106-
this.longTaskTimerIds.put(request,
106+
this.longTaskTimerSamples.put(request,
107107
longTaskTimer(config, request, handler).start());
108108
});
109109
}
@@ -138,8 +138,10 @@ private void completeLongTimerTasks(HttpServletRequest request, Object handler)
138138
private void completeLongTimerTask(HttpServletRequest request, Object handler,
139139
TimerConfig config) {
140140
if (config.getName() != null) {
141-
longTaskTimer(config, request, handler)
142-
.stop(this.longTaskTimerIds.remove(request));
141+
LongTaskTimer.Sample sample = this.longTaskTimerSamples.remove(request);
142+
if (sample != null) {
143+
sample.stop();
144+
}
143145
}
144146
}
145147

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void connectionFactoryIsInstrumented() {
3636
ConnectionFactory connectionFactory = mockConnectionFactory();
3737
SimpleMeterRegistry registry = new SimpleMeterRegistry();
3838
new RabbitMetrics(connectionFactory, "rabbit", null).bindTo(registry);
39-
assertThat(registry.find("rabbit.connections").meter()).isPresent();
39+
registry.get("rabbit.connections");
4040
}
4141

4242
@Test
@@ -45,10 +45,9 @@ public void connectionFactoryWithTagsIsInstrumented() {
4545
SimpleMeterRegistry registry = new SimpleMeterRegistry();
4646
new RabbitMetrics(connectionFactory, "test", Tags.zip("env", "prod"))
4747
.bindTo(registry);
48-
assertThat(registry.find("test.connections").tags("env", "prod").meter())
49-
.isPresent();
50-
assertThat(registry.find("test.connections").tags("env", "dev").meter())
51-
.isNotPresent();
48+
assertThat(registry.get("test.connections").tags("env", "prod").meter())
49+
.isNotNull();
50+
assertThat(registry.find("test.connections").tags("env", "dev").meter()).isNull();
5251
}
5352

5453
private ConnectionFactory mockConnectionFactory() {

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrarTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public void bindToSupportedCache() {
4242
"root", Collections.singleton(new CaffeineCacheMeterBinderProvider()));
4343
assertThat(registrar.bindCacheToRegistry(
4444
new CaffeineCache("test", Caffeine.newBuilder().build()))).isTrue();
45-
assertThat(this.meterRegistry.find("root.requests").tags("name", "test").meter())
46-
.isPresent();
45+
assertThat(this.meterRegistry.get("root.requests").tags("name", "test").meter())
46+
.isNotNull();
4747
}
4848

4949
@Test
@@ -53,7 +53,7 @@ public void bindToUnsupportedCache() {
5353
assertThat(registrar.bindCacheToRegistry(
5454
new CaffeineCache("test", Caffeine.newBuilder().build()))).isFalse();
5555
assertThat(this.meterRegistry.find("root.requests").tags("name", "test").meter())
56-
.isNotPresent();
56+
.isNull();
5757
}
5858

5959
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricsIntegrationTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import io.micrometer.core.instrument.MeterRegistry;
24-
import io.micrometer.core.instrument.Statistic;
2524
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
2625
import org.junit.Test;
2726
import org.junit.runner.RunWith;
@@ -57,13 +56,10 @@ public class SpringIntegrationMetricsIntegrationTests {
5756
@Test
5857
public void springIntegrationMetrics() {
5958
this.converter.fahrenheitToCelsius(68.0);
60-
assertThat(this.registry.find("spring.integration.channel.sends")
61-
.tags("channel", "convert.input").value(Statistic.Count, 1).meter())
62-
.isPresent();
63-
assertThat(this.registry.find("spring.integration.handler.duration.min").meter())
64-
.isPresent();
65-
assertThat(this.registry.find("spring.integration.sourceNames").meter())
66-
.isPresent();
59+
assertThat(this.registry.get("spring.integration.channel.sends")
60+
.tags("channel", "convert.input").functionCounter().count()).isEqualTo(1);
61+
this.registry.get("spring.integration.handler.duration.min").gauge();
62+
this.registry.get("spring.integration.sourceNames").meter();
6763
}
6864

6965
@Configuration

0 commit comments

Comments
 (0)