Search in sources :

Example 16 with StreamsMetricsImpl

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);
}
Also used : Utils.mkProperties(org.apache.kafka.common.utils.Utils.mkProperties) Properties(java.util.Properties) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig)

Example 17 with StreamsMetricsImpl

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 -> {
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) StreamsConfig(org.apache.kafka.streams.StreamsConfig) MockTime(org.apache.kafka.common.utils.MockTime) InternalNameProvider(org.apache.kafka.streams.kstream.internals.InternalNameProvider) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) HashMap(java.util.HashMap) StreamsException(org.apache.kafka.streams.errors.StreamsException) OffsetResetStrategy(org.apache.kafka.clients.consumer.OffsetResetStrategy) DEAD(org.apache.kafka.streams.processor.internals.GlobalStreamThread.State.DEAD) ContextualProcessor(org.apache.kafka.streams.processor.api.ContextualProcessor) ProcessorSupplier(org.apache.kafka.streams.processor.api.ProcessorSupplier) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) Serdes(org.apache.kafka.common.serialization.Serdes) Record(org.apache.kafka.streams.processor.api.Record) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) TopicPartition(org.apache.kafka.common.TopicPartition) RUNNING(org.apache.kafka.streams.processor.internals.GlobalStreamThread.State.RUNNING) MockStateRestoreListener(org.apache.kafka.test.MockStateRestoreListener) TestUtils(org.apache.kafka.test.TestUtils) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) PartitionInfo(org.apache.kafka.common.PartitionInfo) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) File(java.io.File) Bytes(org.apache.kafka.common.utils.Bytes) ConsumerRecordUtil.record(org.apache.kafka.streams.processor.internals.testutil.ConsumerRecordUtil.record) List(java.util.List) Metrics(org.apache.kafka.common.metrics.Metrics) TimestampedKeyValueStoreMaterializer(org.apache.kafka.streams.kstream.internals.TimestampedKeyValueStoreMaterializer) StateStore(org.apache.kafka.streams.processor.StateStore) Assert.assertFalse(org.junit.Assert.assertFalse) Materialized(org.apache.kafka.streams.kstream.Materialized) InvalidOffsetException(org.apache.kafka.clients.consumer.InvalidOffsetException) Node(org.apache.kafka.common.Node) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) InternalNameProvider(org.apache.kafka.streams.kstream.internals.InternalNameProvider) Metrics(org.apache.kafka.common.metrics.Metrics) Record(org.apache.kafka.streams.processor.api.Record) ContextualProcessor(org.apache.kafka.streams.processor.api.ContextualProcessor) MaterializedInternal(org.apache.kafka.streams.kstream.internals.MaterializedInternal) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Before(org.junit.Before)

Example 18 with StreamsMetricsImpl

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

Example 19 with StreamsMetricsImpl

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));
    }
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LinkedHashMap(java.util.LinkedHashMap) Metrics(org.apache.kafka.common.metrics.Metrics) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.Test)

Example 20 with StreamsMetricsImpl

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));
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) MockTime(org.apache.kafka.common.utils.MockTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)54 Test (org.junit.Test)31 Metrics (org.apache.kafka.common.metrics.Metrics)22 MockTime (org.apache.kafka.common.utils.MockTime)22 LogContext (org.apache.kafka.common.utils.LogContext)18 StreamsConfig (org.apache.kafka.streams.StreamsConfig)18 TaskId (org.apache.kafka.streams.processor.TaskId)16 ConsumerGroupMetadata (org.apache.kafka.clients.consumer.ConsumerGroupMetadata)14 Properties (java.util.Properties)12 Before (org.junit.Before)11 File (java.io.File)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 LinkedList (java.util.LinkedList)8 Set (java.util.Set)8 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 MockStateRestoreListener (org.apache.kafka.test.MockStateRestoreListener)8 HashMap (java.util.HashMap)7 KeyValue (org.apache.kafka.streams.KeyValue)7