Search in sources :

Example 6 with Value

use of org.apache.kafka.common.metrics.stats.Value in project ksql by confluentinc.

the class KsqlEngineMetrics method configureErrorRate.

private Sensor configureErrorRate(Metrics metrics) {
    Sensor sensor = createSensor(metrics, metricGroupName + "-error-rate");
    sensor.add(metrics.metricName("error-rate", this.metricGroupName, "The number of messages which were consumed but not processed. " + "Messages may not be processed if, for instance, the message " + "contents could not be deserialized due to an incompatible schema. " + "Alternately, a consumed messages may not have been produced, hence " + "being effectively dropped. Such messages would also be counted " + "toward the error rate."), new Value());
    return sensor;
}
Also used : Value(org.apache.kafka.common.metrics.stats.Value) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 7 with Value

use of org.apache.kafka.common.metrics.stats.Value in project ksql by confluentinc.

the class KsqlEngineMetrics method configureMessagesIn.

private Sensor configureMessagesIn(Metrics metrics) {
    Sensor sensor = createSensor(metrics, metricGroupName + "-messages-consumed");
    sensor.add(metrics.metricName("messages-consumed-per-sec", this.metricGroupName, "The number of messages consumed per second across all queries"), new Value());
    return sensor;
}
Also used : Value(org.apache.kafka.common.metrics.stats.Value) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 8 with Value

use of org.apache.kafka.common.metrics.stats.Value in project ksql by confluentinc.

the class KsqlEngineMetrics method configureIdleQueriesSensor.

private Sensor configureIdleQueriesSensor(Metrics metrics) {
    Sensor sensor = createSensor(metrics, "num-idle-queries");
    sensor.add(metrics.metricName("num-idle-queries", this.metricGroupName), new Value());
    return sensor;
}
Also used : Value(org.apache.kafka.common.metrics.stats.Value) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 9 with Value

use of org.apache.kafka.common.metrics.stats.Value in project kafka by apache.

the class MetricsTest method testConcurrentReadUpdateReport.

/**
 * Verifies that concurrent sensor add, remove, updates and read with a metrics reporter
 * that synchronizes on every reporter method doesn't result in errors or deadlock.
 */
@Test
public void testConcurrentReadUpdateReport() throws Exception {
    class LockingReporter implements MetricsReporter {

        Map<MetricName, KafkaMetric> activeMetrics = new HashMap<>();

        @Override
        public synchronized void init(List<KafkaMetric> metrics) {
        }

        @Override
        public synchronized void metricChange(KafkaMetric metric) {
            activeMetrics.put(metric.metricName(), metric);
        }

        @Override
        public synchronized void metricRemoval(KafkaMetric metric) {
            activeMetrics.remove(metric.metricName(), metric);
        }

        @Override
        public synchronized void close() {
        }

        @Override
        public void configure(Map<String, ?> configs) {
        }

        synchronized void processMetrics() {
            for (KafkaMetric metric : activeMetrics.values()) {
                assertNotNull(metric.metricValue(), "Invalid metric value");
            }
        }
    }
    final LockingReporter reporter = new LockingReporter();
    this.metrics.close();
    this.metrics = new Metrics(config, Arrays.asList(reporter), new MockTime(10), true);
    final Deque<Sensor> sensors = new ConcurrentLinkedDeque<>();
    SensorCreator sensorCreator = new SensorCreator(metrics);
    final Random random = new Random();
    final AtomicBoolean alive = new AtomicBoolean(true);
    executorService = Executors.newFixedThreadPool(3);
    Future<?> writeFuture = executorService.submit(new ConcurrentMetricOperation(alive, "record", () -> sensors.forEach(sensor -> sensor.record(random.nextInt(10000)))));
    Future<?> readFuture = executorService.submit(new ConcurrentMetricOperation(alive, "read", () -> sensors.forEach(sensor -> sensor.metrics().forEach(metric -> assertNotNull(metric.metricValue(), "Invalid metric value")))));
    Future<?> reportFuture = executorService.submit(new ConcurrentMetricOperation(alive, "report", reporter::processMetrics));
    for (int i = 0; i < 10000; i++) {
        if (sensors.size() > 10) {
            Sensor sensor = random.nextBoolean() ? sensors.removeFirst() : sensors.removeLast();
            metrics.removeSensor(sensor.name());
        }
        StatType statType = StatType.forId(random.nextInt(StatType.values().length));
        sensors.add(sensorCreator.createSensor(statType, i));
    }
    assertFalse(readFuture.isDone(), "Read failed");
    assertFalse(writeFuture.isDone(), "Write failed");
    assertFalse(reportFuture.isDone(), "Report failed");
    alive.set(false);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Max(org.apache.kafka.common.metrics.stats.Max) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) MockTime(org.apache.kafka.common.utils.MockTime) Rate(org.apache.kafka.common.metrics.stats.Rate) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Random(java.util.Random) Deque(java.util.Deque) Function(java.util.function.Function) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Percentile(org.apache.kafka.common.metrics.stats.Percentile) BucketSizing(org.apache.kafka.common.metrics.stats.Percentiles.BucketSizing) Map(java.util.Map) Metric(org.apache.kafka.common.Metric) MetricName(org.apache.kafka.common.MetricName) WindowedSum(org.apache.kafka.common.metrics.stats.WindowedSum) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) Value(org.apache.kafka.common.metrics.stats.Value) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) CumulativeSum(org.apache.kafka.common.metrics.stats.CumulativeSum) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) WindowedCount(org.apache.kafka.common.metrics.stats.WindowedCount) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Avg(org.apache.kafka.common.metrics.stats.Avg) Min(org.apache.kafka.common.metrics.stats.Min) SimpleRate(org.apache.kafka.common.metrics.stats.SimpleRate) Meter(org.apache.kafka.common.metrics.stats.Meter) Percentiles(org.apache.kafka.common.metrics.stats.Percentiles) Collections(java.util.Collections) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Aggregations

Value (org.apache.kafka.common.metrics.stats.Value)9 Sensor (org.apache.kafka.common.metrics.Sensor)8 Collections (java.util.Collections)2 Deque (java.util.Deque)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 Metric (org.apache.kafka.common.Metric)2 MetricName (org.apache.kafka.common.MetricName)2 Avg (org.apache.kafka.common.metrics.stats.Avg)2 CumulativeSum (org.apache.kafka.common.metrics.stats.CumulativeSum)2 Max (org.apache.kafka.common.metrics.stats.Max)2 Min (org.apache.kafka.common.metrics.stats.Min)2 Rate (org.apache.kafka.common.metrics.stats.Rate)2 WindowedCount (org.apache.kafka.common.metrics.stats.WindowedCount)2 WindowedSum (org.apache.kafka.common.metrics.stats.WindowedSum)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1