Search in sources :

Example 11 with TestHistogram

use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.

the class DatadogHttpClientTest method serializeHistogram.

@Test
public void serializeHistogram() throws JsonProcessingException {
    DHistogram h = new DHistogram(new TestHistogram(), METRIC, HOST, tags, () -> MOCKED_SYSTEM_MILLIS);
    DSeries series = new DSeries();
    h.addTo(series);
    assertSerialization(DatadogHttpClient.serialize(series), new MetricAssertion(MetricType.gauge, true, "4.0", DHistogram.SUFFIX_AVG), new MetricAssertion(MetricType.gauge, true, "1", DHistogram.SUFFIX_COUNT), new MetricAssertion(MetricType.gauge, true, "0.5", DHistogram.SUFFIX_MEDIAN), new MetricAssertion(MetricType.gauge, true, "0.95", DHistogram.SUFFIX_95_PERCENTILE), new MetricAssertion(MetricType.gauge, true, "7", DHistogram.SUFFIX_MIN), new MetricAssertion(MetricType.gauge, true, "6", DHistogram.SUFFIX_MAX));
}
Also used : TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.Test)

Example 12 with TestHistogram

use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.

the class MetricQueryServiceTest method testCreateDump.

@Test
public void testCreateDump() throws Exception {
    MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
    queryService.start();
    final Counter c = new SimpleCounter();
    final Gauge<String> g = () -> "Hello";
    final Histogram h = new TestHistogram();
    final Meter m = new TestMeter();
    final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();
    queryService.addMetric("counter", c, tm);
    queryService.addMetric("gauge", g, tm);
    queryService.addMetric("histogram", h, tm);
    queryService.addMetric("meter", m, tm);
    MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();
    assertTrue(dump.serializedCounters.length > 0);
    assertTrue(dump.serializedGauges.length > 0);
    assertTrue(dump.serializedHistograms.length > 0);
    assertTrue(dump.serializedMeters.length > 0);
    queryService.removeMetric(c);
    queryService.removeMetric(g);
    queryService.removeMetric(h);
    queryService.removeMetric(m);
    MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();
    assertEquals(0, emptyDump.serializedCounters.length);
    assertEquals(0, emptyDump.serializedGauges.length);
    assertEquals(0, emptyDump.serializedHistograms.length);
    assertEquals(0, emptyDump.serializedMeters.length);
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestMeter(org.apache.flink.metrics.util.TestMeter) Meter(org.apache.flink.metrics.Meter) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.Test)

Example 13 with TestHistogram

use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.

the class MetricFetcherTest method createRequestDumpAnswer.

private static MetricDumpSerialization.MetricSerializationResult createRequestDumpAnswer(ResourceID tmRID, JobID jobID) {
    Map<Counter, Tuple2<QueryScopeInfo, String>> counters = new HashMap<>();
    Map<Gauge<?>, Tuple2<QueryScopeInfo, String>> gauges = new HashMap<>();
    Map<Histogram, Tuple2<QueryScopeInfo, String>> histograms = new HashMap<>();
    Map<Meter, Tuple2<QueryScopeInfo, String>> meters = new HashMap<>();
    SimpleCounter c1 = new SimpleCounter();
    SimpleCounter c2 = new SimpleCounter();
    c1.inc(1);
    c2.inc(2);
    counters.put(c1, new Tuple2<>(new QueryScopeInfo.OperatorQueryScopeInfo(jobID.toString(), "taskid", 2, "opname", "abc"), "oc"));
    counters.put(c2, new Tuple2<>(new QueryScopeInfo.TaskQueryScopeInfo(jobID.toString(), "taskid", 2, "abc"), "tc"));
    meters.put(new Meter() {

        @Override
        public void markEvent() {
        }

        @Override
        public void markEvent(long n) {
        }

        @Override
        public double getRate() {
            return 5;
        }

        @Override
        public long getCount() {
            return 10;
        }
    }, new Tuple2<>(new QueryScopeInfo.JobQueryScopeInfo(jobID.toString(), "abc"), "jc"));
    gauges.put(new Gauge<String>() {

        @Override
        public String getValue() {
            return "x";
        }
    }, new Tuple2<>(new QueryScopeInfo.TaskManagerQueryScopeInfo(tmRID.toString(), "abc"), "gauge"));
    histograms.put(new TestHistogram(), new Tuple2<>(new QueryScopeInfo.JobManagerQueryScopeInfo("abc"), "hist"));
    MetricDumpSerialization.MetricDumpSerializer serializer = new MetricDumpSerialization.MetricDumpSerializer();
    MetricDumpSerialization.MetricSerializationResult dump = serializer.serialize(counters, gauges, histograms, meters);
    serializer.close();
    return dump;
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) HashMap(java.util.HashMap) Meter(org.apache.flink.metrics.Meter) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) Tuple2(org.apache.flink.api.java.tuple.Tuple2)

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