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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations