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