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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations