suneet-s commented on code in PR #15025:
URL: https://github.com/apache/druid/pull/15025#discussion_r1337918871
##########
processing/src/main/java/org/apache/druid/collections/DefaultBlockingPool.java:
##########
@@ -48,6 +49,9 @@ public class DefaultBlockingPool<T> implements BlockingPool<T>
private final Condition notEnough;
private final int maxSize;
+ private final AtomicLong pendingQueries;
+
+
Review Comment:
```suggestion
```
##########
processing/src/main/java/org/apache/druid/collections/DefaultBlockingPool.java:
##########
@@ -62,6 +66,8 @@ public DefaultBlockingPool(
this.lock = new ReentrantLock();
this.notEnough = lock.newCondition();
+
Review Comment:
```suggestion
```
##########
processing/src/main/java/org/apache/druid/java/util/metrics/MergeBufferPoolMonitor.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.druid.java.util.metrics;
+
+import com.google.inject.Inject;
+import org.apache.druid.collections.BlockingPool;
+import org.apache.druid.guice.annotations.Merging;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+
+import java.nio.ByteBuffer;
+
+public class MergeBufferPoolMonitor extends AbstractMonitor
+{
+
+ private final BlockingPool<ByteBuffer> mergeBufferPool;
+
+ @Inject
+ public MergeBufferPoolMonitor(
+ @Merging BlockingPool<ByteBuffer> mergeBufferPoolIn
+ )
+ {
+ this.mergeBufferPool = mergeBufferPoolIn;
+ }
+
+ @Override
+ public boolean doMonitor(ServiceEmitter emitter)
+ {
+ long pendingQueries = this.mergeBufferPool.getPendingQueries();
+
+ ServiceMetricEvent.Builder builder =
ServiceMetricEvent.builder().setFeed("metrics");
Review Comment:
nit: metrics is the default feed already.
```suggestion
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
```
##########
processing/src/main/java/org/apache/druid/java/util/metrics/MergeBufferPoolMonitor.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.druid.java.util.metrics;
+
+import com.google.inject.Inject;
+import org.apache.druid.collections.BlockingPool;
+import org.apache.druid.guice.annotations.Merging;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+
+import java.nio.ByteBuffer;
+
+public class MergeBufferPoolMonitor extends AbstractMonitor
+{
+
+ private final BlockingPool<ByteBuffer> mergeBufferPool;
+
+ @Inject
+ public MergeBufferPoolMonitor(
+ @Merging BlockingPool<ByteBuffer> mergeBufferPoolIn
+ )
+ {
+ this.mergeBufferPool = mergeBufferPoolIn;
+ }
+
+ @Override
+ public boolean doMonitor(ServiceEmitter emitter)
+ {
+ long pendingQueries = this.mergeBufferPool.getPendingQueries();
+
+ ServiceMetricEvent.Builder builder =
ServiceMetricEvent.builder().setFeed("metrics");
+ emitter.emit(builder.setMetric("mergebuffer/pendingQueries",
pendingQueries));
Review Comment:
Could you add a description for this metric in this file under the
appropriate services
https://github.com/apache/druid/blob/7301e60a9c506758d719cbb57426abcbf912b4b9/docs/operations/metrics.md#L4
##########
processing/src/main/java/org/apache/druid/collections/DefaultBlockingPool.java:
##########
@@ -91,26 +97,38 @@ public List<ReferenceCountingResourceHolder<T>>
takeBatch(final int elementNum,
Preconditions.checkArgument(timeoutMs >= 0, "timeoutMs must be a
non-negative value, but was [%s]", timeoutMs);
checkInitialized();
try {
+ pendingQueries.incrementAndGet();
final List<T> objects = timeoutMs > 0 ? pollObjects(elementNum,
timeoutMs) : pollObjects(elementNum);
return
objects.stream().map(this::wrapObject).collect(Collectors.toList());
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
+ finally {
+ pendingQueries.decrementAndGet();
+ }
}
@Override
public List<ReferenceCountingResourceHolder<T>> takeBatch(final int
elementNum)
{
checkInitialized();
try {
+ pendingQueries.incrementAndGet();
return
takeObjects(elementNum).stream().map(this::wrapObject).collect(Collectors.toList());
}
catch (InterruptedException e) {
+ pendingQueries.incrementAndGet();
Review Comment:
Seems like this is missing a finally block to decrement pendingQueries
```suggestion
```
##########
processing/src/main/java/org/apache/druid/java/util/metrics/MergeBufferPoolMonitor.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.druid.java.util.metrics;
+
+import com.google.inject.Inject;
+import org.apache.druid.collections.BlockingPool;
+import org.apache.druid.guice.annotations.Merging;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+
+import java.nio.ByteBuffer;
+
+public class MergeBufferPoolMonitor extends AbstractMonitor
+{
+
+ private final BlockingPool<ByteBuffer> mergeBufferPool;
+
+ @Inject
+ public MergeBufferPoolMonitor(
+ @Merging BlockingPool<ByteBuffer> mergeBufferPoolIn
Review Comment:
To make this monitor easy to deploy by adding it to the list of monitors in
the `common.runtime.properties` can you copy the pattern in
`WorkerTaskCountStatsMonitor`
https://github.com/apache/druid/blob/7301e60a9c506758d719cbb57426abcbf912b4b9/server/src/main/java/org/apache/druid/server/metrics/WorkerTaskCountStatsMonitor.java#L40-L56
It looks like `@Merging BlockingPool<ByteBuffer>` is available on
historicals, indexers, peons and brokers. So we'd want this monitor to emit
these metrics on those nodes, and do nothing on the other nodes.
##########
processing/src/main/java/org/apache/druid/java/util/metrics/MergeBufferPoolMonitor.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.druid.java.util.metrics;
+
+import com.google.inject.Inject;
+import org.apache.druid.collections.BlockingPool;
+import org.apache.druid.guice.annotations.Merging;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+
+import java.nio.ByteBuffer;
+
+public class MergeBufferPoolMonitor extends AbstractMonitor
Review Comment:
javadocs please
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]