Search in sources :

Example 1 with ChainedMetricDimensionConfigurator

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method ChainedMetricDimensionConfigurator_constructor_sets_fields_as_expected.

@Test
public void ChainedMetricDimensionConfigurator_constructor_sets_fields_as_expected() {
    // given
    MetricDimensionConfigurator first = mock(MetricDimensionConfigurator.class);
    MetricDimensionConfigurator second = mock(MetricDimensionConfigurator.class);
    // when
    ChainedMetricDimensionConfigurator instance = new ChainedMetricDimensionConfigurator(first, second);
    // then
    assertThat(instance.firstConfigurator).isSameAs(first);
    assertThat(instance.secondConfigurator).isSameAs(second);
}
Also used : MetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator) DefaultMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) Test(org.junit.Test)

Example 2 with ChainedMetricDimensionConfigurator

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method MetricDimensionConfigurator_chainedWith_returns_ChainedMetricDimensionConfigurator_with_correct_args.

@Test
public void MetricDimensionConfigurator_chainedWith_returns_ChainedMetricDimensionConfigurator_with_correct_args() {
    // given
    MetricDimensionConfigurator orig = (rawBuilder, requestInfo, responseInfo, httpState, responseHttpStatusCode, responseHttpStatusCodeXXValue, elapsedTimeMillis, endpoint, endpointClass, method, matchingPathTemplate) -> null;
    MetricDimensionConfigurator chainMe = mock(MetricDimensionConfigurator.class);
    // when
    MetricDimensionConfigurator result = orig.chainedWith(chainMe);
    // then
    assertThat(result).isInstanceOf(ChainedMetricDimensionConfigurator.class);
    ChainedMetricDimensionConfigurator cmdc = (ChainedMetricDimensionConfigurator) result;
    assertThat(cmdc.firstConfigurator).isSameAs(orig);
    assertThat(cmdc.secondConfigurator).isSameAs(chainMe);
}
Also used : MetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator) MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ResponseInfo(com.nike.riposte.server.http.ResponseInfo) ServerConfig(com.nike.riposte.server.config.ServerConfig) Reservoir(com.codahale.metrics.Reservoir) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DEFAULT_URI_DIMENSION_KEY(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator.DEFAULT_URI_DIMENSION_KEY) SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.eq(org.mockito.Matchers.eq) Matchers.anyInt(org.mockito.Matchers.anyInt) Mockito.doReturn(org.mockito.Mockito.doReturn) Metric(com.codahale.metrics.Metric) UUID(java.util.UUID) Instant(java.time.Instant) DefaultMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator) Matchers.any(org.mockito.Matchers.any) SignalFxReporterFactory(com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) Endpoint(com.nike.riposte.server.http.Endpoint) Timer(com.codahale.metrics.Timer) Gauge(com.codahale.metrics.Gauge) Whitebox.getInternalState(org.mockito.internal.util.reflection.Whitebox.getInternalState) BuilderTagger(com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Mockito.mock(org.mockito.Mockito.mock) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Histogram(com.codahale.metrics.Histogram) RequestInfo(com.nike.riposte.server.http.RequestInfo) MetricBuilder(com.signalfx.codahale.metrics.MetricBuilder) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Matchers.anyString(org.mockito.Matchers.anyString) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) DEFAULT_METHOD_DIMENSION_KEY(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator.DEFAULT_METHOD_DIMENSION_KEY) Matchers.anyLong(org.mockito.Matchers.anyLong) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR) Before(org.junit.Before) DEFAULT_ENDPOINT_CLASS_DIMENSION_KEY(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator.DEFAULT_ENDPOINT_CLASS_DIMENSION_KEY) DEFAULT_RESPONSE_CODE_DIMENSION_KEY(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator.DEFAULT_RESPONSE_CODE_DIMENSION_KEY) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) ChronoUnit(java.time.temporal.ChronoUnit) Pair(com.nike.internal.util.Pair) MetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator) DefaultMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) Test(org.junit.Test)

Example 3 with ChainedMetricDimensionConfigurator

use of com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method ChainedMetricDimensionConfigurator_setupMetricWithDimensions_chains_calls_as_expected.

@Test
public void ChainedMetricDimensionConfigurator_setupMetricWithDimensions_chains_calls_as_expected() {
    // given
    MetricDimensionConfigurator first = mock(MetricDimensionConfigurator.class);
    MetricDimensionConfigurator second = mock(MetricDimensionConfigurator.class);
    ChainedMetricDimensionConfigurator instance = new ChainedMetricDimensionConfigurator(first, second);
    int responseStatusCode = 242;
    int responseStatusCodeXXValue = 2;
    long elapsedTimeMillis = 42;
    String endpointClass = UUID.randomUUID().toString();
    String method = UUID.randomUUID().toString();
    BuilderTagger origBuilderMock = mock(BuilderTagger.class);
    BuilderTagger firstResultBuilderMock = mock(BuilderTagger.class);
    BuilderTagger secondResultBuilderMock = mock(BuilderTagger.class);
    doReturn(firstResultBuilderMock).when(first).setupMetricWithDimensions(any(BuilderTagger.class), any(RequestInfo.class), any(ResponseInfo.class), any(HttpProcessingState.class), anyInt(), anyInt(), anyLong(), any(Endpoint.class), anyString(), anyString(), anyString());
    doReturn(secondResultBuilderMock).when(second).setupMetricWithDimensions(any(BuilderTagger.class), any(RequestInfo.class), any(ResponseInfo.class), any(HttpProcessingState.class), anyInt(), anyInt(), anyLong(), any(Endpoint.class), anyString(), anyString(), anyString());
    // when
    BuilderTagger finalResult = instance.setupMetricWithDimensions(origBuilderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    // then
    verify(first).setupMetricWithDimensions(origBuilderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    verify(second).setupMetricWithDimensions(firstResultBuilderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    assertThat(finalResult).isSameAs(secondResultBuilderMock);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) Endpoint(com.nike.riposte.server.http.Endpoint) MetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator) DefaultMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) Matchers.anyString(org.mockito.Matchers.anyString) RequestInfo(com.nike.riposte.server.http.RequestInfo) BuilderTagger(com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger) Endpoint(com.nike.riposte.server.http.Endpoint) Test(org.junit.Test)

Aggregations

ChainedMetricDimensionConfigurator (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator)3 DefaultMetricDimensionConfigurator (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator)3 MetricDimensionConfigurator (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator)3 Test (org.junit.Test)3 Endpoint (com.nike.riposte.server.http.Endpoint)2 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)2 RequestInfo (com.nike.riposte.server.http.RequestInfo)2 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)2 BuilderTagger (com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Gauge (com.codahale.metrics.Gauge)1 Histogram (com.codahale.metrics.Histogram)1 Metric (com.codahale.metrics.Metric)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Reservoir (com.codahale.metrics.Reservoir)1 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)1 Timer (com.codahale.metrics.Timer)1 Pair (com.nike.internal.util.Pair)1 SignalFxReporterFactory (com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory)1 DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR)1