use of org.apache.flink.runtime.metrics.groups.AbstractMetricGroup in project flink by apache.
the class ShardConsumerMetricsReporterTest method testUnregister.
@Test
public void testUnregister() {
AbstractMetricGroup metricGroup = ShardConsumerTestUtils.createFakeShardConsumerMetricGroup();
ShardConsumerMetricsReporter metricsReporter = new ShardConsumerMetricsReporter(metricGroup);
metricsReporter.unregister();
assertTrue(metricGroup.isClosed());
}
use of org.apache.flink.runtime.metrics.groups.AbstractMetricGroup 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);
}
use of org.apache.flink.runtime.metrics.groups.AbstractMetricGroup in project flink by apache.
the class MetricQueryService method onReceive.
@Override
public void onReceive(Object message) {
try {
if (message instanceof AddMetric) {
AddMetric added = (AddMetric) message;
String metricName = added.metricName;
Metric metric = added.metric;
AbstractMetricGroup group = added.group;
QueryScopeInfo info = group.getQueryServiceMetricInfo(FILTER);
if (metric instanceof Counter) {
counters.put((Counter) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
} else if (metric instanceof Gauge) {
gauges.put((Gauge<?>) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
} else if (metric instanceof Histogram) {
histograms.put((Histogram) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
} else if (metric instanceof Meter) {
meters.put((Meter) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
}
} else if (message instanceof RemoveMetric) {
Metric metric = (((RemoveMetric) message).metric);
if (metric instanceof Counter) {
this.counters.remove(metric);
} else if (metric instanceof Gauge) {
this.gauges.remove(metric);
} else if (metric instanceof Histogram) {
this.histograms.remove(metric);
} else if (metric instanceof Meter) {
this.meters.remove(metric);
}
} else if (message instanceof CreateDump) {
MetricDumpSerialization.MetricSerializationResult dump = serializer.serialize(counters, gauges, histograms, meters);
getSender().tell(dump, getSelf());
} else {
LOG.warn("MetricQueryServiceActor received an invalid message. " + message.toString());
getSender().tell(new Status.Failure(new IOException("MetricQueryServiceActor received an invalid message. " + message.toString())), getSelf());
}
} catch (Exception e) {
LOG.warn("An exception occurred while processing a message.", e);
}
}
use of org.apache.flink.runtime.metrics.groups.AbstractMetricGroup in project flink by apache.
the class ShardConsumerTest method testConsumerAndProducerMetricsAreUnregisteredAfterShardCompletes.
@Test
public void testConsumerAndProducerMetricsAreUnregisteredAfterShardCompletes() throws Exception {
KinesisProxyInterface kinesis = FakeKinesisBehavioursFactory.totalNumOfRecordsAfterNumOfGetRecordsCalls(500, 5, 500);
AbstractMetricGroup metricGroup = createFakeShardConsumerMetricGroup();
assertNumberOfMessagesReceivedFromKinesis(500, kinesis, fakeSequenceNumber(), metricGroup);
assertTrue(metricGroup.isClosed());
}
use of org.apache.flink.runtime.metrics.groups.AbstractMetricGroup in project flink by apache.
the class MetricUtils method createAndInitializeStatusMetricGroup.
private static MetricGroup createAndInitializeStatusMetricGroup(AbstractMetricGroup<?> parentMetricGroup) {
MetricGroup statusGroup = parentMetricGroup.addGroup(METRIC_GROUP_STATUS_NAME);
instantiateStatusMetrics(statusGroup);
return statusGroup;
}
Aggregations