use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.
the class SpringJaxrsTest method testJaxrsCustomHttpMethodMetric.
@Test
public void testJaxrsCustomHttpMethodMetric() {
final WebTarget target = createWebTarget();
try (Response r = target.request().trace()) {
assertThat(r.getStatus()).isEqualTo(Status.NOT_ACCEPTABLE.getStatusCode());
}
await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(serverTags).containsOnly(entry("exception", "None"), entry("method", "TRACE"), entry("operation", "traceBooks"), entry("uri", "/api/library"), entry("outcome", "CLIENT_ERROR"), entry("status", "406"));
RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "TRACE"), entry("operation", "UNKNOWN"), entry("uri", "http://localhost:" + port + "/api/library"), entry("outcome", "CLIENT_ERROR"), entry("status", "406"));
}
use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.
the class SpringJaxrsTest method testJaxrsExceptionMetric.
@Test
public void testJaxrsExceptionMetric() {
final WebTarget target = createWebTarget();
assertThatThrownBy(() -> target.request().delete(String.class)).isInstanceOf(InternalServerErrorException.class).hasMessageContaining("Internal Server Error");
await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(serverTags).containsOnly(entry("exception", "UnsupportedOperationException"), entry("method", "DELETE"), entry("operation", "deleteBooks"), entry("uri", "/api/library"), entry("outcome", "SERVER_ERROR"), entry("status", "500"));
RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "DELETE"), entry("operation", "UNKNOWN"), entry("uri", "http://localhost:" + port + "/api/library"), entry("outcome", "SERVER_ERROR"), entry("status", "500"));
}
use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.
the class SpringJaxrsTest method testJaxrsClientExceptionMetric.
@Test
public void testJaxrsClientExceptionMetric() {
final int fakePort = SocketUtils.findAvailableTcpPort();
final WebTarget target = ClientBuilder.newClient().register(new MetricsFeature(metricsProvider)).target("http://localhost:" + fakePort + "/api/library");
assertThatThrownBy(() -> target.request().delete(String.class)).isInstanceOf(ProcessingException.class).hasMessageContaining("Connection refused");
// no server meters
assertThat(registry.getMeters()).noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "DELETE"), entry("operation", "UNKNOWN"), entry("uri", "http://localhost:" + fakePort + "/api/library"), entry("outcome", "UNKNOWN"), entry("status", "UNKNOWN"));
}
use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.
the class SpringJaxrsTest method testJaxrsSuccessMetric.
@Test
public void testJaxrsSuccessMetric() {
final WebTarget target = createWebTarget();
try (Response r = target.request().get()) {
assertThat(r.getStatus()).isEqualTo(200);
}
await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(serverTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBooks"), entry("uri", "/api/library"), entry("outcome", "SUCCESS"), entry("status", "200"));
RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "UNKNOWN"), entry("uri", "http://localhost:" + port + "/api/library"), entry("outcome", "SUCCESS"), entry("status", "200"));
}
use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.
the class SpringClientOnlyJaxrsTest method testJaxrsClientExceptionMetric.
@Test
public void testJaxrsClientExceptionMetric() {
final WebTarget target = ClientBuilder.newClient().register(new MetricsFeature(metricsProvider)).target("http://localhost:" + port + "/api/library");
final Builder builder = target.request().header(HttpHeaders.CONTENT_TYPE, "text/plain");
assertThatThrownBy(() -> builder.delete(String.class)).isInstanceOf(BadRequestException.class).hasMessageContaining("Bad Request");
// no server meters
assertThat(registry.getMeters()).noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "DELETE"), entry("operation", "UNKNOWN"), entry("uri", "http://localhost:" + port + "/api/library"), entry("outcome", "CLIENT_ERROR"), entry("status", "400"));
}
Aggregations