use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class StreamTaskTest method createSingleSourceStateless.
private StreamTask createSingleSourceStateless(final StreamsConfig config, final String builtInMetricsVersion) {
final ProcessorTopology topology = withSources(asList(source1, processorStreamTime, processorSystemTime), mkMap(mkEntry(topic1, source1)));
source1.addChild(processorStreamTime);
source1.addChild(processorSystemTime);
EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet());
EasyMock.expect(stateManager.changelogOffsets()).andReturn(Collections.emptyMap()).anyTimes();
EasyMock.expect(recordCollector.offsets()).andReturn(Collections.emptyMap()).anyTimes();
EasyMock.replay(stateManager, recordCollector);
final InternalProcessorContext context = new ProcessorContextImpl(taskId, config, stateManager, streamsMetrics, null);
return new StreamTask(taskId, mkSet(partition1), topology, consumer, new TopologyConfig(null, config, new Properties()).getTaskConfig(), new StreamsMetricsImpl(metrics, "test", builtInMetricsVersion, time), stateDirectory, cache, time, stateManager, recordCollector, context, logContext);
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class GlobalStreamThreadTest method before.
@Before
public void before() {
final MaterializedInternal<Object, Object, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.with(null, null), new InternalNameProvider() {
@Override
public String newProcessorName(final String prefix) {
return "processorName";
}
@Override
public String newStoreName(final String prefix) {
return GLOBAL_STORE_NAME;
}
}, "store-");
final ProcessorSupplier<Object, Object, Void, Void> processorSupplier = () -> new ContextualProcessor<Object, Object, Void, Void>() {
@Override
public void process(final Record<Object, Object> record) {
}
};
builder.addGlobalStore(new TimestampedKeyValueStoreMaterializer<>(materialized).materialize().withLoggingDisabled(), "sourceName", null, null, null, GLOBAL_STORE_TOPIC_NAME, "processorName", processorSupplier);
baseDirectoryName = TestUtils.tempDirectory().getAbsolutePath();
final HashMap<String, Object> properties = new HashMap<>();
properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "blah");
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "testAppId");
properties.put(StreamsConfig.STATE_DIR_CONFIG, baseDirectoryName);
properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
config = new StreamsConfig(properties);
globalStreamThread = new GlobalStreamThread(builder.rewriteTopology(config).buildGlobalStateTopology(), config, mockConsumer, new StateDirectory(config, time, true, false), 0, new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, time), time, "clientId", stateRestoreListener, e -> {
});
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl 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"));
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class ProcessorNodeTest method testMetricsWithBuiltInMetricsVersionLatest.
@Test
public void testMetricsWithBuiltInMetricsVersionLatest() {
final Metrics metrics = new Metrics();
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
final InternalMockProcessorContext<Object, Object> context = new InternalMockProcessorContext<>(streamsMetrics);
final ProcessorNode<Object, Object, Object, Object> node = new ProcessorNode<>("name", new NoOpProcessor(), Collections.emptySet());
node.init(context);
final String threadId = Thread.currentThread().getName();
final String[] latencyOperations = { "process", "punctuate", "create", "destroy" };
final String groupName = "stream-processor-node-metrics";
final Map<String, String> metricTags = new LinkedHashMap<>();
final String threadIdTagKey = "client-id";
metricTags.put("processor-node-id", node.name());
metricTags.put("task-id", context.taskId().toString());
metricTags.put(threadIdTagKey, threadId);
for (final String opName : latencyOperations) {
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-latency-avg", groupName, metricTags));
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-latency-max", groupName, metricTags));
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-rate", groupName, metricTags));
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-total", groupName, metricTags));
}
// test parent sensors
metricTags.put("processor-node-id", ROLLUP_VALUE);
for (final String opName : latencyOperations) {
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-latency-avg", groupName, metricTags));
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-latency-max", groupName, metricTags));
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-rate", groupName, metricTags));
assertFalse(StreamsTestUtils.containsMetric(metrics, opName + "-total", groupName, metricTags));
}
}
use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.
the class RocksDBMetricsRecorderTest method shouldThrowIfMetricRecorderIsReInitialisedWithDifferentStreamsMetrics.
@Test
public void shouldThrowIfMetricRecorderIsReInitialisedWithDifferentStreamsMetrics() {
setUpMetricsStubMock();
recorder.init(streamsMetrics, TASK_ID1);
assertThrows(IllegalStateException.class, () -> recorder.init(new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, new MockTime()), TASK_ID1));
}
Aggregations