use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.
the class MeteredTimestampedKeyValueStoreTest method shouldPutIfAbsentAndRecordPutIfAbsentMetric.
@Test
public void shouldPutIfAbsentAndRecordPutIfAbsentMetric() {
expect(inner.putIfAbsent(eq(KEY_BYTES), aryEq(VALUE_AND_TIMESTAMP_BYTES))).andReturn(null);
init();
metered.putIfAbsent(KEY, VALUE_AND_TIMESTAMP);
final KafkaMetric metric = metric("put-if-absent-rate");
assertTrue((Double) metric.metricValue() > 0);
verify(inner);
}
use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.
the class MeteredTimestampedKeyValueStoreTest method shouldPutAllToInnerStoreAndRecordPutAllMetric.
@SuppressWarnings("unchecked")
@Test
public void shouldPutAllToInnerStoreAndRecordPutAllMetric() {
inner.putAll(anyObject(List.class));
expectLastCall();
init();
metered.putAll(Collections.singletonList(KeyValue.pair(KEY, VALUE_AND_TIMESTAMP)));
final KafkaMetric metric = metric("put-all-rate");
assertTrue((Double) metric.metricValue() > 0);
verify(inner);
}
use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.
the class StreamsMetricsImplTest method testTotalMetricDoesntDecrease.
@Test
public void testTotalMetricDoesntDecrease() {
final MockTime time = new MockTime(1);
final MetricConfig config = new MetricConfig().timeWindow(1, TimeUnit.MILLISECONDS);
final Metrics metrics = new Metrics(config, time);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "", VERSION, time);
final String scope = "scope";
final String entity = "entity";
final String operation = "op";
final Sensor sensor = streamsMetrics.addLatencyRateTotalSensor(scope, entity, operation, RecordingLevel.INFO);
final double latency = 100.0;
final MetricName totalMetricName = metrics.metricName("op-total", "stream-scope-metrics", "", "thread-id", Thread.currentThread().getName(), "scope-id", "entity");
final KafkaMetric totalMetric = metrics.metric(totalMetricName);
for (int i = 0; i < 10; i++) {
assertEquals(i, Math.round(totalMetric.measurable().measure(config, time.milliseconds())));
sensor.record(latency, time.milliseconds());
}
}
use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.
the class StreamTaskTest method verifyCloseTaskMetric.
private void verifyCloseTaskMetric(final double expected, final StreamsMetricsImpl streamsMetrics, final MetricName metricName) {
final KafkaMetric metric = (KafkaMetric) streamsMetrics.metrics().get(metricName);
final double totalCloses = metric.measurable().measure(metric.config(), System.currentTimeMillis());
assertThat(totalCloses, equalTo(expected));
}
use of org.apache.kafka.common.metrics.KafkaMetric in project kafka by apache.
the class ActiveTaskCreatorTest method shouldConstructProducerMetricsPerTask.
private void shouldConstructProducerMetricsPerTask() {
mockClientSupplier.setApplicationIdForProducer("appId");
createTasks();
final MetricName testMetricName1 = new MetricName("test_metric_1", "", "", new HashMap<>());
final Metric testMetric1 = new KafkaMetric(new Object(), testMetricName1, (Measurable) (config, now) -> 0, null, new MockTime());
mockClientSupplier.producers.get(0).setMockMetrics(testMetricName1, testMetric1);
final MetricName testMetricName2 = new MetricName("test_metric_2", "", "", new HashMap<>());
final Metric testMetric2 = new KafkaMetric(new Object(), testMetricName2, (Measurable) (config, now) -> 0, null, new MockTime());
mockClientSupplier.producers.get(0).setMockMetrics(testMetricName2, testMetric2);
final Map<MetricName, Metric> producerMetrics = activeTaskCreator.producerMetrics();
assertThat(producerMetrics, is(mkMap(mkEntry(testMetricName1, testMetric1), mkEntry(testMetricName2, testMetric2))));
}
Aggregations