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:
committed by
Phillip Webb
parent
b234501af3
commit
d1de1cd053
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user