3424672656 commented on code in PR #25309:
URL: https://github.com/apache/pulsar/pull/25309#discussion_r2916950882


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java:
##########
@@ -294,30 +285,14 @@ public ProducerImpl(PulsarClientImpl client, String 
topic, ProducerConfiguration
         }
 
         InstrumentProvider ip = client.instrumentProvider();
-        latencyHistogram = 
ip.newLatencyHistogram("pulsar.client.producer.message.send.duration",
-                "Publish latency experienced by the application, includes 
client batching time", topic,
-                Attributes.empty());
-        rpcLatencyHistogram = 
ip.newLatencyHistogram("pulsar.client.producer.rpc.send.duration",
-                "Publish RPC latency experienced internally by the client when 
sending data to receiving an ack", topic,
-                Attributes.empty());
-        publishedBytesCounter = 
ip.newCounter("pulsar.client.producer.message.send.size",
-                Unit.Bytes, "The number of bytes published", topic, 
Attributes.empty());
-        pendingMessagesUpDownCounter =
-                
ip.newUpDownCounter("pulsar.client.producer.message.pending.count", 
Unit.Messages,
-                        "The number of messages in the producer internal send 
queue, waiting to be sent", topic,
-                        Attributes.empty());
-        pendingBytesUpDownCounter = 
ip.newUpDownCounter("pulsar.client.producer.message.pending.size", Unit.Bytes,
-                "The size of the messages in the producer internal queue, 
waiting to sent", topic, Attributes.empty());
-        producersOpenedCounter = 
ip.newCounter("pulsar.client.producer.opened", Unit.Sessions,
-                "The number of producer sessions opened", topic, 
Attributes.empty());
-        producersClosedCounter = 
ip.newCounter("pulsar.client.producer.closed", Unit.Sessions,
-                "The number of producer sessions closed", topic, 
Attributes.empty());
+        producerMetrics = new ProducerMetrics(ip, topic);
+        rpcLatencyHistogram = producerMetrics.getRpcLatencyHistogram();

Review Comment:
   done~



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/metrics/ConsumerMetrics.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.client.impl.metrics;
+
+import io.opentelemetry.api.common.Attributes;
+
+public class ConsumerMetrics {
+
+    private final Counter messagesReceivedCounter;
+    private final Counter bytesReceivedCounter;
+    private final UpDownCounter messagesPrefetchedGauge;
+    private final UpDownCounter bytesPrefetchedGauge;
+    private final Counter consumersOpenedCounter;
+    private final Counter consumersClosedCounter;
+    private final Counter consumerAcksCounter;
+    private final Counter consumerNacksCounter;
+    private final Counter consumerDlqMessagesCounter;
+
+    public ConsumerMetrics(InstrumentProvider ip, String topic, String 
subscription) {
+        Attributes attrs = Attributes.builder().put("pulsar.subscription", 
subscription).build();
+
+        consumersOpenedCounter = 
ip.newCounter("pulsar.client.consumer.opened", Unit.Sessions,
+                "The number of consumer sessions opened", topic, attrs);
+        consumersClosedCounter = 
ip.newCounter("pulsar.client.consumer.closed", Unit.Sessions,
+                "The number of consumer sessions closed", topic, attrs);
+        messagesReceivedCounter = 
ip.newCounter("pulsar.client.consumer.message.received.count", Unit.Messages,
+                "The number of messages explicitly received by the consumer 
application", topic, attrs);
+        bytesReceivedCounter = 
ip.newCounter("pulsar.client.consumer.message.received.size", Unit.Bytes,
+                "The number of bytes explicitly received by the consumer 
application", topic, attrs);
+        messagesPrefetchedGauge = 
ip.newUpDownCounter("pulsar.client.consumer.receive_queue.count", Unit.Messages,
+                "The number of messages currently sitting in the consumer 
receive queue", topic, attrs);
+        bytesPrefetchedGauge = 
ip.newUpDownCounter("pulsar.client.consumer.receive_queue.size", Unit.Bytes,
+                "The total size in bytes of messages currently sitting in the 
consumer receive queue", topic, attrs);
+        consumerAcksCounter = 
ip.newCounter("pulsar.client.consumer.message.ack", Unit.Messages,
+                "The number of acknowledged messages", topic, attrs);
+        consumerNacksCounter = 
ip.newCounter("pulsar.client.consumer.message.nack", Unit.Messages,
+                "The number of negatively acknowledged messages", topic, 
attrs);
+        consumerDlqMessagesCounter = 
ip.newCounter("pulsar.client.consumer.message.dlq", Unit.Messages,
+                "The number of messages sent to DLQ", topic, attrs);
+    }
+
+    public void recordMessagePrefetched(int msgSize) {
+        messagesPrefetchedGauge.increment();
+        bytesPrefetchedGauge.add(msgSize);
+    }
+
+    public void recordMessageReceived(int msgSize) {
+        messagesPrefetchedGauge.decrement();
+        bytesPrefetchedGauge.subtract(msgSize);
+        messagesReceivedCounter.increment();
+        bytesReceivedCounter.add(msgSize);
+    }
+
+    public void recordAck() {
+        consumerAcksCounter.increment();
+    }
+
+    public void recordNack() {
+        consumerNacksCounter.increment();
+    }
+
+    public void recordDlq() {

Review Comment:
   done~



-- 
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]

Reply via email to