Search in sources :

Example 1 with LatencyMarker

use of org.apache.flink.streaming.runtime.streamrecord.LatencyMarker in project flink by apache.

the class InputTest method setup.

@Before
public void setup() {
    element = new StreamRecord<>(GenericRowData.of(StringData.fromString("123")), 456);
    watermark = new Watermark(1223456789);
    latencyMarker = new LatencyMarker(122345678, new OperatorID(123, 456), 1);
}
Also used : LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Before(org.junit.Before)

Example 2 with LatencyMarker

use of org.apache.flink.streaming.runtime.streamrecord.LatencyMarker in project flink by apache.

the class SourceOperatorLatencyMetricsTest method testLatencyMarkEmission.

private void testLatencyMarkEmission(boolean shouldExpectLatencyMarkers, Configuration taskManagerConfig, ExecutionConfig executionConfig) throws Exception {
    try (SourceOperatorTestHarness testHarness = new SourceOperatorTestHarness(new SourceOperatorFactory(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), new MockEnvironmentBuilder().setTaskManagerRuntimeInfo(new TestingTaskManagerRuntimeInfo(taskManagerConfig)).setExecutionConfig(executionConfig).build())) {
        testHarness.open();
        testHarness.setup();
        for (long processingTime = 0; processingTime <= MAX_PROCESSING_TIME; processingTime++) {
            testHarness.getProcessingTimeService().setCurrentTime(processingTime);
            testHarness.emitNext();
        }
        List<LatencyMarker> expectedOutput = new ArrayList<>();
        if (!shouldExpectLatencyMarkers) {
            assertTrue(testHarness.getOutput().isEmpty());
        } else {
            expectedOutput.add(new LatencyMarker(1, testHarness.getOperator().getOperatorID(), 0));
            for (long markedTime = LATENCY_MARK_INTERVAL; markedTime <= MAX_PROCESSING_TIME; markedTime += LATENCY_MARK_INTERVAL) {
                expectedOutput.add(new LatencyMarker(markedTime, testHarness.getOperator().getOperatorID(), 0));
            }
            assertThat((Collection<Object>) testHarness.getOutput(), contains(expectedOutput.toArray()));
        }
    }
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) SourceOperatorTestHarness(org.apache.flink.streaming.util.SourceOperatorTestHarness) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) ArrayList(java.util.ArrayList) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory)

Example 3 with LatencyMarker

use of org.apache.flink.streaming.runtime.streamrecord.LatencyMarker 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 4 with LatencyMarker

use of org.apache.flink.streaming.runtime.streamrecord.LatencyMarker in project flink by apache.

the class MultipleInputStreamTaskTest method testLatencyMarker.

@Test
public void testLatencyMarker() 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).addInput(BasicTypeInfo.INT_TYPE_INFO).addInput(BasicTypeInfo.DOUBLE_TYPE_INFO).setupOutputForSingletonOperatorChain(new MapToStringMultipleInputOperatorFactory(3)).setTaskMetricGroup(taskMetricGroup).build()) {
        ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
        OperatorID sourceId = new OperatorID();
        LatencyMarker latencyMarker = new LatencyMarker(42L, sourceId, 0);
        testHarness.processElement(latencyMarker);
        expectedOutput.add(latencyMarker);
        assertThat(testHarness.getOutput(), contains(expectedOutput.toArray()));
        testHarness.endInput();
        testHarness.waitForTaskCompletion();
    }
}
Also used : InterceptingTaskMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ArrayDeque(java.util.ArrayDeque) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) Metric(org.apache.flink.metrics.Metric) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 5 with LatencyMarker

use of org.apache.flink.streaming.runtime.streamrecord.LatencyMarker in project flink by apache.

the class OutputTest method setup.

@Before
public void setup() {
    element = new StreamRecord<>(GenericRowData.of(StringData.fromString("123")), 456);
    watermark = new Watermark(1223456789);
    latencyMarker = new LatencyMarker(122345678, new OperatorID(123, 456), 1);
    serializer = InternalTypeInfo.of(RowType.of(DataTypes.STRING().getLogicalType())).createSerializer(new ExecutionConfig());
}
Also used : LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Before(org.junit.Before)

Aggregations

LatencyMarker (org.apache.flink.streaming.runtime.streamrecord.LatencyMarker)5 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)4 ArrayList (java.util.ArrayList)2 Watermark (org.apache.flink.streaming.api.watermark.Watermark)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ArrayDeque (java.util.ArrayDeque)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Consumer (java.util.function.Consumer)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 MockSource (org.apache.flink.api.connector.source.mocks.MockSource)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 MetricOptions (org.apache.flink.configuration.MetricOptions)1 Histogram (org.apache.flink.metrics.Histogram)1 Metric (org.apache.flink.metrics.Metric)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 AbstractMetricGroup (org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)1 GenericMetricGroup (org.apache.flink.runtime.metrics.groups.GenericMetricGroup)1 TaskMetricGroup (org.apache.flink.runtime.metrics.groups.TaskMetricGroup)1