Search in sources :

Example 1 with AbstractMetricGroup

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());
}
Also used : AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) Test(org.junit.Test)

Example 2 with AbstractMetricGroup

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

Example 3 with AbstractMetricGroup

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);
    }
}
Also used : Status(akka.actor.Status) Histogram(org.apache.flink.metrics.Histogram) Meter(org.apache.flink.metrics.Meter) IOException(java.io.IOException) IOException(java.io.IOException) Gauge(org.apache.flink.metrics.Gauge) Counter(org.apache.flink.metrics.Counter) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Metric(org.apache.flink.metrics.Metric) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)

Example 4 with AbstractMetricGroup

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());
}
Also used : KinesisProxyInterface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyInterface) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) Test(org.junit.Test)

Example 5 with AbstractMetricGroup

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;
}
Also used : TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) ProcessMetricGroup(org.apache.flink.runtime.metrics.groups.ProcessMetricGroup)

Aggregations

AbstractMetricGroup (org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)5 Test (org.junit.Test)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 Histogram (org.apache.flink.metrics.Histogram)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 Status (akka.actor.Status)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 MetricOptions (org.apache.flink.configuration.MetricOptions)1 Counter (org.apache.flink.metrics.Counter)1 Gauge (org.apache.flink.metrics.Gauge)1 Meter (org.apache.flink.metrics.Meter)1 Metric (org.apache.flink.metrics.Metric)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1 GenericMetricGroup (org.apache.flink.runtime.metrics.groups.GenericMetricGroup)1 ProcessMetricGroup (org.apache.flink.runtime.metrics.groups.ProcessMetricGroup)1 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)1 UnregisteredMetricGroups (org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups)1