You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "dragosvictor (via GitHub)" <gi...@apache.org> on 2024/06/07 23:52:09 UTC

[PR] [feat][broker] PIP-264: Add OpenTelemetry producer metrics [pulsar]

dragosvictor opened a new pull request, #22882:
URL: https://github.com/apache/pulsar/pull/22882

   [PIP-264](https://github.com/apache/pulsar/blob/master/pip/pip-264.md)
   
   ### Motivation
   
   Adds producer related metrics to the OpenTelemetry pipeline.
   
   ### Modifications
   
   - Adds the metrics described in https://github.com/apache/pulsar-site/pull/911/ to the collector runs.
   - Relocates the metric backend data-sources (`Producer#msgIn`, `Producer#chunkedMessageRate` and `Producer#msgDrop`) from the `Producer` class to `PublisherStatsImpl` and `NonPersistentPublisherStatsImpl`, for a cleaner design.
   - Add field `Rate.totalValueAdder` keeping track of cumulative values added to the Rate, further simplifying the design.
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   This change added tests and can be verified as follows:
   
     - Added basic messaging test in `OpenTelemetryProducerStatsTest`
     - Updated existing test `` to cover the message drop counter functionality
   
   ### Does this pull request potentially affect one of the following parts:
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [x] The metrics: As described in https://github.com/apache/pulsar-site/pull/911/
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [x] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: https://github.com/dragosvictor/pulsar/pull/25
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][broker] PIP-264: Add OpenTelemetry producer metrics [pulsar]

Posted by "dragosvictor (via GitHub)" <gi...@apache.org>.
dragosvictor commented on code in PR #22882:
URL: https://github.com/apache/pulsar/pull/22882#discussion_r1636994032


##########
pulsar-common/src/main/java/org/apache/pulsar/common/stats/Rate.java:
##########
@@ -28,6 +28,7 @@ public class Rate {
     private final LongAdder valueAdder = new LongAdder();
     private final LongAdder countAdder = new LongAdder();
     private final LongAdder totalCountAdder = new LongAdder();
+    private final LongAdder totalValueAdder = new LongAdder();

Review Comment:
   My thinking is that it can be reused in other places where OpenTelemetry metrics are being exposed, so it's not useless. When we remove the Prometheus metrics, we will be able to clear out the other two `LongAdder`s instead.
   
   As for memory consumption, it depends on the cardinality of the object itself. I expect consumers, producers and topics to occupy the lions share of the memory here. Since the numbers themselves have to be exposed one way or another, that loss cannot be avoided. I expect many of these `Rate`s will be exposed under OpenTelemetry, and there will be few instances where the new variable is not being read, and thus redundant.
   
   If we need to improve this still, perhaps we can keep the totals only, while replacing the 'relative' adders with simple atomics. Something along the lines of:
   
   ```java
   private final LongAdder totalValueAdder = new LongAdder();
   private final AtomicLong totalValueCache = new AtomicLong(); // or an AtomicRef updater
   private double valueRate;
   
   public void calculateRate(double period) {
     var current = totalValueAdder.sum();
     var delta = current - totalValueCache.getAndSet(current);
     valueRate = delta / period;
   }
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][broker] PIP-264: Add OpenTelemetry producer metrics [pulsar]

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn merged PR #22882:
URL: https://github.com/apache/pulsar/pull/22882


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][broker] PIP-264: Add OpenTelemetry producer metrics [pulsar]

Posted by "dragosvictor (via GitHub)" <gi...@apache.org>.
dragosvictor commented on code in PR #22882:
URL: https://github.com/apache/pulsar/pull/22882#discussion_r1636979386


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/OpenTelemetryProducerStats.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.pulsar.broker.stats;
+
+import io.opentelemetry.api.metrics.BatchCallback;
+import io.opentelemetry.api.metrics.ObservableLongMeasurement;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.service.Producer;
+import org.apache.pulsar.common.policies.data.stats.NonPersistentPublisherStatsImpl;
+
+public class OpenTelemetryProducerStats implements AutoCloseable {
+
+    // Replaces pulsar_producer_msg_rate_in
+    public static final String MESSAGE_IN_COUNTER = "pulsar.broker.producer.message.incoming.count";
+    private final ObservableLongMeasurement messageInCounter;
+
+    // Replaces pulsar_producer_msg_throughput_in
+    public static final String BYTES_IN_COUNTER = "pulsar.broker.producer.message.incoming.size";
+    private final ObservableLongMeasurement bytesInCounter;
+
+    // Replaces pulsar_consumer_msg_ack_rate
+    public static final String MESSAGE_DROP_COUNTER = "pulsar.broker.producer.message.drop.count";
+    private final ObservableLongMeasurement messageDropCounter;
+
+    private final BatchCallback batchCallback;
+
+    public OpenTelemetryProducerStats(PulsarService pulsar) {
+        var meter = pulsar.getOpenTelemetry().getMeter();
+
+        messageInCounter = meter
+                .counterBuilder(MESSAGE_IN_COUNTER)
+                .setUnit("{message}")
+                .setDescription("The total number of messages received from this producer.")
+                .buildObserver();
+
+        bytesInCounter = meter
+                .counterBuilder(BYTES_IN_COUNTER)
+                .setUnit("By")
+                .setDescription("The total number of messages bytes received from this producer.")
+                .buildObserver();
+
+        messageDropCounter = meter
+                .counterBuilder(MESSAGE_DROP_COUNTER)
+                .setUnit("{message}")
+                .setDescription("The total number of messages dropped from this producer.")
+                .buildObserver();
+

Review Comment:
   That one in particular did not seem too useful IMO. For Prometheus it might have made sense, since the values are getting reset with every run. Under OpenTelemetry, this would be the cumulative total divided by the cumulative count. Something that can be done further down the pipeline, if desired.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][broker] PIP-264: Add OpenTelemetry producer metrics [pulsar]

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #22882:
URL: https://github.com/apache/pulsar/pull/22882#discussion_r1636953499


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/OpenTelemetryProducerStats.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.pulsar.broker.stats;
+
+import io.opentelemetry.api.metrics.BatchCallback;
+import io.opentelemetry.api.metrics.ObservableLongMeasurement;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.service.Producer;
+import org.apache.pulsar.common.policies.data.stats.NonPersistentPublisherStatsImpl;
+
+public class OpenTelemetryProducerStats implements AutoCloseable {
+
+    // Replaces pulsar_producer_msg_rate_in
+    public static final String MESSAGE_IN_COUNTER = "pulsar.broker.producer.message.incoming.count";
+    private final ObservableLongMeasurement messageInCounter;
+
+    // Replaces pulsar_producer_msg_throughput_in
+    public static final String BYTES_IN_COUNTER = "pulsar.broker.producer.message.incoming.size";
+    private final ObservableLongMeasurement bytesInCounter;
+
+    // Replaces pulsar_consumer_msg_ack_rate

Review Comment:
   should we update this comment?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/OpenTelemetryProducerStats.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.pulsar.broker.stats;
+
+import io.opentelemetry.api.metrics.BatchCallback;
+import io.opentelemetry.api.metrics.ObservableLongMeasurement;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.service.Producer;
+import org.apache.pulsar.common.policies.data.stats.NonPersistentPublisherStatsImpl;
+
+public class OpenTelemetryProducerStats implements AutoCloseable {
+
+    // Replaces pulsar_producer_msg_rate_in
+    public static final String MESSAGE_IN_COUNTER = "pulsar.broker.producer.message.incoming.count";
+    private final ObservableLongMeasurement messageInCounter;
+
+    // Replaces pulsar_producer_msg_throughput_in
+    public static final String BYTES_IN_COUNTER = "pulsar.broker.producer.message.incoming.size";
+    private final ObservableLongMeasurement bytesInCounter;
+
+    // Replaces pulsar_consumer_msg_ack_rate
+    public static final String MESSAGE_DROP_COUNTER = "pulsar.broker.producer.message.drop.count";
+    private final ObservableLongMeasurement messageDropCounter;
+
+    private final BatchCallback batchCallback;
+
+    public OpenTelemetryProducerStats(PulsarService pulsar) {
+        var meter = pulsar.getOpenTelemetry().getMeter();
+
+        messageInCounter = meter
+                .counterBuilder(MESSAGE_IN_COUNTER)
+                .setUnit("{message}")
+                .setDescription("The total number of messages received from this producer.")
+                .buildObserver();
+
+        bytesInCounter = meter
+                .counterBuilder(BYTES_IN_COUNTER)
+                .setUnit("By")
+                .setDescription("The total number of messages bytes received from this producer.")
+                .buildObserver();
+
+        messageDropCounter = meter
+                .counterBuilder(MESSAGE_DROP_COUNTER)
+                .setUnit("{message}")
+                .setDescription("The total number of messages dropped from this producer.")
+                .buildObserver();
+

Review Comment:
   Why don't we emit other publisher metrics from PublisherStatsImpl, eg. averageMsgSize?



##########
pulsar-common/src/main/java/org/apache/pulsar/common/stats/Rate.java:
##########
@@ -28,6 +28,7 @@ public class Rate {
     private final LongAdder valueAdder = new LongAdder();
     private final LongAdder countAdder = new LongAdder();
     private final LongAdder totalCountAdder = new LongAdder();
+    private final LongAdder totalValueAdder = new LongAdder();

Review Comment:
   I wonder if we need to extend this Rate class to add this var, if adding this var significantly impacts memory usage ,especially for clusters with a larger number of metrics objects.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [feat][broker] PIP-264: Add OpenTelemetry producer metrics [pulsar]

Posted by "dragosvictor (via GitHub)" <gi...@apache.org>.
dragosvictor commented on code in PR #22882:
URL: https://github.com/apache/pulsar/pull/22882#discussion_r1636994032


##########
pulsar-common/src/main/java/org/apache/pulsar/common/stats/Rate.java:
##########
@@ -28,6 +28,7 @@ public class Rate {
     private final LongAdder valueAdder = new LongAdder();
     private final LongAdder countAdder = new LongAdder();
     private final LongAdder totalCountAdder = new LongAdder();
+    private final LongAdder totalValueAdder = new LongAdder();

Review Comment:
   My thinking is that it can be reused in other places where OpenTelemetry metrics are being exposed, so it's not useless. When we remove the Prometheus metrics, we will be able to clear out the other two `LongAdder`s instead.
   
   As for memory consumption, it depends on the cardinality of the object itself. I expect consumers, producers and topics to occupy the lions share of the memory here. Since the numbers themselves have to be exposed one way or another, that loss cannot be avoided. I expect many of these `Rate`s will be exposed under OpenTelemetry, and there will be few instances where the new variable is not being read, and thus redundant.
   
   If we need to improve this still, perhaps we can keep the totals only, while replacing the 'relative' adders with simple atomics. Something along the lines of:
   
   ```
   private final LongAdder totalValueAdder = new LongAdder();
   private final AtomicLong totalValueCache = new AtomicLong(); // or an AtomicRef updater
   private double valueRate;
   
   public void calculateRate(double period) {
     int current = totalValueAdder.sum();
     int delta = current - totalValueCache.getAndSet(current);
     valueRate = delta / period;
   }
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org