Search in sources :

Example 1 with SensorAccessor

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

the class SourceNodeTest method shouldExposeProcessMetrics.

@Test
public void shouldExposeProcessMetrics() {
    final Metrics metrics = new Metrics();
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
    final InternalMockProcessorContext<String, String> context = new InternalMockProcessorContext<>(streamsMetrics);
    final SourceNode<String, String> node = new SourceNode<>(context.currentNode().name(), new TheDeserializer(), new TheDeserializer());
    node.init(context);
    final String threadId = Thread.currentThread().getName();
    final String groupName = "stream-processor-node-metrics";
    final Map<String, String> metricTags = mkMap(mkEntry("thread-id", threadId), mkEntry("task-id", context.taskId().toString()), mkEntry("processor-node-id", node.name()));
    assertTrue(StreamsTestUtils.containsMetric(metrics, "process-rate", groupName, metricTags));
    assertTrue(StreamsTestUtils.containsMetric(metrics, "process-total", groupName, metricTags));
    // test parent sensors
    final String parentGroupName = "stream-task-metrics";
    metricTags.remove("processor-node-id");
    assertTrue(StreamsTestUtils.containsMetric(metrics, "process-rate", parentGroupName, metricTags));
    assertTrue(StreamsTestUtils.containsMetric(metrics, "process-total", parentGroupName, metricTags));
    final String sensorNamePrefix = "internal." + threadId + ".task." + context.taskId().toString();
    final Sensor processSensor = metrics.getSensor(sensorNamePrefix + ".node." + context.currentNode().name() + ".s.process");
    final SensorAccessor sensorAccessor = new SensorAccessor(processSensor);
    assertThat(sensorAccessor.parents().stream().map(Sensor::name).collect(Collectors.toList()), contains(sensorNamePrefix + ".s.process"));
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) MockSourceNode(org.apache.kafka.test.MockSourceNode) SensorAccessor(org.apache.kafka.common.metrics.SensorAccessor) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) MockTime(org.apache.kafka.common.utils.MockTime) Sensor(org.apache.kafka.common.metrics.Sensor) Test(org.junit.Test)

Aggregations

Metrics (org.apache.kafka.common.metrics.Metrics)1 Sensor (org.apache.kafka.common.metrics.Sensor)1 SensorAccessor (org.apache.kafka.common.metrics.SensorAccessor)1 MockTime (org.apache.kafka.common.utils.MockTime)1 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)1 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)1 MockSourceNode (org.apache.kafka.test.MockSourceNode)1 Test (org.junit.Test)1