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