Search in sources :

Example 21 with StreamsMetricsImpl

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

the class RocksDBMetricsRecorderGaugesTest method runAndVerifyBlockCacheMetricsWithSingleCache.

private void runAndVerifyBlockCacheMetricsWithSingleCache(final String propertyName) throws Exception {
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
    final RocksDBMetricsRecorder recorder = new RocksDBMetricsRecorder(METRICS_SCOPE, STORE_NAME);
    recorder.init(streamsMetrics, TASK_ID);
    recorder.addValueProviders(SEGMENT_STORE_NAME_1, dbToAdd1, cacheToAdd1, statisticsToAdd1);
    recorder.addValueProviders(SEGMENT_STORE_NAME_2, dbToAdd2, cacheToAdd1, statisticsToAdd2);
    final long recordedValue = 5L;
    expect(dbToAdd1.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue);
    expect(dbToAdd2.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue);
    replay(dbToAdd1, dbToAdd2);
    verifyMetrics(streamsMetrics, propertyName, recordedValue);
}
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)

Example 22 with StreamsMetricsImpl

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

the class RocksDBMetricsRecorderGaugesTest method runAndVerifySumOfProperties.

private void runAndVerifySumOfProperties(final String propertyName) throws Exception {
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
    final RocksDBMetricsRecorder recorder = new RocksDBMetricsRecorder(METRICS_SCOPE, STORE_NAME);
    recorder.init(streamsMetrics, TASK_ID);
    recorder.addValueProviders(SEGMENT_STORE_NAME_1, dbToAdd1, cacheToAdd1, statisticsToAdd1);
    recorder.addValueProviders(SEGMENT_STORE_NAME_2, dbToAdd2, cacheToAdd2, statisticsToAdd2);
    final long recordedValue1 = 5L;
    final long recordedValue2 = 3L;
    expect(dbToAdd1.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue1);
    expect(dbToAdd2.getAggregatedLongProperty(ROCKSDB_PROPERTIES_PREFIX + propertyName)).andStubReturn(recordedValue2);
    replay(dbToAdd1, dbToAdd2);
    verifyMetrics(streamsMetrics, propertyName, recordedValue1 + recordedValue2);
}
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)

Example 23 with StreamsMetricsImpl

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

the class AbstractRocksDBSegmentedBytesStoreTest method shouldRestoreRecordsAndConsistencyVectorMultipleTopics.

@Test
public void shouldRestoreRecordsAndConsistencyVectorMultipleTopics() {
    final Properties props = StreamsTestUtils.getStreamsConfig();
    props.put(InternalConfig.IQ_CONSISTENCY_OFFSET_VECTOR_ENABLED, true);
    final File dir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext<>(dir, Serdes.String(), Serdes.String(), new StreamsMetricsImpl(new Metrics(), "mock", StreamsConfig.METRICS_LATEST, new MockTime()), new StreamsConfig(props), MockRecordCollector::new, new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())), Time.SYSTEM);
    bytesStore = getBytesStore();
    bytesStore.init((StateStoreContext) context, bytesStore);
    // 0 segments initially.
    assertEquals(0, bytesStore.getSegments().size());
    bytesStore.restoreAllInternal(getChangelogRecordsMultipleTopics());
    // 2 segments are created during restoration.
    assertEquals(2, bytesStore.getSegments().size());
    final String key = "a";
    final List<KeyValue<Windowed<String>, Long>> expected = new ArrayList<>();
    expected.add(new KeyValue<>(new Windowed<>(key, windows[0]), 50L));
    expected.add(new KeyValue<>(new Windowed<>(key, windows[2]), 100L));
    expected.add(new KeyValue<>(new Windowed<>(key, windows[3]), 200L));
    final List<KeyValue<Windowed<String>, Long>> results = toList(bytesStore.all());
    assertEquals(expected, results);
    assertThat(bytesStore.getPosition(), Matchers.notNullValue());
    assertThat(bytesStore.getPosition().getPartitionPositions("A"), Matchers.notNullValue());
    assertThat(bytesStore.getPosition().getPartitionPositions("A"), hasEntry(0, 3L));
    assertThat(bytesStore.getPosition().getPartitionPositions("B"), Matchers.notNullValue());
    assertThat(bytesStore.getPosition().getPartitionPositions("B"), hasEntry(0, 2L));
}
Also used : KeyValue(org.apache.kafka.streams.KeyValue) ArrayList(java.util.ArrayList) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Properties(java.util.Properties) Windowed(org.apache.kafka.streams.kstream.Windowed) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) File(java.io.File) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 24 with StreamsMetricsImpl

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

the class GlobalStateStoreProviderTest method before.

@Before
public void before() {
    stores.put("kv-store", Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore("kv-store"), Serdes.String(), Serdes.String()).build());
    stores.put("ts-kv-store", Stores.timestampedKeyValueStoreBuilder(Stores.inMemoryKeyValueStore("ts-kv-store"), Serdes.String(), Serdes.String()).build());
    stores.put("w-store", Stores.windowStoreBuilder(Stores.inMemoryWindowStore("w-store", Duration.ofMillis(10L), Duration.ofMillis(2L), false), Serdes.String(), Serdes.String()).build());
    stores.put("ts-w-store", Stores.timestampedWindowStoreBuilder(Stores.inMemoryWindowStore("ts-w-store", Duration.ofMillis(10L), Duration.ofMillis(2L), false), Serdes.String(), Serdes.String()).build());
    stores.put("s-store", Stores.sessionStoreBuilder(Stores.inMemorySessionStore("s-store", Duration.ofMillis(10L)), Serdes.String(), Serdes.String()).build());
    final ProcessorContextImpl mockContext = niceMock(ProcessorContextImpl.class);
    expect(mockContext.applicationId()).andStubReturn("appId");
    expect(mockContext.metrics()).andStubReturn(new StreamsMetricsImpl(new Metrics(), "threadName", StreamsConfig.METRICS_LATEST, new MockTime()));
    expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
    expect(mockContext.recordCollector()).andStubReturn(null);
    expect(mockContext.appConfigs()).andStubReturn(CONFIGS);
    expectSerdes(mockContext);
    replay(mockContext);
    for (final StateStore store : stores.values()) {
        store.init((StateStoreContext) mockContext, null);
    }
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) TaskId(org.apache.kafka.streams.processor.TaskId) StateStore(org.apache.kafka.streams.processor.StateStore) ProcessorContextImpl(org.apache.kafka.streams.processor.internals.ProcessorContextImpl) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 25 with StreamsMetricsImpl

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

the class AbstractRocksDBSegmentedBytesStoreTest method shouldNotThrowWhenRestoringOnMissingHeaders.

@Test
public void shouldNotThrowWhenRestoringOnMissingHeaders() {
    final Properties props = StreamsTestUtils.getStreamsConfig();
    props.put(InternalConfig.IQ_CONSISTENCY_OFFSET_VECTOR_ENABLED, true);
    final File dir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext<>(dir, Serdes.String(), Serdes.String(), new StreamsMetricsImpl(new Metrics(), "mock", StreamsConfig.METRICS_LATEST, new MockTime()), new StreamsConfig(props), MockRecordCollector::new, new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())), Time.SYSTEM);
    bytesStore = getBytesStore();
    bytesStore.init((StateStoreContext) context, bytesStore);
    bytesStore.restoreAllInternal(getChangelogRecordsWithoutHeaders());
    assertThat(bytesStore.getPosition(), is(Position.emptyPosition()));
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Properties(java.util.Properties) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) File(java.io.File) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig) 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