@Override public long getCount() { return histogram.getCount(); }
@Override public long getCount() { return delegate.getCount(); }
@Override public long getCount() { return histogram.getCount(); }
@Test @InSequence(2) public void updateHistogramField() { assertThat("Histogram is not registered correctly", registry.getHistograms(), hasKey(HISTOGRAM_NAME)); Histogram histogram = registry.getHistograms().get(HISTOGRAM_NAME); // Call the update method and assert the histogram is up-to-date long value = Math.round(Math.random() * Long.MAX_VALUE); bean.update(value); assertThat("Histogram count is incorrect", histogram.getCount(), is(equalTo(1L))); assertThat("Histogram size is incorrect", histogram.getSnapshot().size(), is(equalTo(1))); assertThat("Histogram min value is incorrect", histogram.getSnapshot().getMin(), is(equalTo(value))); assertThat("Histogram max value is incorrect", histogram.getSnapshot().getMax(), is(equalTo(value))); } }
Snapshot snapshot = histogram.getSnapshot(); json.writeStartObject(); json.writeObjectField("count", histogram.getCount()); json.writeObjectField("min", snapshot.getMin()); json.writeObjectField("max", snapshot.getMax());
Snapshot snap = executionTimes.getSnapshot(); assertThat("histogram count", executionTimes.getCount(), is(2L)); // Rejected executions not recorded in histogram assertThat("median", snap.getMedian(), approxMillis(1000)); assertThat("mean", snap.getMean(), approxMillis(1000)); assertThat("histogram count", executionTimes.getCount(), is(12L)); assertThat("median", snap.getMedian(), approxMillis(0)); assertThat("75th percentile", snap.get75thPercentile(), approxMillis(0));
return new StringBuilder() .append(type(registryKey, keyBase + keyUnit + " summary", entry.metadata)) .append(value(registryKey, keyBase + keyUnit + "_count", histogram.getCount(), entry.metadata)) .append(toPrometheus(registryKey, keyBase, keyUnit, histogram.getSnapshot(), entry.metadata)); default:
@Test public void testTimeoutHistogram() { MetricGetter m = new MetricGetter(TimeoutMetricBean.class, "histogramTestWorkForMillis"); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(100); // 50th Percentile timeoutBean.histogramTestWorkForMillis(100); timeoutBean.histogramTestWorkForMillis(1000); timeoutBean.histogramTestWorkForMillis(1000); // 75th Percentile expectTimeout(() -> timeoutBean.histogramTestWorkForMillis(5000)); // Will timeout after 2000 expectTimeout(() -> timeoutBean.histogramTestWorkForMillis(5000)); // Will timeout after 2000 Histogram histogram = m.getTimeoutExecutionDuration().get(); Snapshot snapshot = histogram.getSnapshot(); assertThat("Histogram count", histogram.getCount(), is(10L)); assertThat("Median", snapshot.getMedian(), MetricComparator.approxMillis(100)); assertThat("75th percentile", snapshot.get75thPercentile(), MetricComparator.approxMillis(1000)); assertThat("99th percentile", snapshot.get99thPercentile(), MetricComparator.approxMillis(2000)); assertThat("99.9th percentile", snapshot.get999thPercentile(), MetricComparator.approxMillis(2000)); }