use of com.nike.riposte.server.config.ServerConfig in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method initServerConfigMetrics_adds_expected_metrics.
@DataProvider(value = { "true", "false" })
@Test
public void initServerConfigMetrics_adds_expected_metrics(boolean includeServerConfigMetrics) {
// given
setupMetricRegistryAndCodahaleMetricsCollector();
CodahaleMetricsListener instance = CodahaleMetricsListener.newBuilder(cmcMock).withEndpointMetricsHandler(endpointMetricsHandlerMock).withIncludeServerConfigMetrics(includeServerConfigMetrics).build();
verifyServerStatisticMetrics(instance);
String expectedBossThreadsGaugeName = name(ServerConfig.class.getSimpleName(), "boss_threads");
String expectedWorkerThreadsGaugeName = name(ServerConfig.class.getSimpleName(), "worker_threads");
String expectedMaxRequestSizeInBytesGaugeName = name(ServerConfig.class.getSimpleName(), "max_request_size_in_bytes");
String expectedEndpointsListGaugeName = name(ServerConfig.class.getSimpleName(), "endpoints");
List<String> expectedEndpointsListValue = serverConfig.appEndpoints().stream().map(endpoint -> endpoint.getClass().getName() + "-" + instance.getMatchingHttpMethodsAsCombinedString(endpoint) + "-" + endpoint.requestMatcher().matchingPathTemplates()).collect(Collectors.toList());
// when
instance.initEndpointAndServerConfigMetrics(serverConfig);
// then
if (includeServerConfigMetrics) {
// Metrics for server config values
assertThat(registeredGauges).containsKey(expectedBossThreadsGaugeName);
assertThat(registeredGauges.get(expectedBossThreadsGaugeName).getValue()).isEqualTo(serverConfig.numBossThreads());
assertThat(registeredGauges).containsKey(expectedWorkerThreadsGaugeName);
assertThat(registeredGauges.get(expectedWorkerThreadsGaugeName).getValue()).isEqualTo(serverConfig.numWorkerThreads());
assertThat(registeredGauges).containsKey(expectedMaxRequestSizeInBytesGaugeName);
assertThat(registeredGauges.get(expectedMaxRequestSizeInBytesGaugeName).getValue()).isEqualTo(serverConfig.maxRequestSizeInBytes());
assertThat(registeredGauges).containsKey(expectedEndpointsListGaugeName);
assertThat(registeredGauges.get(expectedEndpointsListGaugeName).getValue()).isEqualTo(expectedEndpointsListValue);
} else {
// No server config values should have been registered.
verifyNoMoreInteractions(metricRegistryMock);
}
// In either case, the EndpointMetricsHandler should have been called to delegate setting up endpoint-specific metrics.
verify(endpointMetricsHandlerMock).setupEndpointsMetrics(serverConfig, metricRegistryMock);
}
use of com.nike.riposte.server.config.ServerConfig in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method beforeMethod.
@Before
public void beforeMethod() {
setupMetricRegistryAndCodahaleMetricsCollector();
endpointMetricsHandlerMock = mock(EndpointMetricsHandler.class);
mockHistogramSupplier = () -> mock(Histogram.class);
listener = new CodahaleMetricsListener(cmcMock, endpointMetricsHandlerMock, true, null, null, mockHistogramSupplier);
serverConfig = new ServerConfig() {
private final List<Endpoint<?>> endpoints = Arrays.asList(new DummyEndpoint(Matcher.match("/foo")), new DummyEndpoint(Matcher.match("/bar", HttpMethod.POST, HttpMethod.PUT)), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiFoo", "/multiBar"))), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiBaz", "/multiBat"), HttpMethod.PATCH, HttpMethod.OPTIONS)));
@Override
public Collection<Endpoint<?>> appEndpoints() {
return endpoints;
}
@Override
public int numBossThreads() {
return 3;
}
@Override
public int numWorkerThreads() {
return 42;
}
@Override
public int maxRequestSizeInBytes() {
return 42434445;
}
};
listener.initEndpointAndServerConfigMetrics(serverConfig);
requestInfoMock = mock(RequestInfo.class);
responseInfoMock = mock(ResponseInfo.class);
state = new HttpProcessingState();
state.setRequestInfo(requestInfoMock);
state.setResponseInfo(responseInfoMock);
requestStartTime = Instant.now().minus(42, ChronoUnit.MILLIS);
state.setRequestStartTime(requestStartTime);
}
use of com.nike.riposte.server.config.ServerConfig in project riposte by Nike-Inc.
the class EndpointMetricsHandlerDefaultImplTest method beforeMethod.
@Before
public void beforeMethod() {
instance = spy(new EndpointMetricsHandlerDefaultImpl());
serverConfig = new ServerConfig() {
private final List<Endpoint<?>> endpoints = Arrays.asList(new DummyEndpoint(Matcher.match("/foo")), new DummyEndpoint(Matcher.match("/bar", HttpMethod.POST, HttpMethod.PUT)), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiFoo", "/multiBar"))), new DummyEndpoint(Matcher.multiMatch(Arrays.asList("/multiBaz", "/multiBat"), HttpMethod.PATCH, HttpMethod.OPTIONS)));
@Override
public Collection<Endpoint<?>> appEndpoints() {
return endpoints;
}
@Override
public int numBossThreads() {
return 3;
}
@Override
public int numWorkerThreads() {
return 42;
}
@Override
public int maxRequestSizeInBytes() {
return 42434445;
}
};
setupMetricRegistryMock();
requestInfoMock = mock(RequestInfo.class);
responseInfoMock = mock(ResponseInfo.class);
state = new HttpProcessingState();
state.setRequestInfo(requestInfoMock);
state.setResponseInfo(responseInfoMock);
state.setRequestStartTime(Instant.now());
instance.setupEndpointsMetrics(serverConfig, metricRegistryMock);
}
use of com.nike.riposte.server.config.ServerConfig in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method setupEndpointsMetrics_does_nothing.
@Test
public void setupEndpointsMetrics_does_nothing() {
// given
ServerConfig serverConfigMock = mock(ServerConfig.class);
// when
handler.setupEndpointsMetrics(serverConfigMock, metricRegistryMock);
// then
verifyZeroInteractions(serverConfigMock, metricMetadataMock, metricRegistryMock, requestTimerBuilderMock, dimensionConfiguratorMock);
}
Aggregations