Search in sources :

Example 6 with TestHistogram

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);
}
Also used : AfterClass(org.junit.AfterClass) LongStream(java.util.stream.LongStream) BeforeClass(org.junit.BeforeClass) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestMeter(org.apache.flink.metrics.util.TestMeter) Collectors(java.util.stream.Collectors) Histogram(org.apache.flink.metrics.Histogram) Meter(org.apache.flink.metrics.Meter) List(java.util.List) UnregisteredMetricGroups(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups) TestHistogram(org.apache.flink.metrics.util.TestHistogram) After(org.junit.After) Gauge(org.apache.flink.metrics.Gauge) TestLogger(org.apache.flink.util.TestLogger) SimpleCounter(org.apache.flink.metrics.SimpleCounter) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) Time(org.apache.flink.api.common.time.Time) Counter(org.apache.flink.metrics.Counter) Assert.assertEquals(org.junit.Assert.assertEquals) TestMeter(org.apache.flink.metrics.util.TestMeter) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TestHistogram(org.apache.flink.metrics.util.TestHistogram) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Example 7 with TestHistogram

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);
    }
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.jupiter.api.Test)

Example 8 with TestHistogram

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));
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.jupiter.api.Test)

Example 9 with TestHistogram

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));
}
Also used : MBeanInfo(javax.management.MBeanInfo) HistogramStatistics(org.apache.flink.metrics.HistogramStatistics) TestHistogram(org.apache.flink.metrics.util.TestHistogram) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.jupiter.api.Test)

Example 10 with TestHistogram

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");
    }
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.jupiter.api.Test)

Aggregations

TestHistogram (org.apache.flink.metrics.util.TestHistogram)13 Histogram (org.apache.flink.metrics.Histogram)9 Test (org.junit.jupiter.api.Test)8 Counter (org.apache.flink.metrics.Counter)5 Meter (org.apache.flink.metrics.Meter)5 SimpleCounter (org.apache.flink.metrics.SimpleCounter)5 Test (org.junit.Test)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 Gauge (org.apache.flink.metrics.Gauge)3 TestMeter (org.apache.flink.metrics.util.TestMeter)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 LongStream (java.util.stream.LongStream)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1