use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class MetricQueryServiceTest method testHandleOversizedMetricMessage.
@Test
public void testHandleOversizedMetricMessage() throws Exception {
final long sizeLimit = 200L;
MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), sizeLimit);
queryService.start();
final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();
final String gaugeValue = "Hello";
final long requiredGaugesToExceedLimit = sizeLimit / gaugeValue.length() + 1;
List<Tuple2<String, Gauge<String>>> gauges = LongStream.range(0, requiredGaugesToExceedLimit).mapToObj(x -> Tuple2.of("gauge" + x, (Gauge<String>) () -> "Hello" + x)).collect(Collectors.toList());
gauges.forEach(gauge -> queryService.addMetric(gauge.f0, gauge.f1, tm));
queryService.addMetric("counter", new SimpleCounter(), tm);
queryService.addMetric("histogram", new TestHistogram(), tm);
queryService.addMetric("meter", new TestMeter(), tm);
MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();
assertTrue(dump.serializedCounters.length > 0);
assertEquals(1, dump.numCounters);
assertTrue(dump.serializedMeters.length > 0);
assertEquals(1, dump.numMeters);
// gauges exceeded the size limit and will be excluded
assertEquals(0, dump.serializedGauges.length);
assertEquals(0, dump.numGauges);
assertTrue(dump.serializedHistograms.length > 0);
assertEquals(1, dump.numHistograms);
// unregister all but one gauge to ensure gauges are reported again if the remaining fit
for (int x = 1; x < gauges.size(); x++) {
queryService.removeMetric(gauges.get(x).f1);
}
MetricDumpSerialization.MetricSerializationResult recoveredDump = queryService.queryMetrics(TIMEOUT).get();
assertTrue(recoveredDump.serializedCounters.length > 0);
assertEquals(1, recoveredDump.numCounters);
assertTrue(recoveredDump.serializedMeters.length > 0);
assertEquals(1, recoveredDump.numMeters);
assertTrue(recoveredDump.serializedGauges.length > 0);
assertEquals(1, recoveredDump.numGauges);
assertTrue(recoveredDump.serializedHistograms.length > 0);
assertEquals(1, recoveredDump.numHistograms);
}
use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class PrometheusReporterTaskScopeTest method histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels.
@Test
void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
Histogram histogram = new TestHistogram();
taskMetricGroup1.histogram("my_histogram", histogram);
taskMetricGroup2.histogram("my_histogram", histogram);
final String exportedMetrics = pollMetrics(reporter.getPort()).getBody();
assertThat(exportedMetrics).contains(// histogram
"subtask_index=\"0\",quantile=\"0.5\",} 0.5");
assertThat(exportedMetrics).contains(// histogram
"subtask_index=\"1\",quantile=\"0.5\",} 0.5");
final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile");
for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) {
assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile))).isEqualTo(quantile);
assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile))).isEqualTo(quantile);
}
}
use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class Slf4jReporterTest method testAddHistogram.
@Test
void testAddHistogram() throws Exception {
String histogramName = "histogram";
Histogram histogram = new TestHistogram();
reporter.notifyOfAddedMetric(histogram, histogramName, metricGroup);
assertThat(reporter.getHistograms()).containsKey(histogram);
String expectedHistogramName = reporter.filterCharacters(SCOPE) + delimiter + reporter.filterCharacters(histogramName);
reporter.report();
assertThat(testLoggerResource.getMessages()).anyMatch(logOutput -> logOutput.contains(expectedHistogramName));
}
use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class JMXReporterTest method testHistogramReporting.
/**
* Tests that histograms are properly reported via the JMXReporter.
*/
@Test
void testHistogramReporting() throws Exception {
String histogramName = "histogram";
final JMXReporter reporter = new JMXReporter(null);
TestHistogram histogram = new TestHistogram();
reporter.notifyOfAddedMetric(histogram, histogramName, metricGroup);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
MBeanAttributeInfo[] attributeInfos = info.getAttributes();
assertThat(attributeInfos).hasSize(11);
assertThat(mBeanServer.getAttribute(objectName, "Count")).isEqualTo(histogram.getCount());
HistogramStatistics statistics = histogram.getStatistics();
assertThat(mBeanServer.getAttribute(objectName, "Mean")).isEqualTo(statistics.getMean());
assertThat(mBeanServer.getAttribute(objectName, "StdDev")).isEqualTo(statistics.getStdDev());
assertThat(mBeanServer.getAttribute(objectName, "Max")).isEqualTo(statistics.getMax());
assertThat(mBeanServer.getAttribute(objectName, "Min")).isEqualTo(statistics.getMin());
assertThat(mBeanServer.getAttribute(objectName, "Median")).isEqualTo(statistics.getQuantile(0.5));
assertThat(mBeanServer.getAttribute(objectName, "75thPercentile")).isEqualTo(statistics.getQuantile(0.75));
assertThat(mBeanServer.getAttribute(objectName, "95thPercentile")).isEqualTo(statistics.getQuantile(0.95));
assertThat(mBeanServer.getAttribute(objectName, "98thPercentile")).isEqualTo(statistics.getQuantile(0.98));
assertThat(mBeanServer.getAttribute(objectName, "99thPercentile")).isEqualTo(statistics.getQuantile(0.99));
assertThat(mBeanServer.getAttribute(objectName, "999thPercentile")).isEqualTo(statistics.getQuantile(0.999));
}
use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class PrometheusReporterTest method histogramIsReportedAsPrometheusSummary.
@Test
void histogramIsReportedAsPrometheusSummary() throws UnirestException {
Histogram testHistogram = new TestHistogram();
String histogramName = "testHistogram";
String summaryName = SCOPE_PREFIX + histogramName;
String response = addMetricAndPollResponse(testHistogram, histogramName);
assertThat(response).contains(HELP_PREFIX + summaryName + " " + histogramName + " (scope: taskmanager)\n" + TYPE_PREFIX + summaryName + " summary" + "\n" + summaryName + "_count" + DEFAULT_LABELS + " 1.0" + "\n");
for (String quantile : Arrays.asList("0.5", "0.75", "0.95", "0.98", "0.99", "0.999")) {
assertThat(response).contains(summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n");
}
}
Aggregations