Search in sources :

Example 16 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project apache-kafka-on-k8s by banzaicloud.

the class WorkerTest method assertStartupStatistics.

private void assertStartupStatistics(Worker worker, int connectorStartupAttempts, int connectorStartupFailures, int taskStartupAttempts, int taskStartupFailures) {
    double connectStartupSuccesses = connectorStartupAttempts - connectorStartupFailures;
    double taskStartupSuccesses = taskStartupAttempts - taskStartupFailures;
    double connectStartupSuccessPct = 0.0d;
    double connectStartupFailurePct = 0.0d;
    double taskStartupSuccessPct = 0.0d;
    double taskStartupFailurePct = 0.0d;
    if (connectorStartupAttempts != 0) {
        connectStartupSuccessPct = connectStartupSuccesses / connectorStartupAttempts;
        connectStartupFailurePct = (double) connectorStartupFailures / connectorStartupAttempts;
    }
    if (taskStartupAttempts != 0) {
        taskStartupSuccessPct = taskStartupSuccesses / taskStartupAttempts;
        taskStartupFailurePct = (double) taskStartupFailures / taskStartupAttempts;
    }
    MetricGroup workerMetrics = worker.workerMetricsGroup().metricGroup();
    assertEquals(connectorStartupAttempts, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "connector-startup-attempts-total"), 0.0001d);
    assertEquals(connectStartupSuccesses, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "connector-startup-success-total"), 0.0001d);
    assertEquals(connectorStartupFailures, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "connector-startup-failure-total"), 0.0001d);
    assertEquals(connectStartupSuccessPct, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "connector-startup-success-percentage"), 0.0001d);
    assertEquals(connectStartupFailurePct, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "connector-startup-failure-percentage"), 0.0001d);
    assertEquals(taskStartupAttempts, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-startup-attempts-total"), 0.0001d);
    assertEquals(taskStartupSuccesses, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-startup-success-total"), 0.0001d);
    assertEquals(taskStartupFailures, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-startup-failure-total"), 0.0001d);
    assertEquals(taskStartupSuccessPct, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-startup-success-percentage"), 0.0001d);
    assertEquals(taskStartupFailurePct, MockConnectMetrics.currentMetricValueAsDouble(worker.metrics(), workerMetrics, "task-startup-failure-percentage"), 0.0001d);
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 17 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project apache-kafka-on-k8s by banzaicloud.

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.NEGATIVE_INFINITY, rebalanceTimeMax, 0.0001d);
        assertEquals(0.0d, 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 18 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project apache-kafka-on-k8s by banzaicloud.

the class ConnectMetricsTest method testGettingGroupWithTags.

@Test
public void testGettingGroupWithTags() {
    MetricGroup group1 = metrics.group("name", "k1", "v1", "k2", "v2");
    assertEquals("v1", group1.tags().get("k1"));
    assertEquals("v2", group1.tags().get("k2"));
    assertEquals(2, group1.tags().size());
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup) Test(org.junit.Test)

Example 19 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project apache-kafka-on-k8s by banzaicloud.

the class WorkerConnectorTest method assertInitializedMetric.

protected void assertInitializedMetric(WorkerConnector workerConnector) {
    assertTrue(workerConnector.metrics().isUnassigned());
    assertFalse(workerConnector.metrics().isFailed());
    assertFalse(workerConnector.metrics().isPaused());
    assertFalse(workerConnector.metrics().isRunning());
    MetricGroup metricGroup = workerConnector.metrics().metricGroup();
    String status = metrics.currentMetricValueAsString(metricGroup, "status");
    String type = metrics.currentMetricValueAsString(metricGroup, "connector-type");
    String clazz = metrics.currentMetricValueAsString(metricGroup, "connector-class");
    String version = metrics.currentMetricValueAsString(metricGroup, "connector-version");
    assertEquals(type, "unknown");
    assertNotNull(clazz);
    assertEquals(VERSION, version);
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 20 with MetricGroup

use of org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup in project apache-kafka-on-k8s by banzaicloud.

the class WorkerSinkTaskTest method sinkMetricValue.

private double sinkMetricValue(String metricName) {
    MetricGroup sinkTaskGroup = workerTask.sinkTaskMetricsGroup().metricGroup();
    double value = metrics.currentMetricValueAsDouble(sinkTaskGroup, metricName);
    System.out.println("** " + metricName + "=" + value);
    return value;
}
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