Search in sources :

Example 1 with SinkTaskMetricsGroup

use of org.apache.kafka.connect.runtime.WorkerSinkTask.SinkTaskMetricsGroup in project apache-kafka-on-k8s by banzaicloud.

the class WorkerSinkTaskTest method testMetricsGroup.

@Test
public void testMetricsGroup() {
    SinkTaskMetricsGroup group = new SinkTaskMetricsGroup(taskId, metrics);
    SinkTaskMetricsGroup group1 = new SinkTaskMetricsGroup(taskId1, metrics);
    for (int i = 0; i != 10; ++i) {
        group.recordRead(1);
        group.recordSend(2);
        group.recordPut(3);
        group.recordPartitionCount(4);
        group.recordOffsetSequenceNumber(5);
    }
    Map<TopicPartition, OffsetAndMetadata> committedOffsets = new HashMap<>();
    committedOffsets.put(TOPIC_PARTITION, new OffsetAndMetadata(FIRST_OFFSET + 1));
    group.recordCommittedOffsets(committedOffsets);
    Map<TopicPartition, OffsetAndMetadata> consumedOffsets = new HashMap<>();
    consumedOffsets.put(TOPIC_PARTITION, new OffsetAndMetadata(FIRST_OFFSET + 10));
    group.recordConsumedOffsets(consumedOffsets);
    for (int i = 0; i != 20; ++i) {
        group1.recordRead(1);
        group1.recordSend(2);
        group1.recordPut(30);
        group1.recordPartitionCount(40);
        group1.recordOffsetSequenceNumber(50);
    }
    committedOffsets = new HashMap<>();
    committedOffsets.put(TOPIC_PARTITION2, new OffsetAndMetadata(FIRST_OFFSET + 2));
    committedOffsets.put(TOPIC_PARTITION3, new OffsetAndMetadata(FIRST_OFFSET + 3));
    group1.recordCommittedOffsets(committedOffsets);
    consumedOffsets = new HashMap<>();
    consumedOffsets.put(TOPIC_PARTITION2, new OffsetAndMetadata(FIRST_OFFSET + 20));
    consumedOffsets.put(TOPIC_PARTITION3, new OffsetAndMetadata(FIRST_OFFSET + 30));
    group1.recordConsumedOffsets(consumedOffsets);
    assertEquals(0.333, metrics.currentMetricValueAsDouble(group.metricGroup(), "sink-record-read-rate"), 0.001d);
    assertEquals(0.667, metrics.currentMetricValueAsDouble(group.metricGroup(), "sink-record-send-rate"), 0.001d);
    assertEquals(9, metrics.currentMetricValueAsDouble(group.metricGroup(), "sink-record-active-count"), 0.001d);
    assertEquals(4, metrics.currentMetricValueAsDouble(group.metricGroup(), "partition-count"), 0.001d);
    assertEquals(5, metrics.currentMetricValueAsDouble(group.metricGroup(), "offset-commit-seq-no"), 0.001d);
    assertEquals(3, metrics.currentMetricValueAsDouble(group.metricGroup(), "put-batch-max-time-ms"), 0.001d);
    // Close the group
    group.close();
    for (MetricName metricName : group.metricGroup().metrics().metrics().keySet()) {
        // Metrics for this group should no longer exist
        assertFalse(group.metricGroup().groupId().includes(metricName));
    }
    // Sensors for this group should no longer exist
    assertNull(group.metricGroup().metrics().getSensor("source-record-poll"));
    assertNull(group.metricGroup().metrics().getSensor("source-record-write"));
    assertNull(group.metricGroup().metrics().getSensor("poll-batch-time"));
    assertEquals(0.667, metrics.currentMetricValueAsDouble(group1.metricGroup(), "sink-record-read-rate"), 0.001d);
    assertEquals(1.333, metrics.currentMetricValueAsDouble(group1.metricGroup(), "sink-record-send-rate"), 0.001d);
    assertEquals(45, metrics.currentMetricValueAsDouble(group1.metricGroup(), "sink-record-active-count"), 0.001d);
    assertEquals(40, metrics.currentMetricValueAsDouble(group1.metricGroup(), "partition-count"), 0.001d);
    assertEquals(50, metrics.currentMetricValueAsDouble(group1.metricGroup(), "offset-commit-seq-no"), 0.001d);
    assertEquals(30, metrics.currentMetricValueAsDouble(group1.metricGroup(), "put-batch-max-time-ms"), 0.001d);
}
Also used : MetricName(org.apache.kafka.common.MetricName) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) SinkTaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerSinkTask.SinkTaskMetricsGroup) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with SinkTaskMetricsGroup

use of org.apache.kafka.connect.runtime.WorkerSinkTask.SinkTaskMetricsGroup in project kafka by apache.

the class WorkerSinkTaskTest method testMetricsGroup.

@Test
public void testMetricsGroup() {
    SinkTaskMetricsGroup group = new SinkTaskMetricsGroup(taskId, metrics);
    SinkTaskMetricsGroup group1 = new SinkTaskMetricsGroup(taskId1, metrics);
    for (int i = 0; i != 10; ++i) {
        group.recordRead(1);
        group.recordSend(2);
        group.recordPut(3);
        group.recordPartitionCount(4);
        group.recordOffsetSequenceNumber(5);
    }
    Map<TopicPartition, OffsetAndMetadata> committedOffsets = new HashMap<>();
    committedOffsets.put(TOPIC_PARTITION, new OffsetAndMetadata(FIRST_OFFSET + 1));
    group.recordCommittedOffsets(committedOffsets);
    Map<TopicPartition, OffsetAndMetadata> consumedOffsets = new HashMap<>();
    consumedOffsets.put(TOPIC_PARTITION, new OffsetAndMetadata(FIRST_OFFSET + 10));
    group.recordConsumedOffsets(consumedOffsets);
    for (int i = 0; i != 20; ++i) {
        group1.recordRead(1);
        group1.recordSend(2);
        group1.recordPut(30);
        group1.recordPartitionCount(40);
        group1.recordOffsetSequenceNumber(50);
    }
    committedOffsets = new HashMap<>();
    committedOffsets.put(TOPIC_PARTITION2, new OffsetAndMetadata(FIRST_OFFSET + 2));
    committedOffsets.put(TOPIC_PARTITION3, new OffsetAndMetadata(FIRST_OFFSET + 3));
    group1.recordCommittedOffsets(committedOffsets);
    consumedOffsets = new HashMap<>();
    consumedOffsets.put(TOPIC_PARTITION2, new OffsetAndMetadata(FIRST_OFFSET + 20));
    consumedOffsets.put(TOPIC_PARTITION3, new OffsetAndMetadata(FIRST_OFFSET + 30));
    group1.recordConsumedOffsets(consumedOffsets);
    assertEquals(0.333, metrics.currentMetricValueAsDouble(group.metricGroup(), "sink-record-read-rate"), 0.001d);
    assertEquals(0.667, metrics.currentMetricValueAsDouble(group.metricGroup(), "sink-record-send-rate"), 0.001d);
    assertEquals(9, metrics.currentMetricValueAsDouble(group.metricGroup(), "sink-record-active-count"), 0.001d);
    assertEquals(4, metrics.currentMetricValueAsDouble(group.metricGroup(), "partition-count"), 0.001d);
    assertEquals(5, metrics.currentMetricValueAsDouble(group.metricGroup(), "offset-commit-seq-no"), 0.001d);
    assertEquals(3, metrics.currentMetricValueAsDouble(group.metricGroup(), "put-batch-max-time-ms"), 0.001d);
    // Close the group
    group.close();
    for (MetricName metricName : group.metricGroup().metrics().metrics().keySet()) {
        // Metrics for this group should no longer exist
        assertFalse(group.metricGroup().groupId().includes(metricName));
    }
    // Sensors for this group should no longer exist
    assertNull(group.metricGroup().metrics().getSensor("source-record-poll"));
    assertNull(group.metricGroup().metrics().getSensor("source-record-write"));
    assertNull(group.metricGroup().metrics().getSensor("poll-batch-time"));
    assertEquals(0.667, metrics.currentMetricValueAsDouble(group1.metricGroup(), "sink-record-read-rate"), 0.001d);
    assertEquals(1.333, metrics.currentMetricValueAsDouble(group1.metricGroup(), "sink-record-send-rate"), 0.001d);
    assertEquals(45, metrics.currentMetricValueAsDouble(group1.metricGroup(), "sink-record-active-count"), 0.001d);
    assertEquals(40, metrics.currentMetricValueAsDouble(group1.metricGroup(), "partition-count"), 0.001d);
    assertEquals(50, metrics.currentMetricValueAsDouble(group1.metricGroup(), "offset-commit-seq-no"), 0.001d);
    assertEquals(30, metrics.currentMetricValueAsDouble(group1.metricGroup(), "put-batch-max-time-ms"), 0.001d);
}
Also used : MetricName(org.apache.kafka.common.MetricName) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) SinkTaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerSinkTask.SinkTaskMetricsGroup) RetryWithToleranceOperatorTest(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)2 MetricName (org.apache.kafka.common.MetricName)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 SinkTaskMetricsGroup (org.apache.kafka.connect.runtime.WorkerSinkTask.SinkTaskMetricsGroup)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 RetryWithToleranceOperatorTest (org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest)1