Search in sources :

Example 11 with MetricGroup

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

the class ConnectMetricsTest method addToGroup.

private Sensor addToGroup(ConnectMetrics connectMetrics, boolean shouldClose) {
    ConnectMetricsRegistry registry = connectMetrics.registry();
    ConnectMetrics.MetricGroup metricGroup = connectMetrics.group(registry.taskGroupName(), registry.connectorTagName(), "conn_name");
    if (shouldClose) {
        metricGroup.close();
    }
    Sensor sensor = metricGroup.sensor("my_sensor");
    sensor.add(metricName("x1"), new Max());
    sensor.add(metricName("y2"), new Avg());
    return sensor;
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup) Avg(org.apache.kafka.common.metrics.stats.Avg) Max(org.apache.kafka.common.metrics.stats.Max) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 12 with MetricGroup

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

the class WorkerConnectorTest method assertInitializedMetric.

protected void assertInitializedMetric(WorkerConnector workerConnector, String expectedType) {
    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(expectedType, type);
    assertNotNull(clazz);
    assertEquals(VERSION, version);
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 13 with MetricGroup

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

the class WorkerSinkTaskTest method assertSinkMetricValue.

private void assertSinkMetricValue(String name, double expected) {
    MetricGroup sinkTaskGroup = workerTask.sinkTaskMetricsGroup().metricGroup();
    double measured = metrics.currentMetricValueAsDouble(sinkTaskGroup, name);
    assertEquals(expected, measured, 0.001d);
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 14 with MetricGroup

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

the class WorkerSinkTaskTest method taskMetricValue.

private double taskMetricValue(String metricName) {
    MetricGroup taskGroup = workerTask.taskMetricsGroup().metricGroup();
    double value = metrics.currentMetricValueAsDouble(taskGroup, metricName);
    System.out.println("** " + metricName + "=" + value);
    return value;
}
Also used : MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup)

Example 15 with MetricGroup

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

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 {
        assertTrue(pollRate == 0.0d);
    }
    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 {
        assertTrue(writeRate == 0.0d);
    }
    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(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)

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