Search in sources :

Example 1 with InternalSinkWriterMetricGroup

use of org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup in project flink by apache.

the class KafkaWriterITCase method testIncreasingRecordBasedCounters.

@Test
public void testIncreasingRecordBasedCounters() throws Exception {
    final OperatorIOMetricGroup operatorIOMetricGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup().getIOMetricGroup();
    final InternalSinkWriterMetricGroup metricGroup = InternalSinkWriterMetricGroup.mock(metricListener.getMetricGroup(), operatorIOMetricGroup);
    try (final KafkaWriter<Integer> writer = createWriterWithConfiguration(getKafkaClientConfiguration(), DeliveryGuarantee.NONE, metricGroup)) {
        final Counter numBytesOut = operatorIOMetricGroup.getNumBytesOutCounter();
        final Counter numRecordsOut = operatorIOMetricGroup.getNumRecordsOutCounter();
        assertEquals(numBytesOut.getCount(), 0L);
        writer.write(1, SINK_WRITER_CONTEXT);
        timeService.trigger();
        assertEquals(numRecordsOut.getCount(), 1);
        assertThat(numBytesOut.getCount(), greaterThan(0L));
    }
}
Also used : Counter(org.apache.flink.metrics.Counter) OperatorIOMetricGroup(org.apache.flink.metrics.groups.OperatorIOMetricGroup) InternalSinkWriterMetricGroup(org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with InternalSinkWriterMetricGroup

use of org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup in project flink by apache.

the class KafkaWriterITCase method testCurrentSendTimeMetric.

@Test
public void testCurrentSendTimeMetric() throws Exception {
    final InternalSinkWriterMetricGroup metricGroup = InternalSinkWriterMetricGroup.mock(metricListener.getMetricGroup());
    try (final KafkaWriter<Integer> writer = createWriterWithConfiguration(getKafkaClientConfiguration(), DeliveryGuarantee.AT_LEAST_ONCE, metricGroup)) {
        final Optional<Gauge<Long>> currentSendTime = metricListener.getGauge("currentSendTime");
        assertTrue(currentSendTime.isPresent());
        assertEquals(currentSendTime.get().getValue(), 0L);
        IntStream.range(0, 100).forEach((run) -> {
            try {
                writer.write(1, SINK_WRITER_CONTEXT);
                // Manually flush the records to generate a sendTime
                if (run % 10 == 0) {
                    writer.flush(false);
                }
            } catch (IOException | InterruptedException e) {
                throw new RuntimeException("Failed writing Kafka record.");
            }
        });
        assertThat(currentSendTime.get().getValue(), greaterThan(0L));
    }
}
Also used : IOException(java.io.IOException) InternalSinkWriterMetricGroup(org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup) Gauge(org.apache.flink.metrics.Gauge) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with InternalSinkWriterMetricGroup

use of org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup in project flink by apache.

the class ElasticsearchWriterITCase method testIncrementByteOutMetric.

@Test
void testIncrementByteOutMetric() throws Exception {
    final String index = "test-inc-byte-out";
    final OperatorIOMetricGroup operatorIOMetricGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup().getIOMetricGroup();
    final InternalSinkWriterMetricGroup metricGroup = InternalSinkWriterMetricGroup.mock(metricListener.getMetricGroup(), operatorIOMetricGroup);
    final int flushAfterNActions = 2;
    final BulkProcessorConfig bulkProcessorConfig = new BulkProcessorConfig(flushAfterNActions, -1, -1, FlushBackoffType.NONE, 0, 0);
    try (final ElasticsearchWriter<Tuple2<Integer, String>> writer = createWriter(index, false, bulkProcessorConfig, metricGroup)) {
        final Counter numBytesOut = operatorIOMetricGroup.getNumBytesOutCounter();
        assertEquals(numBytesOut.getCount(), 0);
        writer.write(Tuple2.of(1, buildMessage(1)), null);
        writer.write(Tuple2.of(2, buildMessage(2)), null);
        writer.blockingFlushAllActions();
        long first = numBytesOut.getCount();
        assertTrue(first > 0);
        writer.write(Tuple2.of(1, buildMessage(1)), null);
        writer.write(Tuple2.of(2, buildMessage(2)), null);
        writer.blockingFlushAllActions();
        assertTrue(numBytesOut.getCount() > first);
    }
}
Also used : Counter(org.apache.flink.metrics.Counter) OperatorIOMetricGroup(org.apache.flink.metrics.groups.OperatorIOMetricGroup) Tuple2(org.apache.flink.api.java.tuple.Tuple2) InternalSinkWriterMetricGroup(org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InternalSinkWriterMetricGroup (org.apache.flink.runtime.metrics.groups.InternalSinkWriterMetricGroup)3 Test (org.junit.jupiter.api.Test)3 Counter (org.apache.flink.metrics.Counter)2 OperatorIOMetricGroup (org.apache.flink.metrics.groups.OperatorIOMetricGroup)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 IOException (java.io.IOException)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Gauge (org.apache.flink.metrics.Gauge)1