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