-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-19398: (De)Register oldest-iterator-open-since-ms metric dynamically #20022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.streams.internals.metrics; | ||
|
|
||
| import org.apache.kafka.common.MetricName; | ||
| import org.apache.kafka.streams.processor.TaskId; | ||
| import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl; | ||
| import org.apache.kafka.streams.state.internals.MeteredIterator; | ||
| import org.apache.kafka.streams.state.internals.metrics.StateStoreMetrics; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.NavigableSet; | ||
| import java.util.concurrent.ConcurrentSkipListSet; | ||
| import java.util.concurrent.atomic.LongAdder; | ||
|
|
||
| public class OpenIterators { | ||
| private final TaskId taskId; | ||
| private final String metricsScope; | ||
| private final String name; | ||
| private final StreamsMetricsImpl streamsMetrics; | ||
|
|
||
| private final LongAdder numOpenIterators = new LongAdder(); | ||
| private final NavigableSet<MeteredIterator> openIterators = new ConcurrentSkipListSet<>(Comparator.comparingLong(MeteredIterator::startTimestamp)); | ||
|
|
||
| private MetricName metricName; | ||
|
|
||
| public OpenIterators(final TaskId taskId, | ||
| final String metricsScope, | ||
| final String name, | ||
| final StreamsMetricsImpl streamsMetrics) { | ||
| this.taskId = taskId; | ||
| this.metricsScope = metricsScope; | ||
| this.name = name; | ||
| this.streamsMetrics = streamsMetrics; | ||
| } | ||
|
|
||
| public void add(final MeteredIterator iterator) { | ||
| openIterators.add(iterator); | ||
| numOpenIterators.increment(); | ||
|
|
||
| if (numOpenIterators.intValue() == 1) { | ||
| metricName = StateStoreMetrics.addOldestOpenIteratorGauge(taskId.toString(), metricsScope, name, streamsMetrics, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answer to your question: we need to remember the |
||
| (config, now) -> openIterators.first().startTimestamp() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| public void remove(final MeteredIterator iterator) { | ||
| if (numOpenIterators.intValue() == 1) { | ||
| streamsMetrics.removeMetric(metricName); | ||
| } | ||
| numOpenIterators.decrement(); | ||
| openIterators.remove(iterator); | ||
| } | ||
|
|
||
| public long sum() { | ||
| return numOpenIterators.sum(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,6 +335,10 @@ public final void removeAllThreadLevelMetrics(final String threadId) { | |
| } | ||
| } | ||
|
|
||
| public void removeMetric(final MetricName metricName) { | ||
| metrics.removeMetric(metricName); | ||
| } | ||
|
|
||
| public Map<String, String> taskLevelTagMap(final String threadId, final String taskId) { | ||
| final Map<String, String> tagMap = new LinkedHashMap<>(); | ||
| tagMap.put(THREAD_ID_TAG, threadId); | ||
|
|
@@ -517,13 +521,13 @@ public final Sensor storeLevelSensor(final String taskId, | |
| return getSensors(storeLevelSensors, sensorSuffix, sensorPrefix, recordingLevel, parents); | ||
| } | ||
|
|
||
| public <T> void addStoreLevelMutableMetric(final String taskId, | ||
| final String metricsScope, | ||
| final String storeName, | ||
| final String name, | ||
| final String description, | ||
| final RecordingLevel recordingLevel, | ||
| final Gauge<T> valueProvider) { | ||
| public <T> MetricName addStoreLevelMutableMetric(final String taskId, | ||
| final String metricsScope, | ||
| final String storeName, | ||
| final String name, | ||
| final String description, | ||
| final RecordingLevel recordingLevel, | ||
| final Gauge<T> valueProvider) { | ||
| final MetricName metricName = metrics.metricName( | ||
| name, | ||
| STATE_STORE_LEVEL_GROUP, | ||
|
|
@@ -535,6 +539,8 @@ public <T> void addStoreLevelMutableMetric(final String taskId, | |
| final String key = storeSensorPrefix(Thread.currentThread().getName(), taskId, storeName); | ||
| storeLevelMetrics.computeIfAbsent(key, ignored -> new LinkedList<>()).push(metricName); | ||
| } | ||
|
|
||
| return metricName; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the |
||
| } | ||
|
|
||
| public final void removeAllStoreLevelSensorsAndMetrics(final String taskId, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| */ | ||
| package org.apache.kafka.streams.state.internals.metrics; | ||
|
|
||
| import org.apache.kafka.common.MetricName; | ||
| import org.apache.kafka.common.metrics.Gauge; | ||
| import org.apache.kafka.common.metrics.Sensor; | ||
| import org.apache.kafka.common.metrics.Sensor.RecordingLevel; | ||
|
|
@@ -455,12 +456,12 @@ public static void addNumOpenIteratorsGauge(final String taskId, | |
|
|
||
| } | ||
|
|
||
| public static void addOldestOpenIteratorGauge(final String taskId, | ||
| final String storeType, | ||
| final String storeName, | ||
| final StreamsMetricsImpl streamsMetrics, | ||
| final Gauge<Long> oldestOpenIteratorGauge) { | ||
| streamsMetrics.addStoreLevelMutableMetric( | ||
| public static MetricName addOldestOpenIteratorGauge(final String taskId, | ||
| final String storeType, | ||
| final String storeName, | ||
| final StreamsMetricsImpl streamsMetrics, | ||
| final Gauge<Long> oldestOpenIteratorGauge) { | ||
| return streamsMetrics.addStoreLevelMutableMetric( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer :) |
||
| taskId, | ||
| storeType, | ||
| storeName, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
openIterators.size()?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this has historic reasons -- I just "refactored" existing code.
KIP-989 introduced 4 new metrics which got added by 4 PRs.
numOpenIterators-> KAFKA-15541: Add num-open-iterators metric #15975openIterators-> KAFKA-15541: Add oldest-iterator-open-since-ms metric #16041(omitting the other two PRs as they are irrelevant)
There was also a follow up PR fro
numOpenIterators: #16076@nicktelford do you see any reason why we need both variables, or can we unify them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess we can also do this unification only in
trunkto get this into4.1on time?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain, but it's possible the
LongAdderandSetduplicating the counting functionality is just an oversight. In theory, using theLongAdderwould yield improved performance vs.openIterators.size(), however, in practice the total number of open iterators is not likely to be large enough to be a problem, so it seems reasonable to removenumOpenIterators.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you interested to do a PR for this @nicktelford? If not, happy to do one myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did a quick PR for it: #20060