Search in sources :

Example 6 with Metric

use of org.apache.flink.metrics.Metric in project flink by apache.

the class MultipleInputStreamTaskTest method testCheckpointBarrierMetrics.

/**
 * Tests the checkpoint related metrics are registered into {@link TaskIOMetricGroup} correctly
 * while generating the {@link TwoInputStreamTask}.
 */
@Test
public void testCheckpointBarrierMetrics() throws Exception {
    final Map<String, Metric> metrics = new ConcurrentHashMap<>();
    final TaskMetricGroup taskMetricGroup = StreamTaskTestHarness.createTaskMetricGroup(metrics);
    try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).addInput(BasicTypeInfo.STRING_TYPE_INFO, 2).addInput(BasicTypeInfo.INT_TYPE_INFO, 2).addInput(BasicTypeInfo.DOUBLE_TYPE_INFO, 2).setupOutputForSingletonOperatorChain(new MapToStringMultipleInputOperatorFactory(3)).setTaskMetricGroup(taskMetricGroup).build()) {
        assertThat(metrics, IsMapContaining.hasKey(MetricNames.CHECKPOINT_ALIGNMENT_TIME));
        assertThat(metrics, IsMapContaining.hasKey(MetricNames.CHECKPOINT_START_DELAY_TIME));
        testHarness.endInput();
        testHarness.waitForTaskCompletion();
    }
}
Also used : InterceptingTaskMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) Metric(org.apache.flink.metrics.Metric) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 7 with Metric

use of org.apache.flink.metrics.Metric in project flink by apache.

the class OneInputStreamTaskTest method testCheckpointBarrierMetrics.

/**
 * Tests the checkpoint related metrics are registered into {@link TaskIOMetricGroup} correctly
 * while generating the {@link OneInputStreamTask}.
 */
@Test
public void testCheckpointBarrierMetrics() throws Exception {
    final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
    testHarness.setupOutputForSingletonOperatorChain();
    StreamConfig streamConfig = testHarness.getStreamConfig();
    streamConfig.setStreamOperator(new TestOperator());
    final Map<String, Metric> metrics = new ConcurrentHashMap<>();
    final TaskMetricGroup taskMetricGroup = StreamTaskTestHarness.createTaskMetricGroup(metrics);
    final StreamMockEnvironment environment = testHarness.createEnvironment();
    environment.setTaskMetricGroup(taskMetricGroup);
    testHarness.invoke(environment);
    testHarness.waitForTaskRunning();
    assertThat(metrics, IsMapContaining.hasKey(MetricNames.CHECKPOINT_ALIGNMENT_TIME));
    assertThat(metrics, IsMapContaining.hasKey(MetricNames.CHECKPOINT_START_DELAY_TIME));
    testHarness.endInput();
    testHarness.waitForTaskCompletion();
}
Also used : TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) InterceptingTaskMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) Metric(org.apache.flink.metrics.Metric) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 8 with Metric

use of org.apache.flink.metrics.Metric in project flink by apache.

the class InMemoryReporter method notifyOfAddedMetric.

@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
    MetricGroup metricGroup = unwrap(group);
    LOG.debug("Registered {} @ {}", metricName, metricGroup);
    synchronized (this) {
        metrics.computeIfAbsent(metricGroup, dummy -> new HashMap<>()).put(metricName, metric);
    }
}
Also used : Arrays(java.util.Arrays) MetricConfig(org.apache.flink.metrics.MetricConfig) LogicalScopeProvider(org.apache.flink.metrics.LogicalScopeProvider) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) Metric(org.apache.flink.metrics.Metric) OperatorMetricGroup(org.apache.flink.metrics.groups.OperatorMetricGroup) ScopeFormat(org.apache.flink.runtime.metrics.scope.ScopeFormat) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) SimpleEntry(java.util.AbstractMap.SimpleEntry) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) MetricReporterFactory(org.apache.flink.metrics.reporter.MetricReporterFactory) Logger(org.slf4j.Logger) Properties(java.util.Properties) Configuration(org.apache.flink.configuration.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MetricGroup(org.apache.flink.metrics.MetricGroup) List(java.util.List) JobID(org.apache.flink.api.common.JobID) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Experimental(org.apache.flink.annotation.Experimental) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) Collections(java.util.Collections) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OperatorMetricGroup(org.apache.flink.metrics.groups.OperatorMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup)

Example 9 with Metric

use of org.apache.flink.metrics.Metric in project flink by apache.

the class TwoInputStreamTaskTest method testCheckpointBarrierMetrics.

/**
 * Tests the checkpoint related metrics are registered into {@link TaskIOMetricGroup} correctly
 * while generating the {@link TwoInputStreamTask}.
 */
@Test
public void testCheckpointBarrierMetrics() throws Exception {
    final TwoInputStreamTaskTestHarness<String, Integer, String> testHarness = new TwoInputStreamTaskTestHarness<>(TwoInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
    final StreamConfig streamConfig = testHarness.getStreamConfig();
    final CoStreamMap<String, Integer, String> coMapOperator = new CoStreamMap<>(new IdentityMap());
    testHarness.setupOutputForSingletonOperatorChain();
    streamConfig.setStreamOperator(coMapOperator);
    final Map<String, Metric> metrics = new ConcurrentHashMap<>();
    final TaskMetricGroup taskMetricGroup = StreamTaskTestHarness.createTaskMetricGroup(metrics);
    final StreamMockEnvironment environment = testHarness.createEnvironment();
    environment.setTaskMetricGroup(taskMetricGroup);
    testHarness.invoke(environment);
    testHarness.waitForTaskRunning();
    assertThat(metrics, IsMapContaining.hasKey(MetricNames.CHECKPOINT_ALIGNMENT_TIME));
    assertThat(metrics, IsMapContaining.hasKey(MetricNames.CHECKPOINT_START_DELAY_TIME));
    testHarness.endInput();
    testHarness.waitForTaskCompletion();
}
Also used : CoStreamMap(org.apache.flink.streaming.api.operators.co.CoStreamMap) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) InterceptingTaskMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) Metric(org.apache.flink.metrics.Metric) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 10 with Metric

use of org.apache.flink.metrics.Metric 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)

Aggregations

Metric (org.apache.flink.metrics.Metric)14 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 TaskMetricGroup (org.apache.flink.runtime.metrics.groups.TaskMetricGroup)6 Test (org.junit.Test)6 Gauge (org.apache.flink.metrics.Gauge)4 OperatorMetricGroup (org.apache.flink.metrics.groups.OperatorMetricGroup)4 InterceptingTaskMetricGroup (org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup)4 Configuration (org.apache.flink.configuration.Configuration)3 MetricGroup (org.apache.flink.metrics.MetricGroup)3 IOException (java.io.IOException)2 JobID (org.apache.flink.api.common.JobID)2 MetricReporter (org.apache.flink.metrics.reporter.MetricReporter)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)2 Status (akka.actor.Status)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1