Search in sources :

Example 71 with KafkaMetric

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

the class MeteredKeyValueBytesStoreTest method shouldPutIfAbsentAndRecordPutIfAbsentMetric.

@Test
public void shouldPutIfAbsentAndRecordPutIfAbsentMetric() {
    EasyMock.expect(inner.putIfAbsent(EasyMock.eq(keyBytes), EasyMock.aryEq(valueBytes))).andReturn(null);
    init();
    metered.putIfAbsent(key, value);
    final KafkaMetric metric = metric("put-if-absent-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 72 with KafkaMetric

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

the class MeteredKeyValueBytesStoreTest method shouldGetAllFromInnerStoreAndRecordAllMetric.

@Test
public void shouldGetAllFromInnerStoreAndRecordAllMetric() {
    EasyMock.expect(inner.all()).andReturn(new KeyValueIteratorStub<>(Collections.singletonList(KeyValue.pair(keyBytes, valueBytes)).iterator()));
    init();
    final KeyValueIterator<String, String> iterator = metered.all();
    assertThat(iterator.next().value, equalTo(value));
    assertFalse(iterator.hasNext());
    iterator.close();
    final KafkaMetric metric = metric(new MetricName("all-rate", "stream-scope-metrics", "", tags));
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : MetricName(org.apache.kafka.common.MetricName) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 73 with KafkaMetric

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

the class MeteredSessionStoreTest method shouldRecordRestoreTimeOnInit.

@Test
public void shouldRecordRestoreTimeOnInit() {
    init();
    final KafkaMetric metric = metric("restore-rate");
    assertTrue(metric.value() > 0);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 74 with KafkaMetric

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

the class MeteredSessionStoreTest method shouldFindSessionsFromStoreAndRecordFetchMetric.

@Test
public void shouldFindSessionsFromStoreAndRecordFetchMetric() {
    EasyMock.expect(inner.findSessions(Bytes.wrap(keyBytes), 0, 0)).andReturn(new KeyValueIteratorStub<>(Collections.singleton(KeyValue.pair(windowedKeyBytes, keyBytes)).iterator()));
    init();
    final KeyValueIterator<Windowed<String>, String> iterator = metered.findSessions(key, 0, 0);
    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 75 with KafkaMetric

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

the class MeteredSessionStoreTest method shouldFetchRangeFromStoreAndRecordFetchMetric.

@Test
public void shouldFetchRangeFromStoreAndRecordFetchMetric() {
    EasyMock.expect(inner.findSessions(Bytes.wrap(keyBytes), 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, 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)

Aggregations

KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)128 Test (org.junit.Test)84 MetricName (org.apache.kafka.common.MetricName)59 HashMap (java.util.HashMap)29 LinkedHashMap (java.util.LinkedHashMap)24 Test (org.junit.jupiter.api.Test)23 Map (java.util.Map)17 MetricConfig (org.apache.kafka.common.metrics.MetricConfig)16 Metric (org.apache.kafka.common.Metric)15 MemoryRecordsBuilder (org.apache.kafka.common.record.MemoryRecordsBuilder)14 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)13 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)12 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)12 Value (org.apache.kafka.common.metrics.stats.Value)12 Windowed (org.apache.kafka.streams.kstream.Windowed)12 Sensor (org.apache.kafka.common.metrics.Sensor)11 TopicPartition (org.apache.kafka.common.TopicPartition)10 Metrics (org.apache.kafka.common.metrics.Metrics)10 List (java.util.List)8 Cluster (org.apache.kafka.common.Cluster)8