mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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
This commit is contained in:
parent
b234501af3
commit
d1de1cd053
@ -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<Tag> tags = Tags.zip("name", getConnectionFactoryName(beanName));
|
||||
Iterable<Tag> tags = Tags.zip("name", getConnectionFactoryName(beanName));
|
||||
new RabbitMetrics(connectionFactory.getRabbitConnectionFactory(), this.metricName,
|
||||
tags).bindTo(this.registry);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<Tag> tags = Tags.zip("name", getDataSourceName(beanName));
|
||||
Iterable<Tag> tags = Tags.zip("name", getDataSourceName(beanName));
|
||||
new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName,
|
||||
tags).bindTo(this.registry);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -79,8 +79,8 @@ public class CacheMetricsRegistrar {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private MeterBinder getMeterBinder(Cache cache, List<Tag> tags) {
|
||||
tags.addAll(getAdditionalTags(cache));
|
||||
private MeterBinder getMeterBinder(Cache cache, Iterable<Tag> tags) {
|
||||
Iterable<Tag> 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<Tag> getAdditionalTags(Cache cache) {
|
||||
protected Iterable<Tag> getAdditionalTags(Cache cache) {
|
||||
return Tags.zip("name", cache.getName());
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class WebMvcMetrics {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WebMvcMetrics.class);
|
||||
|
||||
private final Map<HttpServletRequest, Long> longTaskTimerIds = Collections
|
||||
private final Map<HttpServletRequest, LongTaskTimer.Sample> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -112,7 +112,7 @@
|
||||
<logback.version>1.2.3</logback.version>
|
||||
<lombok.version>1.16.20</lombok.version>
|
||||
<mariadb.version>2.2.1</mariadb.version>
|
||||
<micrometer.version>1.0.0-rc.7</micrometer.version>
|
||||
<micrometer.version>1.0.0-SNAPSHOT</micrometer.version>
|
||||
<mssql-jdbc.version>6.2.2.jre8</mssql-jdbc.version>
|
||||
<mockito.version>2.13.0</mockito.version>
|
||||
<mongo-driver-reactivestreams.version>1.7.0</mongo-driver-reactivestreams.version>
|
||||
|
Loading…
Reference in New Issue
Block a user