Search in sources :

Example 51 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class RocksDBStoreTest method shouldVerifyThatPropertyBasedMetricsUseValidPropertyName.

@Test
public void shouldVerifyThatPropertyBasedMetricsUseValidPropertyName() {
    final TaskId taskId = new TaskId(0, 0);
    final Metrics metrics = new Metrics(new MetricConfig().recordLevel(RecordingLevel.INFO));
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-application", StreamsConfig.METRICS_LATEST, time);
    final Properties props = StreamsTestUtils.getStreamsConfig();
    context = EasyMock.niceMock(InternalMockProcessorContext.class);
    EasyMock.expect(context.metrics()).andStubReturn(streamsMetrics);
    EasyMock.expect(context.taskId()).andStubReturn(taskId);
    EasyMock.expect(context.appConfigs()).andStubReturn(new StreamsConfig(props).originals());
    EasyMock.expect(context.stateDir()).andStubReturn(dir);
    EasyMock.replay(context);
    rocksDBStore.init((StateStoreContext) context, rocksDBStore);
    final List<String> propertyNames = Arrays.asList("num-entries-active-mem-table", "num-deletes-active-mem-table", "num-entries-imm-mem-tables", "num-deletes-imm-mem-tables", "num-immutable-mem-table", "cur-size-active-mem-table", "cur-size-all-mem-tables", "size-all-mem-tables", "mem-table-flush-pending", "num-running-flushes", "compaction-pending", "num-running-compactions", "estimate-pending-compaction-bytes", "total-sst-files-size", "live-sst-files-size", "num-live-versions", "block-cache-capacity", "block-cache-usage", "block-cache-pinned-usage", "estimate-num-keys", "estimate-table-readers-mem", "background-errors");
    for (final String propertyname : propertyNames) {
        final Metric metric = metrics.metric(new MetricName(propertyname, StreamsMetricsImpl.STATE_STORE_LEVEL_GROUP, "description is not verified", streamsMetrics.storeLevelTagMap(taskId.toString(), METRICS_SCOPE, DB_NAME)));
        assertThat("Metric " + propertyname + " not found!", metric, notNullValue());
        metric.metricValue();
    }
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) TaskId(org.apache.kafka.streams.processor.TaskId) Metric(org.apache.kafka.common.Metric) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) Properties(java.util.Properties) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 52 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class RocksDBStoreTest method shouldVerifyThatMetricsRecordedFromStatisticsGetMeasurementsFromRocksDB.

@Test
public void shouldVerifyThatMetricsRecordedFromStatisticsGetMeasurementsFromRocksDB() {
    final TaskId taskId = new TaskId(0, 0);
    final Metrics metrics = new Metrics(new MetricConfig().recordLevel(RecordingLevel.DEBUG));
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-application", StreamsConfig.METRICS_LATEST, time);
    context = EasyMock.niceMock(InternalMockProcessorContext.class);
    EasyMock.expect(context.metrics()).andStubReturn(streamsMetrics);
    EasyMock.expect(context.taskId()).andStubReturn(taskId);
    EasyMock.expect(context.appConfigs()).andStubReturn(new StreamsConfig(StreamsTestUtils.getStreamsConfig()).originals());
    EasyMock.expect(context.stateDir()).andStubReturn(dir);
    final MonotonicProcessorRecordContext processorRecordContext = new MonotonicProcessorRecordContext("test", 0);
    EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.of(processorRecordContext));
    EasyMock.replay(context);
    rocksDBStore.init((StateStoreContext) context, rocksDBStore);
    final byte[] key = "hello".getBytes();
    final byte[] value = "world".getBytes();
    rocksDBStore.put(Bytes.wrap(key), value);
    streamsMetrics.rocksDBMetricsRecordingTrigger().run();
    final Metric bytesWrittenTotal = metrics.metric(new MetricName("bytes-written-total", StreamsMetricsImpl.STATE_STORE_LEVEL_GROUP, "description is not verified", streamsMetrics.storeLevelTagMap(taskId.toString(), METRICS_SCOPE, DB_NAME)));
    assertThat((double) bytesWrittenTotal.metricValue(), greaterThan(0d));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) TaskId(org.apache.kafka.streams.processor.TaskId) Metric(org.apache.kafka.common.Metric) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 53 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class RocksDBStoreTest method shouldVerifyThatMetricsRecordedFromPropertiesGetMeasurementsFromRocksDB.

@Test
public void shouldVerifyThatMetricsRecordedFromPropertiesGetMeasurementsFromRocksDB() {
    final TaskId taskId = new TaskId(0, 0);
    final Metrics metrics = new Metrics(new MetricConfig().recordLevel(RecordingLevel.INFO));
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-application", StreamsConfig.METRICS_LATEST, time);
    context = EasyMock.niceMock(InternalMockProcessorContext.class);
    EasyMock.expect(context.metrics()).andStubReturn(streamsMetrics);
    EasyMock.expect(context.taskId()).andStubReturn(taskId);
    EasyMock.expect(context.appConfigs()).andStubReturn(new StreamsConfig(StreamsTestUtils.getStreamsConfig()).originals());
    EasyMock.expect(context.stateDir()).andStubReturn(dir);
    final MonotonicProcessorRecordContext processorRecordContext = new MonotonicProcessorRecordContext("test", 0);
    EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.of(processorRecordContext));
    EasyMock.replay(context);
    rocksDBStore.init((StateStoreContext) context, rocksDBStore);
    final byte[] key = "hello".getBytes();
    final byte[] value = "world".getBytes();
    rocksDBStore.put(Bytes.wrap(key), value);
    final Metric numberOfEntriesActiveMemTable = metrics.metric(new MetricName("num-entries-active-mem-table", StreamsMetricsImpl.STATE_STORE_LEVEL_GROUP, "description is not verified", streamsMetrics.storeLevelTagMap(taskId.toString(), METRICS_SCOPE, DB_NAME)));
    assertThat(numberOfEntriesActiveMemTable, notNullValue());
    assertThat((BigInteger) numberOfEntriesActiveMemTable.metricValue(), greaterThan(BigInteger.valueOf(0)));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) TaskId(org.apache.kafka.streams.processor.TaskId) Metric(org.apache.kafka.common.Metric) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 54 with StreamsMetricsImpl

use of org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl in project kafka by apache.

the class StreamThreadStateStoreProviderTest method createStreamsTask.

private StreamTask createStreamsTask(final StreamsConfig streamsConfig, final MockClientSupplier clientSupplier, final ProcessorTopology topology, final TaskId taskId) {
    final Metrics metrics = new Metrics();
    final LogContext logContext = new LogContext("test-stream-task ");
    final Set<TopicPartition> partitions = Collections.singleton(new TopicPartition(topicName, taskId.partition()));
    final ProcessorStateManager stateManager = new ProcessorStateManager(taskId, Task.TaskType.ACTIVE, StreamsConfigUtils.eosEnabled(streamsConfig), logContext, stateDirectory, new StoreChangelogReader(new MockTime(), streamsConfig, logContext, clientSupplier.adminClient, clientSupplier.restoreConsumer, new MockStateRestoreListener()), topology.storeToChangelogTopic(), partitions);
    final RecordCollector recordCollector = new RecordCollectorImpl(logContext, taskId, new StreamsProducer(streamsConfig, "threadId", clientSupplier, new TaskId(0, 0), UUID.randomUUID(), logContext, Time.SYSTEM), streamsConfig.defaultProductionExceptionHandler(), new MockStreamsMetrics(metrics));
    final StreamsMetricsImpl streamsMetrics = new MockStreamsMetrics(metrics);
    final InternalProcessorContext context = new ProcessorContextImpl(taskId, streamsConfig, stateManager, streamsMetrics, null);
    return new StreamTask(taskId, partitions, topology, clientSupplier.consumer, new TopologyConfig(null, streamsConfig, new Properties()).getTaskConfig(), streamsMetrics, stateDirectory, EasyMock.createNiceMock(ThreadCache.class), new MockTime(), stateManager, recordCollector, context, logContext);
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) RecordCollector(org.apache.kafka.streams.processor.internals.RecordCollector) StreamsProducer(org.apache.kafka.streams.processor.internals.StreamsProducer) InternalProcessorContext(org.apache.kafka.streams.processor.internals.InternalProcessorContext) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockStateRestoreListener(org.apache.kafka.test.MockStateRestoreListener) ProcessorContextImpl(org.apache.kafka.streams.processor.internals.ProcessorContextImpl) Properties(java.util.Properties) RecordCollectorImpl(org.apache.kafka.streams.processor.internals.RecordCollectorImpl) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) StoreChangelogReader(org.apache.kafka.streams.processor.internals.StoreChangelogReader) ProcessorStateManager(org.apache.kafka.streams.processor.internals.ProcessorStateManager) MockTime(org.apache.kafka.common.utils.MockTime) StreamTask(org.apache.kafka.streams.processor.internals.StreamTask) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig)

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