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