Search in sources :

Example 11 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project apache-kafka-on-k8s by banzaicloud.

the class MeteredKeyValueBytesStoreTest method shouldDeleteFromInnerStoreAndRecordDeleteMetric.

@Test
public void shouldDeleteFromInnerStoreAndRecordDeleteMetric() {
    EasyMock.expect(inner.delete(keyBytes)).andReturn(valueBytes);
    init();
    metered.delete(key);
    final KafkaMetric metric = metric("delete-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 12 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project apache-kafka-on-k8s by banzaicloud.

the class MeteredSessionStoreTest method shouldWriteBytesToInnerStoreAndRecordPutMetric.

@Test
public void shouldWriteBytesToInnerStoreAndRecordPutMetric() {
    inner.put(EasyMock.eq(windowedKeyBytes), EasyMock.aryEq(keyBytes));
    EasyMock.expectLastCall();
    init();
    metered.put(new Windowed<>(key, new SessionWindow(0, 0)), key);
    final KafkaMetric metric = metric("put-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 13 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project apache-kafka-on-k8s by banzaicloud.

the class MeteredSessionStoreTest method shouldFetchForKeyAndRecordFetchMetric.

@Test
public void shouldFetchForKeyAndRecordFetchMetric() {
    EasyMock.expect(inner.findSessions(Bytes.wrap(keyBytes), 0, Long.MAX_VALUE)).andReturn(new KeyValueIteratorStub<>(Collections.singleton(KeyValue.pair(windowedKeyBytes, keyBytes)).iterator()));
    init();
    final KeyValueIterator<Windowed<String>, String> iterator = metered.fetch(key);
    assertThat(iterator.next().value, equalTo(key));
    assertFalse(iterator.hasNext());
    iterator.close();
    final KafkaMetric metric = metric("fetch-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 14 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project apache-kafka-on-k8s by banzaicloud.

the class MeteredSessionStoreTest method shouldRemoveFromStoreAndRecordRemoveMetric.

@Test
public void shouldRemoveFromStoreAndRecordRemoveMetric() {
    inner.remove(windowedKeyBytes);
    EasyMock.expectLastCall();
    init();
    metered.remove(new Windowed<>(key, new SessionWindow(0, 0)));
    final KafkaMetric metric = metric("remove-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 15 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project apache-kafka-on-k8s by banzaicloud.

the class FetcherTest method testFetcherMetrics.

/*
     * Send multiple requests. Verify that the client side quota metrics have the right values
     */
@Test
public void testFetcherMetrics() {
    subscriptions.assignFromUser(singleton(tp0));
    subscriptions.seek(tp0, 0);
    MetricName maxLagMetric = metrics.metricInstance(metricsRegistry.recordsLagMax);
    Map<String, String> tags = new HashMap<>();
    tags.put("topic", tp0.topic());
    tags.put("partition", String.valueOf(tp0.partition()));
    MetricName partitionLagMetric = metrics.metricName("records-lag", metricGroup, tags);
    Map<MetricName, KafkaMetric> allMetrics = metrics.metrics();
    KafkaMetric recordsFetchLagMax = allMetrics.get(maxLagMetric);
    // recordsFetchLagMax should be initialized to negative infinity
    assertEquals(Double.NEGATIVE_INFINITY, recordsFetchLagMax.value(), EPSILON);
    // recordsFetchLagMax should be hw - fetchOffset after receiving an empty FetchResponse
    fetchRecords(tp0, MemoryRecords.EMPTY, Errors.NONE, 100L, 0);
    assertEquals(100, recordsFetchLagMax.value(), EPSILON);
    KafkaMetric partitionLag = allMetrics.get(partitionLagMetric);
    assertEquals(100, partitionLag.value(), EPSILON);
    // recordsFetchLagMax should be hw - offset of the last message after receiving a non-empty FetchResponse
    MemoryRecordsBuilder builder = MemoryRecords.builder(ByteBuffer.allocate(1024), CompressionType.NONE, TimestampType.CREATE_TIME, 0L);
    for (int v = 0; v < 3; v++) builder.appendWithOffset(v, RecordBatch.NO_TIMESTAMP, "key".getBytes(), ("value-" + v).getBytes());
    fetchRecords(tp0, builder.build(), Errors.NONE, 200L, 0);
    assertEquals(197, recordsFetchLagMax.value(), EPSILON);
    assertEquals(197, partitionLag.value(), EPSILON);
    // verify de-registration of partition lag
    subscriptions.unsubscribe();
    assertFalse(allMetrics.containsKey(partitionLagMetric));
}
Also used : MetricName(org.apache.kafka.common.MetricName) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MemoryRecordsBuilder(org.apache.kafka.common.record.MemoryRecordsBuilder) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Aggregations

KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)95 Test (org.junit.Test)73 MetricName (org.apache.kafka.common.MetricName)36 HashMap (java.util.HashMap)17 MemoryRecordsBuilder (org.apache.kafka.common.record.MemoryRecordsBuilder)14 LinkedHashMap (java.util.LinkedHashMap)12 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)12 Windowed (org.apache.kafka.streams.kstream.Windowed)12 Test (org.junit.jupiter.api.Test)11 TopicPartition (org.apache.kafka.common.TopicPartition)10 List (java.util.List)8 Cluster (org.apache.kafka.common.Cluster)8 Node (org.apache.kafka.common.Node)8 Sensor (org.apache.kafka.common.metrics.Sensor)8 LegacyRecord (org.apache.kafka.common.record.LegacyRecord)8 MemoryRecords (org.apache.kafka.common.record.MemoryRecords)8 Record (org.apache.kafka.common.record.Record)8 SimpleRecord (org.apache.kafka.common.record.SimpleRecord)8 Metrics (org.apache.kafka.common.metrics.Metrics)7 PartitionData (org.apache.kafka.common.requests.FetchRequest.PartitionData)7