Search in sources :

Example 51 with Histogram

use of com.codahale.metrics.Histogram in project wikidata-query-rdf by wikimedia.

the class DropwizardToFlinkListenerUnitTest method shouldRegisterHistograms.

@Test
public void shouldRegisterHistograms() {
    String histogramName = "histogram";
    Histogram histogram = metricRegistry.histogram(histogramName);
    int updateValue = 10;
    histogram.update(updateValue);
    histogram.update(2 * updateValue);
    verify(metricGroupMock).histogram(eq(histogramName), histogramArgumentCaptor.capture());
    org.apache.flink.metrics.Histogram flinkHistogram = histogramArgumentCaptor.getValue();
    assertThat(flinkHistogram.getCount()).isEqualTo(2);
    assertThat(flinkHistogram.getStatistics().getValues()).containsExactly(updateValue, 2 * updateValue);
}
Also used : Histogram(com.codahale.metrics.Histogram) Test(org.junit.Test)

Example 52 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method setupMetricRegistryAndCodahaleMetricsCollector.

private void setupMetricRegistryAndCodahaleMetricsCollector() {
    metricRegistryMock = mock(MetricRegistry.class);
    cmcMock = mock(CodahaleMetricsCollector.class);
    doReturn(metricRegistryMock).when(cmcMock).getMetricRegistry();
    registeredTimerMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgument(0);
        Timer timerMock = mock(Timer.class);
        registeredTimerMocks.put(name, timerMock);
        return timerMock;
    }).when(metricRegistryMock).timer(anyString());
    registeredMeterMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgument(0);
        Meter meterMock = mock(Meter.class);
        registeredMeterMocks.put(name, meterMock);
        return meterMock;
    }).when(metricRegistryMock).meter(anyString());
    registeredCounterMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgument(0);
        Counter counterMock = mock(Counter.class);
        registeredCounterMocks.put(name, counterMock);
        return counterMock;
    }).when(metricRegistryMock).counter(anyString());
    registeredHistogramMocks = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgument(0);
        Histogram histogramMock = mock(Histogram.class);
        registeredHistogramMocks.put(name, histogramMock);
        return histogramMock;
    }).when(metricRegistryMock).histogram(anyString());
    registeredGauges = new HashMap<>();
    doAnswer(invocation -> {
        String name = invocation.getArgument(0);
        Metric metric = invocation.getArgument(1);
        if (metric instanceof Gauge)
            registeredGauges.put(name, (Gauge) metric);
        else if (metric instanceof Histogram)
            registeredHistogramMocks.put(name, (Histogram) metric);
        else
            throw new RuntimeException("Expected Gauge or Histogram, but received: " + metric.getClass().getName());
        return metric;
    }).when(metricRegistryMock).register(anyString(), any(Metric.class));
    doAnswer(invocation -> {
        String name = invocation.getArgument(0);
        Metric metric = invocation.getArgument(1);
        metricRegistryMock.register(name, metric);
        return metric;
    }).when(cmcMock).registerNamedMetric(anyString(), any(Metric.class));
    doAnswer(invocation -> metricRegistryMock.counter(invocation.getArgument(0))).when(cmcMock).getNamedCounter(anyString());
    doAnswer(invocation -> metricRegistryMock.meter(invocation.getArgument(0))).when(cmcMock).getNamedMeter(anyString());
    doAnswer(invocation -> metricRegistryMock.histogram(invocation.getArgument(0))).when(cmcMock).getNamedHistogram(anyString());
    doAnswer(invocation -> metricRegistryMock.timer(invocation.getArgument(0))).when(cmcMock).getNamedTimer(anyString());
}
Also used : Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Gauge(com.codahale.metrics.Gauge)

Example 53 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowArrayReservoir_with_expected_values.

@DataProvider(value = { "42     |   DAYS", "123    |   SECONDS", "999    |   MILLISECONDS", "3      |   HOURS" }, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowArrayReservoir_with_expected_values(long amount, TimeUnit timeUnit) {
    // given
    RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
    // when
    Timer timer = rwtb.newMetric();
    // then
    Histogram histogram = (Histogram) getInternalState(timer, "histogram");
    Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
    assertThat(reservoir).isInstanceOf(SlidingTimeWindowArrayReservoir.class);
    // The expected value here comes from logic in the SlidingTimeWindowArrayReservoir constructor.
    assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) Reservoir(com.codahale.metrics.Reservoir) SlidingTimeWindowArrayReservoir(com.codahale.metrics.SlidingTimeWindowArrayReservoir) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 54 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method builder_works_as_expected_for_specified_fields.

@DataProvider(value = { "true   |   true", "true   |   false", "false  |   true", "false  |   false" }, splitBy = "\\|")
@Test
public void builder_works_as_expected_for_specified_fields(boolean overrideCodahaleMetricsCollector, boolean includeServerConfigMetrics) {
    // given
    setupMetricRegistryAndCodahaleMetricsCollector();
    CodahaleMetricsCollector alternateCmcMock = mock(CodahaleMetricsCollector.class);
    doReturn(metricRegistryMock).when(alternateCmcMock).getMetricRegistry();
    MetricNamingStrategy<ServerStatisticsMetricNames> statsNamingStrat = new DefaultMetricNamingStrategy<>();
    MetricNamingStrategy<ServerConfigMetricNames> configNamingStrat = new DefaultMetricNamingStrategy<>();
    Supplier<Histogram> histogramSupplier = () -> mock(Histogram.class);
    Builder builder = CodahaleMetricsListener.newBuilder(cmcMock);
    if (overrideCodahaleMetricsCollector)
        builder = builder.withMetricsCollector(alternateCmcMock);
    builder = builder.withEndpointMetricsHandler(endpointMetricsHandlerMock).withIncludeServerConfigMetrics(includeServerConfigMetrics).withServerConfigMetricNamingStrategy(configNamingStrat).withServerStatsMetricNamingStrategy(statsNamingStrat).withRequestAndResponseSizeHistogramSupplier(histogramSupplier);
    // when
    CodahaleMetricsListener result = builder.build();
    // then
    if (overrideCodahaleMetricsCollector)
        assertThat(result.metricsCollector).isSameAs(alternateCmcMock);
    else
        assertThat(result.metricsCollector).isSameAs(cmcMock);
    assertThat(result.endpointMetricsHandler).isSameAs(endpointMetricsHandlerMock);
    assertThat(result.includeServerConfigMetrics).isEqualTo(includeServerConfigMetrics);
    assertThat(result.serverConfigMetricNamingStrategy).isSameAs(configNamingStrat);
    assertThat(result.serverStatsMetricNamingStrategy).isSameAs(statsNamingStrat);
    assertThat(result.requestAndResponseSizeHistogramSupplier).isSameAs(histogramSupplier);
}
Also used : Histogram(com.codahale.metrics.Histogram) DefaultMetricNamingStrategy(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.DefaultMetricNamingStrategy) ServerConfigMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerConfigMetricNames) ServerStatisticsMetricNames(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.ServerStatisticsMetricNames) Builder(com.nike.riposte.metrics.codahale.CodahaleMetricsListener.Builder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 55 with Histogram

use of com.codahale.metrics.Histogram in project riposte by Nike-Inc.

the class SignalFxAwareCodahaleMetricsCollectorTest method getNamedHistogram_creates_histogram_using_sfx_mechanisms.

@Test
public void getNamedHistogram_creates_histogram_using_sfx_mechanisms() {
    // given
    String histogramName = UUID.randomUUID().toString();
    // when
    Histogram result = sfxImpl.getNamedHistogram(histogramName);
    // then
    verifyMetricCreation(histogramBuilderMock, histogramTaggerMock, histogramName, histogramMock, result);
}
Also used : Histogram(com.codahale.metrics.Histogram) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5