Search in sources :

Example 21 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project kafka by apache.

the class ConnectMetricsTest method testGettingGroupMultipleTimes.

@Test
public void testGettingGroupMultipleTimes() {
    MetricGroup group1 = metrics.group("name");
    MetricGroup group2 = metrics.group("name");
    assertNotNull(group1);
    assertSame(group1, group2);
    MetricGroup group3 = metrics.group("other");
    assertNotNull(group3);
    assertNotSame(group1, group3);
    // Now with tags
    MetricGroup group4 = metrics.group("name", "k1", "v1");
    assertNotNull(group4);
    assertNotSame(group1, group4);
    assertNotSame(group2, group4);
    assertNotSame(group3, group4);
    MetricGroup group5 = metrics.group("name", "k1", "v1");
    assertSame(group4, group5);
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup) Test(org.junit.Test)

Example 22 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project kafka by apache.

the class WorkerSourceTaskTest method assertPollMetrics.

private void assertPollMetrics(int minimumPollCountExpected) {
    MetricGroup sourceTaskGroup = workerTask.sourceTaskMetricsGroup().metricGroup();
    MetricGroup taskGroup = workerTask.taskMetricsGroup().metricGroup();
    double pollRate = metrics.currentMetricValueAsDouble(sourceTaskGroup, "source-record-poll-rate");
    double pollTotal = metrics.currentMetricValueAsDouble(sourceTaskGroup, "source-record-poll-total");
    if (minimumPollCountExpected > 0) {
        assertEquals(RECORDS.size(), metrics.currentMetricValueAsDouble(taskGroup, "batch-size-max"), 0.000001d);
        assertEquals(RECORDS.size(), metrics.currentMetricValueAsDouble(taskGroup, "batch-size-avg"), 0.000001d);
        assertTrue(pollRate > 0.0d);
    } else {
        assertEquals(0.0d, pollRate, 0.0);
    }
    assertTrue(pollTotal >= minimumPollCountExpected);
    double writeRate = metrics.currentMetricValueAsDouble(sourceTaskGroup, "source-record-write-rate");
    double writeTotal = metrics.currentMetricValueAsDouble(sourceTaskGroup, "source-record-write-total");
    if (minimumPollCountExpected > 0) {
        assertTrue(writeRate > 0.0d);
    } else {
        assertEquals(0.0d, writeRate, 0.0);
    }
    assertTrue(writeTotal >= minimumPollCountExpected);
    double pollBatchTimeMax = metrics.currentMetricValueAsDouble(sourceTaskGroup, "poll-batch-max-time-ms");
    double pollBatchTimeAvg = metrics.currentMetricValueAsDouble(sourceTaskGroup, "poll-batch-avg-time-ms");
    if (minimumPollCountExpected > 0) {
        assertTrue(pollBatchTimeMax >= 0.0d);
    }
    assertTrue(Double.isNaN(pollBatchTimeAvg) || pollBatchTimeAvg > 0.0d);
    double activeCount = metrics.currentMetricValueAsDouble(sourceTaskGroup, "source-record-active-count");
    double activeCountMax = metrics.currentMetricValueAsDouble(sourceTaskGroup, "source-record-active-count-max");
    assertEquals(0, activeCount, 0.000001d);
    if (minimumPollCountExpected > 0) {
        assertEquals(RECORDS.size(), activeCountMax, 0.000001d);
    }
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 23 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project kafka by apache.

the class DistributedHerderTest method assertStatistics.

private void assertStatistics(String expectedLeader, boolean isRebalancing, int expectedEpoch, int completedRebalances, double rebalanceTime, double millisSinceLastRebalance) {
    HerderMetrics herderMetrics = herder.herderMetrics();
    MetricGroup group = herderMetrics.metricGroup();
    double epoch = MockConnectMetrics.currentMetricValueAsDouble(metrics, group, "epoch");
    String leader = MockConnectMetrics.currentMetricValueAsString(metrics, group, "leader-name");
    double rebalanceCompletedTotal = MockConnectMetrics.currentMetricValueAsDouble(metrics, group, "completed-rebalances-total");
    double rebalancing = MockConnectMetrics.currentMetricValueAsDouble(metrics, group, "rebalancing");
    double rebalanceTimeMax = MockConnectMetrics.currentMetricValueAsDouble(metrics, group, "rebalance-max-time-ms");
    double rebalanceTimeAvg = MockConnectMetrics.currentMetricValueAsDouble(metrics, group, "rebalance-avg-time-ms");
    double rebalanceTimeSinceLast = MockConnectMetrics.currentMetricValueAsDouble(metrics, group, "time-since-last-rebalance-ms");
    assertEquals(expectedEpoch, epoch, 0.0001d);
    assertEquals(expectedLeader, leader);
    assertEquals(completedRebalances, rebalanceCompletedTotal, 0.0001d);
    assertEquals(isRebalancing ? 1.0d : 0.0d, rebalancing, 0.0001d);
    assertEquals(millisSinceLastRebalance, rebalanceTimeSinceLast, 0.0001d);
    if (rebalanceTime <= 0L) {
        assertEquals(Double.NaN, rebalanceTimeMax, 0.0001d);
        assertEquals(Double.NaN, rebalanceTimeAvg, 0.0001d);
    } else {
        assertEquals(rebalanceTime, rebalanceTimeMax, 0.0001d);
        assertEquals(rebalanceTime, rebalanceTimeAvg, 0.0001d);
    }
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup) HerderMetrics(org.apache.kafka.connect.runtime.distributed.DistributedHerder.HerderMetrics)

Example 24 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project kafka by apache.

the class WorkerTest method assertStatistics.

private void assertStatistics(Worker worker, int connectors, int tasks) {
    assertStatusMetrics(tasks, "connector-total-task-count");
    MetricGroup workerMetrics = worker.workerMetricsGroup().metricGroup();
    assertEquals(connectors, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "connector-count"), 0.0001d);
    assertEquals(tasks, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-count"), 0.0001d);
    assertEquals(tasks, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-count"), 0.0001d);
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 25 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project kafka by apache.

the class WorkerTest method assertStatusMetrics.

private void assertStatusMetrics(long expected, String metricName) {
    MetricGroup statusMetrics = worker.connectorStatusMetricsGroup().metricGroup(TASK_ID.connector());
    if (expected == 0L) {
        assertNull(statusMetrics);
        return;
    }
    assertEquals(expected, MockConnectMetrics.currentMetricValue(worker.metrics(), statusMetrics, metricName));
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Aggregations

MetricGroup (org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)29 Test (org.junit.Test)4 Sensor (org.apache.kafka.common.metrics.Sensor)2 Avg (org.apache.kafka.common.metrics.stats.Avg)2 Max (org.apache.kafka.common.metrics.stats.Max)2 HerderMetrics (org.apache.kafka.connect.runtime.distributed.DistributedHerder.HerderMetrics)2