Search in sources :

Example 81 with Histogram

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

the class EndpointMetricsHandlerDefaultImplTest method setupMetricRegistryMock.

private void setupMetricRegistryMock() {
    metricRegistryMock = mock(MetricRegistry.class);
    registeredTimers = new HashMap<>();
    doAnswer(invocation -> {
        Timer originalTimer = (Timer) invocation.callRealMethod();
        return spy(originalTimer);
    }).when(instance).createAndRegisterRequestTimer(anyString(), any(MetricRegistry.class));
    doThrow(new RuntimeException("All timer creation should go through createAndRegisterRequestTimer(), *not* metricRegistry.timer(...).")).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 Timer)
            registeredTimers.put(name, (Timer) metric);
        else
            throw new RuntimeException("Expected Gauge or Timer, but received: " + metric.getClass().getName());
        return metric;
    }).when(metricRegistryMock).register(anyString(), any(Metric.class));
}
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 82 with Histogram

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

the class CodahaleMetricsListenerTest method constructor_uses_histogram_supplier_for_request_size_and_response_size_metrics.

@Test
public void constructor_uses_histogram_supplier_for_request_size_and_response_size_metrics() {
    // given
    Histogram mockHistogram = mock(Histogram.class);
    Supplier<Histogram> histogramSupplier = () -> mockHistogram;
    // when
    CodahaleMetricsListener instance = new CodahaleMetricsListener(cmcMock, endpointMetricsHandlerMock, false, null, null, histogramSupplier);
    // then
    assertThat(instance.requestSizes).isSameAs(mockHistogram);
    assertThat(instance.responseSizes).isSameAs(mockHistogram);
}
Also used : Histogram(com.codahale.metrics.Histogram) Test(org.junit.Test)

Example 83 with Histogram

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

the class SignalFxAwareCodahaleMetricsCollectorTest method getNamedHistogram_with_varargs_dimensions_creates_dimensioned_histogram_using_sfx_mechanisms.

@DataProvider(value = { "null", "0", "1", "2" }, splitBy = "\\|")
@Test
public void getNamedHistogram_with_varargs_dimensions_creates_dimensioned_histogram_using_sfx_mechanisms(Integer numDimensions) {
    // given
    String histogramName = UUID.randomUUID().toString();
    Pair<String, String>[] varargDims = generateVarargDimensions(numDimensions);
    List<Pair<String, String>> dimsAsList = (varargDims == null) ? null : Arrays.asList(varargDims);
    // when
    Histogram result = sfxImpl.getNamedHistogram(histogramName, varargDims);
    // then
    verifyMetricCreation(histogramBuilderMock, histogramTaggerMock, histogramName, dimsAsList, histogramMock, result);
}
Also used : Histogram(com.codahale.metrics.Histogram) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Pair(com.nike.internal.util.Pair) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 84 with Histogram

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

the class SignalFxAwareCodahaleMetricsCollectorTest method getNamedHistogram_with_iterable_dimensions_creates_dimensioned_histogram_using_sfx_mechanisms.

@DataProvider(value = { "null", "0", "1", "2" }, splitBy = "\\|")
@Test
public void getNamedHistogram_with_iterable_dimensions_creates_dimensioned_histogram_using_sfx_mechanisms(Integer numDimensions) {
    // given
    String histogramName = UUID.randomUUID().toString();
    List<Pair<String, String>> iterableDims = generateIterableDimensions(numDimensions);
    // when
    Histogram result = sfxImpl.getNamedHistogram(histogramName, iterableDims);
    // then
    verifyMetricCreation(histogramBuilderMock, histogramTaggerMock, histogramName, iterableDims, histogramMock, result);
}
Also used : Histogram(com.codahale.metrics.Histogram) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Pair(com.nike.internal.util.Pair) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 85 with Histogram

use of com.codahale.metrics.Histogram in project engineblock by engineblock.

the class ExceptionHistoMetrics method update.

public void update(Throwable e, long magnitude) {
    Histogram h = counters.get(e.getClass());
    if (h == null) {
        synchronized (counters) {
            h = counters.computeIfAbsent(e.getClass(), k -> ActivityMetrics.histogram(activityDef, "errorhistos." + e.getClass().getSimpleName()));
        }
    }
    h.update(magnitude);
}
Also used : Histogram(com.codahale.metrics.Histogram) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ActivityDef(io.engineblock.activityimpl.ActivityDef) Histogram(com.codahale.metrics.Histogram)

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