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);
}
Aggregations