Search in sources :

Example 1 with TestingMetricRegistry

use of org.apache.flink.runtime.metrics.util.TestingMetricRegistry in project flink by apache.

the class LatencyStatsTest method testLatencyStats.

private static void testLatencyStats(final LatencyStats.Granularity granularity, final Consumer<List<Tuple2<String, Histogram>>> verifier) {
    final AbstractMetricGroup<?> dummyGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup();
    final List<Tuple2<String, Histogram>> latencyHistograms = new ArrayList<>(4);
    final TestingMetricRegistry registry = TestingMetricRegistry.builder().setRegisterConsumer((metric, metricName, group) -> {
        if (metric instanceof Histogram) {
            latencyHistograms.add(Tuple2.of(group.getMetricIdentifier(metricName), (Histogram) metric));
        }
    }).build();
    final MetricGroup parentGroup = new GenericMetricGroup(registry, dummyGroup, PARENT_GROUP_NAME);
    final LatencyStats latencyStats = new LatencyStats(parentGroup, MetricOptions.LATENCY_HISTORY_SIZE.defaultValue(), OPERATOR_SUBTASK_INDEX, OPERATOR_ID, granularity);
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 1));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 2));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 3));
    verifier.accept(latencyHistograms);
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test) MetricOptions(org.apache.flink.configuration.MetricOptions) Histogram(org.apache.flink.metrics.Histogram) ArrayList(java.util.ArrayList) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) Consumer(java.util.function.Consumer) MetricGroup(org.apache.flink.metrics.MetricGroup) List(java.util.List) UnregisteredMetricGroups(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) TestLogger(org.apache.flink.util.TestLogger) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) Assert(org.junit.Assert) Histogram(org.apache.flink.metrics.Histogram) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) ArrayList(java.util.ArrayList) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 MetricOptions (org.apache.flink.configuration.MetricOptions)1 Histogram (org.apache.flink.metrics.Histogram)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1 AbstractMetricGroup (org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)1 GenericMetricGroup (org.apache.flink.runtime.metrics.groups.GenericMetricGroup)1 UnregisteredMetricGroups (org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups)1 TestingMetricRegistry (org.apache.flink.runtime.metrics.util.TestingMetricRegistry)1 LatencyMarker (org.apache.flink.streaming.runtime.streamrecord.LatencyMarker)1 TestLogger (org.apache.flink.util.TestLogger)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1