|
|
@ -34,7 +34,6 @@ import io.micrometer.core.annotation.Timed;
|
|
|
|
import io.micrometer.core.instrument.Clock;
|
|
|
|
import io.micrometer.core.instrument.Clock;
|
|
|
|
import io.micrometer.core.instrument.Meter;
|
|
|
|
import io.micrometer.core.instrument.Meter;
|
|
|
|
import io.micrometer.core.instrument.MeterRegistry;
|
|
|
|
import io.micrometer.core.instrument.MeterRegistry;
|
|
|
|
import io.micrometer.core.instrument.Statistic;
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.Tag;
|
|
|
|
import io.micrometer.core.instrument.Tag;
|
|
|
|
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
|
|
|
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
|
|
|
import io.micrometer.core.instrument.config.MeterFilter;
|
|
|
|
import io.micrometer.core.instrument.config.MeterFilter;
|
|
|
@ -112,38 +111,38 @@ public class WebMvcMetricsFilterTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void timedMethod() throws Exception {
|
|
|
|
public void timedMethod() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c1/10")).andExpect(status().isOk());
|
|
|
|
this.mvc.perform(get("/api/c1/10")).andExpect(status().isOk());
|
|
|
|
assertThat(this.registry.find("http.server.requests")
|
|
|
|
assertThat(this.registry.get("http.server.requests")
|
|
|
|
.tags("status", "200", "uri", "/api/c1/{id}", "public", "true")
|
|
|
|
.tags("status", "200", "uri", "/api/c1/{id}", "public", "true").timer()
|
|
|
|
.value(Statistic.Count, 1.0).timer()).isPresent();
|
|
|
|
.count()).isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void subclassedTimedMethod() throws Exception {
|
|
|
|
public void subclassedTimedMethod() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c1/metaTimed/10")).andExpect(status().isOk());
|
|
|
|
this.mvc.perform(get("/api/c1/metaTimed/10")).andExpect(status().isOk());
|
|
|
|
assertThat(this.registry.find("http.server.requests")
|
|
|
|
assertThat(this.registry.get("http.server.requests")
|
|
|
|
.tags("status", "200", "uri", "/api/c1/metaTimed/{id}")
|
|
|
|
.tags("status", "200", "uri", "/api/c1/metaTimed/{id}").timer().count())
|
|
|
|
.value(Statistic.Count, 1.0).timer()).isPresent();
|
|
|
|
.isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void untimedMethod() throws Exception {
|
|
|
|
public void untimedMethod() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c1/untimed/10")).andExpect(status().isOk());
|
|
|
|
this.mvc.perform(get("/api/c1/untimed/10")).andExpect(status().isOk());
|
|
|
|
assertThat(this.registry.find("http.server.requests")
|
|
|
|
assertThat(this.registry.find("http.server.requests")
|
|
|
|
.tags("uri", "/api/c1/untimed/10").timer()).isEmpty();
|
|
|
|
.tags("uri", "/api/c1/untimed/10").timer()).isNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void timedControllerClass() throws Exception {
|
|
|
|
public void timedControllerClass() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c2/10")).andExpect(status().isOk());
|
|
|
|
this.mvc.perform(get("/api/c2/10")).andExpect(status().isOk());
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("status", "200")
|
|
|
|
assertThat(this.registry.get("http.server.requests").tags("status", "200").timer()
|
|
|
|
.value(Statistic.Count, 1.0).timer()).isPresent();
|
|
|
|
.count()).isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void badClientRequest() throws Exception {
|
|
|
|
public void badClientRequest() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c1/oops")).andExpect(status().is4xxClientError());
|
|
|
|
this.mvc.perform(get("/api/c1/oops")).andExpect(status().is4xxClientError());
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("status", "400")
|
|
|
|
assertThat(this.registry.get("http.server.requests").tags("status", "400").timer()
|
|
|
|
.value(Statistic.Count, 1.0).timer()).isPresent();
|
|
|
|
.count()).isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -151,8 +150,8 @@ public class WebMvcMetricsFilterTests {
|
|
|
|
this.mvc.perform(get("/api/redirect")
|
|
|
|
this.mvc.perform(get("/api/redirect")
|
|
|
|
.header(RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER, "302"))
|
|
|
|
.header(RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER, "302"))
|
|
|
|
.andExpect(status().is3xxRedirection());
|
|
|
|
.andExpect(status().is3xxRedirection());
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("uri", "REDIRECTION")
|
|
|
|
assertThat(this.registry.get("http.server.requests").tags("uri", "REDIRECTION")
|
|
|
|
.tags("status", "302").timer()).isPresent();
|
|
|
|
.tags("status", "302").timer()).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -160,8 +159,8 @@ public class WebMvcMetricsFilterTests {
|
|
|
|
this.mvc.perform(get("/api/not/found")
|
|
|
|
this.mvc.perform(get("/api/not/found")
|
|
|
|
.header(RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER, "404"))
|
|
|
|
.header(RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER, "404"))
|
|
|
|
.andExpect(status().is4xxClientError());
|
|
|
|
.andExpect(status().is4xxClientError());
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("uri", "NOT_FOUND")
|
|
|
|
assertThat(this.registry.get("http.server.requests").tags("uri", "NOT_FOUND")
|
|
|
|
.tags("status", "404").timer()).isPresent();
|
|
|
|
.tags("status", "404").timer()).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -169,9 +168,8 @@ public class WebMvcMetricsFilterTests {
|
|
|
|
assertThatCode(() -> this.mvc.perform(get("/api/c1/unhandledError/10"))
|
|
|
|
assertThatCode(() -> this.mvc.perform(get("/api/c1/unhandledError/10"))
|
|
|
|
.andExpect(status().isOk()))
|
|
|
|
.andExpect(status().isOk()))
|
|
|
|
.hasRootCauseInstanceOf(RuntimeException.class);
|
|
|
|
.hasRootCauseInstanceOf(RuntimeException.class);
|
|
|
|
assertThat(this.registry.find("http.server.requests")
|
|
|
|
assertThat(this.registry.get("http.server.requests")
|
|
|
|
.tags("exception", "RuntimeException").value(Statistic.Count, 1.0)
|
|
|
|
.tags("exception", "RuntimeException").timer().count()).isEqualTo(1L);
|
|
|
|
.timer()).isPresent();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -180,30 +178,30 @@ public class WebMvcMetricsFilterTests {
|
|
|
|
.andExpect(request().asyncStarted()).andReturn();
|
|
|
|
.andExpect(request().asyncStarted()).andReturn();
|
|
|
|
// the request is not prematurely recorded as complete
|
|
|
|
// the request is not prematurely recorded as complete
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("uri", "/api/c1/async")
|
|
|
|
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
|
|
|
|
// while the mapping is running, it contributes to the activeTasks count
|
|
|
|
assertThat(this.registry.find("my.long.request").tags("region", "test")
|
|
|
|
assertThat(this.registry.get("my.long.request").tags("region", "test")
|
|
|
|
.value(Statistic.Count, 1.0).longTaskTimer()).isPresent();
|
|
|
|
.longTaskTimer().activeTasks()).isEqualTo(1);
|
|
|
|
// once the mapping completes, we can gather information about status, etc.
|
|
|
|
// once the mapping completes, we can gather information about status, etc.
|
|
|
|
this.asyncLatch.countDown();
|
|
|
|
this.asyncLatch.countDown();
|
|
|
|
this.mvc.perform(asyncDispatch(result)).andExpect(status().isOk());
|
|
|
|
this.mvc.perform(asyncDispatch(result)).andExpect(status().isOk());
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("status", "200")
|
|
|
|
assertThat(this.registry.get("http.server.requests").tags("status", "200").timer()
|
|
|
|
.value(Statistic.Count, 1.0).timer()).isPresent();
|
|
|
|
.count()).isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void endpointThrowsError() throws Exception {
|
|
|
|
public void endpointThrowsError() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c1/error/10")).andExpect(status().is4xxClientError());
|
|
|
|
this.mvc.perform(get("/api/c1/error/10")).andExpect(status().is4xxClientError());
|
|
|
|
assertThat(this.registry.find("http.server.requests").tags("status", "422")
|
|
|
|
assertThat(this.registry.get("http.server.requests").tags("status", "422").timer()
|
|
|
|
.value(Statistic.Count, 1.0).timer()).isPresent();
|
|
|
|
.count()).isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void regexBasedRequestMapping() throws Exception {
|
|
|
|
public void regexBasedRequestMapping() throws Exception {
|
|
|
|
this.mvc.perform(get("/api/c1/regex/.abc")).andExpect(status().isOk());
|
|
|
|
this.mvc.perform(get("/api/c1/regex/.abc")).andExpect(status().isOk());
|
|
|
|
assertThat(this.registry.find("http.server.requests")
|
|
|
|
assertThat(this.registry.get("http.server.requests")
|
|
|
|
.tags("uri", "/api/c1/regex/{id:\\.[a-z]+}").value(Statistic.Count, 1.0)
|
|
|
|
.tags("uri", "/api/c1/regex/{id:\\.[a-z]+}").timer().count())
|
|
|
|
.timer()).isPresent();
|
|
|
|
.isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|