Search in sources :

Example 56 with Counter

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

the class OneInputStreamTask method init.

@Override
public void init() throws Exception {
    StreamConfig configuration = getConfiguration();
    int numberOfInputs = configuration.getNumberOfNetworkInputs();
    if (numberOfInputs > 0) {
        CheckpointedInputGate inputGate = createCheckpointedInputGate();
        Counter numRecordsIn = setupNumRecordsInCounter(mainOperator);
        DataOutput<IN> output = createDataOutput(numRecordsIn);
        StreamTaskInput<IN> input = createTaskInput(inputGate);
        StreamConfig.InputConfig[] inputConfigs = configuration.getInputs(getUserCodeClassLoader());
        StreamConfig.InputConfig inputConfig = inputConfigs[0];
        if (requiresSorting(inputConfig)) {
            checkState(!configuration.isCheckpointingEnabled(), "Checkpointing is not allowed with sorted inputs.");
            input = wrapWithSorted(input);
        }
        getEnvironment().getMetricGroup().getIOMetricGroup().reuseRecordsInputCounter(numRecordsIn);
        inputProcessor = new StreamOneInputProcessor<>(input, output, operatorChain);
    }
    mainOperator.getMetricGroup().gauge(MetricNames.IO_CURRENT_INPUT_WATERMARK, inputWatermarkGauge);
    // wrap watermark gauge since registered metrics must be unique
    getEnvironment().getMetricGroup().gauge(MetricNames.IO_CURRENT_INPUT_WATERMARK, inputWatermarkGauge::getValue);
}
Also used : Counter(org.apache.flink.metrics.Counter) CheckpointedInputGate(org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig)

Example 57 with Counter

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

the class TwoInputStreamTaskTest method testOperatorMetricReuse.

@Test
public void testOperatorMetricReuse() throws Exception {
    final TwoInputStreamTaskTestHarness<String, String, String> testHarness = new TwoInputStreamTaskTestHarness<>(TwoInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
    testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator()).chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).finish();
    final TaskMetricGroup taskMetricGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(NoOpMetricRegistry.INSTANCE, "host", ResourceID.generate()).addJob(new JobID(), "jobname").addTask(new JobVertexID(), new ExecutionAttemptID(), "task", 0, 0);
    final StreamMockEnvironment env = new StreamMockEnvironment(testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {

        @Override
        public TaskMetricGroup getMetricGroup() {
            return taskMetricGroup;
        }
    };
    final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();
    testHarness.invoke(env);
    testHarness.waitForTaskRunning();
    final int numRecords1 = 5;
    final int numRecords2 = 3;
    for (int x = 0; x < numRecords1; x++) {
        testHarness.processElement(new StreamRecord<>("hello"), 0, 0);
    }
    for (int x = 0; x < numRecords2; x++) {
        testHarness.processElement(new StreamRecord<>("hello"), 1, 0);
    }
    testHarness.waitForInputProcessing();
    assertEquals(numRecords1 + numRecords2, numRecordsInCounter.getCount());
    assertEquals((numRecords1 + numRecords2) * 2 * 2 * 2, numRecordsOutCounter.getCount());
    testHarness.endInput();
    testHarness.waitForTaskCompletion();
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) InterceptingTaskMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) Counter(org.apache.flink.metrics.Counter) MockInputSplitProvider(org.apache.flink.runtime.operators.testutils.MockInputSplitProvider) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 58 with Counter

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

the class MetricQueryServiceTest method testCreateDump.

@Test
public void testCreateDump() throws Exception {
    MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
    queryService.start();
    final Counter c = new SimpleCounter();
    final Gauge<String> g = () -> "Hello";
    final Histogram h = new TestHistogram();
    final Meter m = new TestMeter();
    final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();
    queryService.addMetric("counter", c, tm);
    queryService.addMetric("gauge", g, tm);
    queryService.addMetric("histogram", h, tm);
    queryService.addMetric("meter", m, tm);
    MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();
    assertTrue(dump.serializedCounters.length > 0);
    assertTrue(dump.serializedGauges.length > 0);
    assertTrue(dump.serializedHistograms.length > 0);
    assertTrue(dump.serializedMeters.length > 0);
    queryService.removeMetric(c);
    queryService.removeMetric(g);
    queryService.removeMetric(h);
    queryService.removeMetric(m);
    MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();
    assertEquals(0, emptyDump.serializedCounters.length);
    assertEquals(0, emptyDump.serializedGauges.length);
    assertEquals(0, emptyDump.serializedHistograms.length);
    assertEquals(0, emptyDump.serializedMeters.length);
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestMeter(org.apache.flink.metrics.util.TestMeter) Meter(org.apache.flink.metrics.Meter) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.Test)

Example 59 with Counter

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

the class OneInputStreamTaskTest method testOperatorMetricReuse.

@Test
public void testOperatorMetricReuse() throws Exception {
    final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
    testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator()).chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).finish();
    final TaskMetricGroup taskMetricGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(NoOpMetricRegistry.INSTANCE, "host", ResourceID.generate()).addJob(new JobID(), "jobname").addTask(new JobVertexID(), new ExecutionAttemptID(), "task", 0, 0);
    final StreamMockEnvironment env = new StreamMockEnvironment(testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {

        @Override
        public TaskMetricGroup getMetricGroup() {
            return taskMetricGroup;
        }
    };
    final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();
    testHarness.invoke(env);
    testHarness.waitForTaskRunning();
    final int numRecords = 5;
    for (int x = 0; x < numRecords; x++) {
        testHarness.processElement(new StreamRecord<>("hello"));
    }
    testHarness.waitForInputProcessing();
    assertEquals(numRecords, numRecordsInCounter.getCount());
    assertEquals(numRecords * 2 * 2 * 2, numRecordsOutCounter.getCount());
    testHarness.endInput();
    testHarness.waitForTaskCompletion();
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) InterceptingTaskMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingTaskMetricGroup) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) Counter(org.apache.flink.metrics.Counter) MockInputSplitProvider(org.apache.flink.runtime.operators.testutils.MockInputSplitProvider) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 60 with Counter

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

the class InputChannelMetrics method createCounter.

private static Counter createCounter(String name, MetricGroup... parents) {
    Counter[] counters = new Counter[parents.length];
    for (int i = 0; i < parents.length; i++) {
        counters[i] = parents[i].counter(name);
        parents[i].meter(name + MetricNames.SUFFIX_RATE, new MeterView(counters[i]));
    }
    return new MultiCounterWrapper(counters);
}
Also used : Counter(org.apache.flink.metrics.Counter) MeterView(org.apache.flink.metrics.MeterView)

Aggregations

Counter (org.apache.flink.metrics.Counter)78 SimpleCounter (org.apache.flink.metrics.SimpleCounter)24 Test (org.junit.Test)22 CountingCollector (org.apache.flink.runtime.operators.util.metrics.CountingCollector)18 Test (org.junit.jupiter.api.Test)16 Histogram (org.apache.flink.metrics.Histogram)15 Meter (org.apache.flink.metrics.Meter)15 Gauge (org.apache.flink.metrics.Gauge)14 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)12 CountingMutableObjectIterator (org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)10 MetricGroup (org.apache.flink.metrics.MetricGroup)7 TestHistogram (org.apache.flink.metrics.util.TestHistogram)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 TestMeter (org.apache.flink.metrics.util.TestMeter)5 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 OperatorIOMetricGroup (org.apache.flink.metrics.groups.OperatorIOMetricGroup)4 MetricListener (org.apache.flink.metrics.testutils.MetricListener)4