Search in sources :

Example 1 with Counter

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

the class KafkaSourceReaderMetricsTest method testCommitOffsetTracking.

@Test
public void testCommitOffsetTracking() {
    MetricListener metricListener = new MetricListener();
    final KafkaSourceReaderMetrics kafkaSourceReaderMetrics = new KafkaSourceReaderMetrics(InternalSourceReaderMetricGroup.mock(metricListener.getMetricGroup()));
    kafkaSourceReaderMetrics.registerTopicPartition(FOO_0);
    kafkaSourceReaderMetrics.registerTopicPartition(FOO_1);
    kafkaSourceReaderMetrics.registerTopicPartition(BAR_0);
    kafkaSourceReaderMetrics.registerTopicPartition(BAR_1);
    kafkaSourceReaderMetrics.recordCommittedOffset(FOO_0, 15213L);
    kafkaSourceReaderMetrics.recordCommittedOffset(FOO_1, 18213L);
    kafkaSourceReaderMetrics.recordCommittedOffset(BAR_0, 18613L);
    kafkaSourceReaderMetrics.recordCommittedOffset(BAR_1, 15513L);
    assertCommittedOffset(FOO_0, 15213L, metricListener);
    assertCommittedOffset(FOO_1, 18213L, metricListener);
    assertCommittedOffset(BAR_0, 18613L, metricListener);
    assertCommittedOffset(BAR_1, 15513L, metricListener);
    final Optional<Counter> commitsSucceededCounter = metricListener.getCounter(KafkaSourceReaderMetrics.KAFKA_SOURCE_READER_METRIC_GROUP, KafkaSourceReaderMetrics.COMMITS_SUCCEEDED_METRIC_COUNTER);
    assertTrue(commitsSucceededCounter.isPresent());
    assertEquals(0L, commitsSucceededCounter.get().getCount());
    kafkaSourceReaderMetrics.recordSucceededCommit();
    assertEquals(1L, commitsSucceededCounter.get().getCount());
}
Also used : Counter(org.apache.flink.metrics.Counter) MetricListener(org.apache.flink.metrics.testutils.MetricListener) Test(org.junit.Test)

Example 2 with Counter

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

the class FlinkMetricContainer method updateCounterOrMeter.

private void updateCounterOrMeter(Iterable<MetricResult<Long>> counters) {
    for (MetricResult<Long> metricResult : counters) {
        if (!isUserMetric(metricResult)) {
            continue;
        }
        // get identifier
        String flinkMetricIdentifier = getFlinkMetricIdentifierString(metricResult.getKey());
        // get metric type
        ArrayList<String> scopeComponents = getNameSpaceArray(metricResult.getKey());
        if ((scopeComponents.size() % 2) != 0) {
            Meter meter = flinkMeterCache.get(flinkMetricIdentifier);
            if (null == meter) {
                int timeSpanInSeconds = Integer.parseInt(scopeComponents.get(scopeComponents.size() - 1));
                MetricGroup metricGroup = registerMetricGroup(metricResult.getKey(), baseMetricGroup);
                meter = metricGroup.meter(metricResult.getKey().metricName().getName(), new MeterView(timeSpanInSeconds));
                flinkMeterCache.put(flinkMetricIdentifier, meter);
            }
            Long update = metricResult.getAttempted();
            meter.markEvent(update - meter.getCount());
        } else {
            Counter counter = flinkCounterCache.get(flinkMetricIdentifier);
            if (null == counter) {
                MetricGroup metricGroup = registerMetricGroup(metricResult.getKey(), baseMetricGroup);
                counter = metricGroup.counter(metricResult.getKey().metricName().getName());
                flinkCounterCache.put(flinkMetricIdentifier, counter);
            }
            Long update = metricResult.getAttempted();
            counter.inc(update - counter.getCount());
        }
    }
}
Also used : Counter(org.apache.flink.metrics.Counter) Meter(org.apache.flink.metrics.Meter) MetricGroup(org.apache.flink.metrics.MetricGroup) MeterView(org.apache.flink.metrics.MeterView)

Example 3 with Counter

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

the class AbstractCachedBuildSideJoinDriver method run.

@Override
public void run() throws Exception {
    final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    final FlatJoinFunction<IT1, IT2, OT> matchStub = this.taskContext.getStub();
    final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    while (this.running && matchIterator != null && matchIterator.callWithNextKey(matchStub, collector)) {
    }
}
Also used : CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter)

Example 4 with Counter

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

the class CrossDriver method runBlockedOuterFirst.

private void runBlockedOuterFirst() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("Running Cross with Block-Nested-Loops: " + "First input is outer (blocking) side, second input is inner (spilling) side."));
    }
    final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    final MutableObjectIterator<T1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<T1>getInput(0), numRecordsIn);
    final MutableObjectIterator<T2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<T2>getInput(1), numRecordsIn);
    final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
    final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
    final BlockResettableMutableObjectIterator<T1> blockVals = new BlockResettableMutableObjectIterator<T1>(this.memManager, in1, serializer1, this.memPagesForBlockSide, this.taskContext.getContainingTask());
    this.blockIter = blockVals;
    final SpillingResettableMutableObjectIterator<T2> spillVals = new SpillingResettableMutableObjectIterator<T2>(in2, serializer2, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide, this.taskContext.getContainingTask());
    this.spillIter = spillVals;
    final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
    final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final T1 val1Reuse = serializer1.createInstance();
        final T2 val2Reuse = serializer2.createInstance();
        T1 val1;
        T2 val2;
        // for all blocks
        do {
            // for all values from the spilling side
            while (this.running && ((val2 = spillVals.next(val2Reuse)) != null)) {
                // for all values in the block
                while ((val1 = blockVals.next(val1Reuse)) != null) {
                    collector.collect(crosser.cross(val1, val2));
                }
                blockVals.reset();
            }
            spillVals.reset();
        } while (this.running && blockVals.nextBlock());
    } else {
        T1 val1;
        T2 val2;
        // for all blocks
        do {
            // for all values from the spilling side
            while (this.running && ((val2 = spillVals.next()) != null)) {
                // for all values in the block
                while ((val1 = blockVals.next()) != null) {
                    collector.collect(crosser.cross(val1, serializer2.copy(val2)));
                }
                blockVals.reset();
            }
            spillVals.reset();
        } while (this.running && blockVals.nextBlock());
    }
}
Also used : SpillingResettableMutableObjectIterator(org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator) BlockResettableMutableObjectIterator(org.apache.flink.runtime.operators.resettable.BlockResettableMutableObjectIterator) CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)

Example 5 with Counter

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

the class CrossDriver method runStreamedOuterSecond.

private void runStreamedOuterSecond() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("Running Cross with Nested-Loops: " + "First input is inner (spilling) side, second input is outer side."));
    }
    final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    final MutableObjectIterator<T1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<T1>getInput(0), numRecordsIn);
    final MutableObjectIterator<T2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<T2>getInput(1), numRecordsIn);
    final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
    final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
    final SpillingResettableMutableObjectIterator<T1> spillVals = new SpillingResettableMutableObjectIterator<T1>(in1, serializer1, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide, this.taskContext.getContainingTask());
    this.spillIter = spillVals;
    final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
    final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final T1 val1Reuse = serializer1.createInstance();
        final T2 val2Reuse = serializer2.createInstance();
        T1 val1;
        T2 val2;
        // for all blocks
        while (this.running && (val2 = in2.next(val2Reuse)) != null) {
            // for all values from the spilling side
            while (this.running && (val1 = spillVals.next(val1Reuse)) != null) {
                collector.collect(crosser.cross(val1, val2));
            // crosser.cross(val1, val2Copy, collector);
            }
            spillVals.reset();
        }
    } else {
        T1 val1;
        T2 val2;
        // for all blocks
        while (this.running && (val2 = in2.next()) != null) {
            // for all values from the spilling side
            while (this.running && (val1 = spillVals.next()) != null) {
                collector.collect(crosser.cross(val1, serializer2.copy(val2)));
            }
            spillVals.reset();
        }
    }
}
Also used : SpillingResettableMutableObjectIterator(org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator) CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)

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