Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class MeteredKeyValueStore<K, V>
private Sensor prefixScanSensor;
private Sensor flushSensor;
private Sensor e2eLatencySensor;
protected Sensor iteratorDurationSensor;
protected InternalProcessorContext context;
private StreamsMetricsImpl streamsMetrics;
private TaskId taskId;
Expand Down Expand Up @@ -165,6 +166,7 @@ private void registerMetrics() {
flushSensor = StateStoreMetrics.flushSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
deleteSensor = StateStoreMetrics.deleteSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
e2eLatencySensor = StateStoreMetrics.e2ELatencySensor(taskId.toString(), metricsScope, name(), streamsMetrics);
iteratorDurationSensor = StateStoreMetrics.iteratorDurationSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
StateStoreMetrics.addNumOpenIteratorsGauge(taskId.toString(), metricsScope, name(), streamsMetrics,
(config, now) -> numOpenIterators.get());
}
Expand Down Expand Up @@ -486,7 +488,9 @@ public void close() {
try {
iter.close();
} finally {
sensor.record(time.nanoseconds() - startNs);
final long duration = time.nanoseconds() - startNs;
sensor.record(duration);
iteratorDurationSensor.record(duration);
numOpenIterators.decrementAndGet();
}
}
Expand Down Expand Up @@ -532,7 +536,9 @@ public void close() {
try {
iter.close();
} finally {
sensor.record(time.nanoseconds() - startNs);
final long duration = time.nanoseconds() - startNs;
sensor.record(duration);
iteratorDurationSensor.record(duration);
numOpenIterators.decrementAndGet();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

import org.apache.kafka.common.metrics.Sensor;
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.streams.state.VersionedRecordIterator;
import org.apache.kafka.streams.state.VersionedRecord;

Expand All @@ -26,13 +29,21 @@ public class MeteredMultiVersionedKeyQueryIterator<V> implements VersionedRecord
private final VersionedRecordIterator<byte[]> iterator;
private final Function<VersionedRecord<byte[]>, VersionedRecord<V>> deserializeValue;
private final AtomicInteger numOpenIterators;
private final Sensor sensor;
private final Time time;
private final long startNs;

public MeteredMultiVersionedKeyQueryIterator(final VersionedRecordIterator<byte[]> iterator,
final Sensor sensor,
final Time time,
final Function<VersionedRecord<byte[]>, VersionedRecord<V>> deserializeValue,
final AtomicInteger numOpenIterators) {
this.iterator = iterator;
this.deserializeValue = deserializeValue;
this.numOpenIterators = numOpenIterators;
this.sensor = sensor;
this.time = time;
this.startNs = time.nanoseconds();
numOpenIterators.incrementAndGet();
}

Expand All @@ -42,6 +53,7 @@ public void close() {
try {
iterator.close();
} finally {
sensor.record(time.nanoseconds() - startNs);
numOpenIterators.decrementAndGet();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class MeteredSessionStore<K, V>
private Sensor flushSensor;
private Sensor removeSensor;
private Sensor e2eLatencySensor;
private Sensor iteratorDurationSensor;
private InternalProcessorContext<?, ?> context;
private TaskId taskId;

Expand Down Expand Up @@ -134,6 +135,7 @@ private void registerMetrics() {
flushSensor = StateStoreMetrics.flushSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
removeSensor = StateStoreMetrics.removeSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
e2eLatencySensor = StateStoreMetrics.e2ELatencySensor(taskId.toString(), metricsScope, name(), streamsMetrics);
iteratorDurationSensor = StateStoreMetrics.iteratorDurationSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
StateStoreMetrics.addNumOpenIteratorsGauge(taskId.toString(), metricsScope, name(), streamsMetrics,
(config, now) -> numOpenIterators.get());
}
Expand Down Expand Up @@ -250,6 +252,7 @@ public KeyValueIterator<Windowed<K>, V> fetch(final K key) {
return new MeteredWindowedKeyValueIterator<>(
wrapped().fetch(keyBytes(key)),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -263,6 +266,7 @@ public KeyValueIterator<Windowed<K>, V> backwardFetch(final K key) {
return new MeteredWindowedKeyValueIterator<>(
wrapped().backwardFetch(keyBytes(key)),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -277,6 +281,7 @@ public KeyValueIterator<Windowed<K>, V> fetch(final K keyFrom,
return new MeteredWindowedKeyValueIterator<>(
wrapped().fetch(keyBytes(keyFrom), keyBytes(keyTo)),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -290,6 +295,7 @@ public KeyValueIterator<Windowed<K>, V> backwardFetch(final K keyFrom,
return new MeteredWindowedKeyValueIterator<>(
wrapped().backwardFetch(keyBytes(keyFrom), keyBytes(keyTo)),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -310,6 +316,7 @@ public KeyValueIterator<Windowed<K>, V> findSessions(final K key,
earliestSessionEndTime,
latestSessionStartTime),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -330,6 +337,7 @@ public KeyValueIterator<Windowed<K>, V> backwardFindSessions(final K key,
latestSessionStartTime
),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -352,6 +360,7 @@ public KeyValueIterator<Windowed<K>, V> findSessions(final K keyFrom,
earliestSessionEndTime,
latestSessionStartTime),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -365,6 +374,7 @@ public KeyValueIterator<Windowed<K>, V> findSessions(final long earliestSessionE
return new MeteredWindowedKeyValueIterator<>(
wrapped().findSessions(earliestSessionEndTime, latestSessionEndTime),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -387,6 +397,7 @@ public KeyValueIterator<Windowed<K>, V> backwardFindSessions(final K keyFrom,
latestSessionStartTime
),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand Down Expand Up @@ -458,6 +469,7 @@ private <R> QueryResult<R> runRangeQuery(final Query<R> query,
new MeteredWindowedKeyValueIterator<>(
rawResult.getResult(),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
StoreQueryUtils.getDeserializeValue(serdes, wrapped()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ public void close() {
try {
iter.close();
} finally {
sensor.record(time.nanoseconds() - startNs);
final long duration = time.nanoseconds() - startNs;
sensor.record(duration);
iteratorDurationSensor.record(duration);
numOpenIterators.decrementAndGet();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,13 @@ private <R> QueryResult<R> runMultiVersionedKeyQuery(final Query<R> query, final
final QueryResult<VersionedRecordIterator<byte[]>> rawResult = wrapped().query(rawKeyQuery, positionBound, config);
if (rawResult.isSuccess()) {
final MeteredMultiVersionedKeyQueryIterator<V> typedResult =
new MeteredMultiVersionedKeyQueryIterator<V>(rawResult.getResult(), StoreQueryUtils.getDeserializeValue(plainValueSerdes), numOpenIterators);
new MeteredMultiVersionedKeyQueryIterator<V>(
rawResult.getResult(),
iteratorDurationSensor,
time,
StoreQueryUtils.getDeserializeValue(plainValueSerdes),
numOpenIterators
);
final QueryResult<MeteredMultiVersionedKeyQueryIterator<V>> typedQueryResult =
InternalQueryResultUtil.copyAndSubstituteDeserializedResult(rawResult, typedResult);
result = (QueryResult<R>) typedQueryResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class MeteredWindowStore<K, V>
private Sensor fetchSensor;
private Sensor flushSensor;
private Sensor e2eLatencySensor;
private Sensor iteratorDurationSensor;
private InternalProcessorContext<?, ?> context;
private TaskId taskId;

Expand Down Expand Up @@ -153,6 +154,7 @@ private void registerMetrics() {
fetchSensor = StateStoreMetrics.fetchSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
flushSensor = StateStoreMetrics.flushSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
e2eLatencySensor = StateStoreMetrics.e2ELatencySensor(taskId.toString(), metricsScope, name(), streamsMetrics);
iteratorDurationSensor = StateStoreMetrics.iteratorDurationSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
StateStoreMetrics.addNumOpenIteratorsGauge(taskId.toString(), metricsScope, name(), streamsMetrics,
(config, now) -> numOpenIterators.get());
}
Expand Down Expand Up @@ -239,6 +241,7 @@ public WindowStoreIterator<V> fetch(final K key,
return new MeteredWindowStoreIterator<>(
wrapped().fetch(keyBytes(key), timeFrom, timeTo),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::valueFrom,
time,
Expand All @@ -254,6 +257,7 @@ public WindowStoreIterator<V> backwardFetch(final K key,
return new MeteredWindowStoreIterator<>(
wrapped().backwardFetch(keyBytes(key), timeFrom, timeTo),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::valueFrom,
time,
Expand All @@ -273,6 +277,7 @@ public KeyValueIterator<Windowed<K>, V> fetch(final K keyFrom,
timeFrom,
timeTo),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -292,6 +297,7 @@ public KeyValueIterator<Windowed<K>, V> backwardFetch(final K keyFrom,
timeFrom,
timeTo),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -305,6 +311,7 @@ public KeyValueIterator<Windowed<K>, V> fetchAll(final long timeFrom,
return new MeteredWindowedKeyValueIterator<>(
wrapped().fetchAll(timeFrom, timeTo),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -318,6 +325,7 @@ public KeyValueIterator<Windowed<K>, V> backwardFetchAll(final long timeFrom,
return new MeteredWindowedKeyValueIterator<>(
wrapped().backwardFetchAll(timeFrom, timeTo),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -330,6 +338,7 @@ public KeyValueIterator<Windowed<K>, V> all() {
return new MeteredWindowedKeyValueIterator<>(
wrapped().all(),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand All @@ -343,6 +352,7 @@ public KeyValueIterator<Windowed<K>, V> backwardAll() {
return new MeteredWindowedKeyValueIterator<>(
wrapped().backwardAll(),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
serdes::valueFrom,
Expand Down Expand Up @@ -420,6 +430,7 @@ private <R> QueryResult<R> runRangeQuery(final Query<R> query,
new MeteredWindowedKeyValueIterator<>(
rawResult.getResult(),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
serdes::keyFrom,
getDeserializeValue(serdes, wrapped()),
Expand Down Expand Up @@ -471,6 +482,7 @@ private <R> QueryResult<R> runKeyQuery(final Query<R> query,
final MeteredWindowStoreIterator<V> typedResult = new MeteredWindowStoreIterator<>(
rawResult.getResult(),
fetchSensor,
iteratorDurationSensor,
streamsMetrics,
getDeserializeValue(serdes, wrapped()),
time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@
class MeteredWindowStoreIterator<V> implements WindowStoreIterator<V> {

private final WindowStoreIterator<byte[]> iter;
private final Sensor sensor;
private final Sensor operationSensor;
private final Sensor iteratorSensor;
private final StreamsMetrics metrics;
private final Function<byte[], V> valueFrom;
private final long startNs;
private final Time time;
private final AtomicInteger numOpenIterators;

MeteredWindowStoreIterator(final WindowStoreIterator<byte[]> iter,
final Sensor sensor,
final Sensor operationSensor,
final Sensor iteratorSensor,
final StreamsMetrics metrics,
final Function<byte[], V> valueFrom,
final Time time,
final AtomicInteger numOpenIterators) {
this.iter = iter;
this.sensor = sensor;
this.operationSensor = operationSensor;
this.iteratorSensor = iteratorSensor;
this.metrics = metrics;
this.valueFrom = valueFrom;
this.startNs = time.nanoseconds();
Expand All @@ -67,7 +70,9 @@ public void close() {
try {
iter.close();
} finally {
sensor.record(time.nanoseconds() - startNs);
final long duration = time.nanoseconds() - startNs;
operationSensor.record(duration);
iteratorSensor.record(duration);
numOpenIterators.decrementAndGet();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
class MeteredWindowedKeyValueIterator<K, V> implements KeyValueIterator<Windowed<K>, V> {

private final KeyValueIterator<Windowed<Bytes>, byte[]> iter;
private final Sensor sensor;
private final Sensor operationSensor;
private final Sensor iteratorSensor;
private final StreamsMetrics metrics;
private final Function<byte[], K> deserializeKey;
private final Function<byte[], V> deserializeValue;
Expand All @@ -39,14 +40,16 @@ class MeteredWindowedKeyValueIterator<K, V> implements KeyValueIterator<Windowed
private final AtomicInteger numOpenIterators;

MeteredWindowedKeyValueIterator(final KeyValueIterator<Windowed<Bytes>, byte[]> iter,
final Sensor sensor,
final Sensor operationSensor,
final Sensor iteratorSensor,
final StreamsMetrics metrics,
final Function<byte[], K> deserializeKey,
final Function<byte[], V> deserializeValue,
final Time time,
final AtomicInteger numOpenIterators) {
this.iter = iter;
this.sensor = sensor;
this.operationSensor = operationSensor;
this.iteratorSensor = iteratorSensor;
this.metrics = metrics;
this.deserializeKey = deserializeKey;
this.deserializeValue = deserializeValue;
Expand Down Expand Up @@ -77,7 +80,9 @@ public void close() {
try {
iter.close();
} finally {
sensor.record(time.nanoseconds() - startNs);
final long duration = time.nanoseconds() - startNs;
operationSensor.record(duration);
iteratorSensor.record(duration);
numOpenIterators.decrementAndGet();
}
}
Expand Down
Loading