Search in sources :

Example 91 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredKeyValueStoreTest method shouldDeleteFromInnerStoreAndRecordDeleteMetric.

@Test
public void shouldDeleteFromInnerStoreAndRecordDeleteMetric() {
    expect(inner.delete(KEY_BYTES)).andReturn(VALUE_BYTES);
    init();
    metered.delete(KEY);
    final KafkaMetric metric = metric("delete-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 92 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredKeyValueStoreTest method shouldRecordRestoreLatencyOnInit.

@Test
public void shouldRecordRestoreLatencyOnInit() {
    inner.init((StateStoreContext) context, metered);
    init();
    // it suffices to verify one restore metric since all restore metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("restore-rate");
    assertThat((Double) metric.metricValue(), greaterThan(0.0));
    verify(inner);
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 93 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredSessionStoreTest method shouldFindSessionRangeFromStoreAndRecordFetchMetric.

@Test
public void shouldFindSessionRangeFromStoreAndRecordFetchMetric() {
    expect(innerStore.findSessions(KEY_BYTES, KEY_BYTES, 0, 0)).andReturn(new KeyValueIteratorStub<>(Collections.singleton(KeyValue.pair(WINDOWED_KEY_BYTES, VALUE_BYTES)).iterator()));
    init();
    final KeyValueIterator<Windowed<String>, String> iterator = store.findSessions(KEY, KEY, 0, 0);
    assertThat(iterator.next().value, equalTo(VALUE));
    assertFalse(iterator.hasNext());
    iterator.close();
    // it suffices to verify one fetch metric since all put metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(innerStore);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 94 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredSessionStoreTest method shouldBackwardFetchRangeFromStoreAndRecordFetchMetric.

@Test
public void shouldBackwardFetchRangeFromStoreAndRecordFetchMetric() {
    expect(innerStore.backwardFetch(KEY_BYTES, KEY_BYTES)).andReturn(new KeyValueIteratorStub<>(Collections.singleton(KeyValue.pair(WINDOWED_KEY_BYTES, VALUE_BYTES)).iterator()));
    init();
    final KeyValueIterator<Windowed<String>, String> iterator = store.backwardFetch(KEY, KEY);
    assertThat(iterator.next().value, equalTo(VALUE));
    assertFalse(iterator.hasNext());
    iterator.close();
    // it suffices to verify one fetch metric since all fetch metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(innerStore);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 95 with KafkaMetric

use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.

the class MeteredSessionStoreTest method shouldFindSessionsFromStoreAndRecordFetchMetric.

@Test
public void shouldFindSessionsFromStoreAndRecordFetchMetric() {
    expect(innerStore.findSessions(KEY_BYTES, 0, 0)).andReturn(new KeyValueIteratorStub<>(Collections.singleton(KeyValue.pair(WINDOWED_KEY_BYTES, VALUE_BYTES)).iterator()));
    init();
    final KeyValueIterator<Windowed<String>, String> iterator = store.findSessions(KEY, 0, 0);
    assertThat(iterator.next().value, equalTo(VALUE));
    assertFalse(iterator.hasNext());
    iterator.close();
    // it suffices to verify one fetch metric since all put metrics are recorded by the same sensor
    // and the sensor is tested elsewhere
    final KafkaMetric metric = metric("fetch-rate");
    assertTrue((Double) metric.metricValue() > 0);
    verify(innerStore);
}
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