asafm commented on code in PR #22058:
URL: https://github.com/apache/pulsar/pull/22058#discussion_r1501838360


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -403,15 +412,43 @@ public BrokerService(PulsarService pulsar, EventLoopGroup 
eventLoopGroup) throws
         this.defaultServerBootstrap = defaultServerBootstrap();
 
         this.pendingLookupRequests = 
ObserverGauge.build("pulsar_broker_lookup_pending_requests", "-")
-                .supplier(() -> 
pulsar.getConfig().getMaxConcurrentLookupRequest()
-                        - lookupRequestSemaphore.get().availablePermits())
+                .supplier(this::getPendingLookupRequest)
                 .register();
+        this.pendingLookupOperationsCounter = 
pulsar.getOpenTelemetry().getMeter()
+                
.upDownCounterBuilder("pulsar.broker.topic.lookup.operation.pending.usage")
+                .setDescription("The number of pending lookup operations in 
the broker. "
+                        + "When it reaches threshold 
\"maxConcurrentLookupRequest\" defined in broker.conf, "
+                        + "new requests are rejected.")
+                .setUnit("{operation}")
+                .buildWithCallback(measurement -> 
measurement.record(getPendingLookupRequest()));
+        this.pendingLookupOperationsLimitGauge = 
pulsar.getOpenTelemetry().getMeter()
+                
.gaugeBuilder("pulsar.broker.topic.lookup.operation.pending.limit")
+                .ofLongs()
+                .setDescription("The maximum number of pending lookup 
operations in the broker. "
+                        + "Equal to \"maxConcurrentLookupRequest\" defined in 
broker.conf.")
+                .setUnit("{operation}")
+                .buildWithCallback(
+                        measurement -> 
measurement.record(pulsar.getConfig().getMaxConcurrentLookupRequest()));
 
         this.pendingTopicLoadRequests = ObserverGauge.build(
-                "pulsar_broker_topic_load_pending_requests", "-")
-                .supplier(() -> 
pulsar.getConfig().getMaxConcurrentTopicLoadRequest()
-                        - topicLoadRequestSemaphore.get().availablePermits())
+                        "pulsar_broker_topic_load_pending_requests", "-")
+                .supplier(this::getPendingTopicLoadRequests)
                 .register();
+        this.pendingTopicLoadOperationsCounter = 
pulsar.getOpenTelemetry().getMeter()
+                
.upDownCounterBuilder("pulsar.broker.topic.load.operation.pending.usage")
+                .setDescription("The number of pending topic load operations 
in the broker. "
+                        + "When it reaches threshold 
\"maxConcurrentTopicLoadRequest\" defined in broker.conf, "
+                        + "new requests are rejected.")
+                .setUnit("{operation}")
+                .buildWithCallback(measurement -> 
measurement.record(getPendingTopicLoadRequests()));
+        this.pendingTopicLoadOperationsLimitGauge = 
pulsar.getOpenTelemetry().getMeter()

Review Comment:
   Same



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -403,15 +412,43 @@ public BrokerService(PulsarService pulsar, EventLoopGroup 
eventLoopGroup) throws
         this.defaultServerBootstrap = defaultServerBootstrap();
 
         this.pendingLookupRequests = 
ObserverGauge.build("pulsar_broker_lookup_pending_requests", "-")
-                .supplier(() -> 
pulsar.getConfig().getMaxConcurrentLookupRequest()
-                        - lookupRequestSemaphore.get().availablePermits())
+                .supplier(this::getPendingLookupRequest)
                 .register();
+        this.pendingLookupOperationsCounter = 
pulsar.getOpenTelemetry().getMeter()
+                
.upDownCounterBuilder("pulsar.broker.topic.lookup.operation.pending.usage")
+                .setDescription("The number of pending lookup operations in 
the broker. "
+                        + "When it reaches threshold 
\"maxConcurrentLookupRequest\" defined in broker.conf, "
+                        + "new requests are rejected.")
+                .setUnit("{operation}")
+                .buildWithCallback(measurement -> 
measurement.record(getPendingLookupRequest()));
+        this.pendingLookupOperationsLimitGauge = 
pulsar.getOpenTelemetry().getMeter()
+                
.gaugeBuilder("pulsar.broker.topic.lookup.operation.pending.limit")

Review Comment:
   Gauge was selected on purpose for the limit since we don't want people to 
add limits across brokers?



##########
pulsar-broker/src/test/java/org/apache/pulsar/client/api/BrokerServiceLookupTest.java:
##########
@@ -1125,6 +1201,17 @@ public void 
testLookupConnectionNotCloseIfGetUnloadingExOrMetadataEx() throws Ex
         assertTrue(lookupService instanceof BinaryProtoLookupService);
         ClientCnx lookupConnection = 
pulsarClientImpl.getCnxPool().getConnection(lookupService.resolveHost()).join();
 
+        var metricName = "pulsar.broker.lookup.request.duration";
+        var metricReader = pulsarTestContext.getOpenTelemetryMetricReader();
+        assertThat(metricReader.collectAllMetrics())
+                .noneSatisfy(metric -> assertThat(metric)
+                        .hasName(metricName)
+                        .hasHistogramSatisfying(histogram -> 
histogram.hasPointsSatisfying(
+                                point -> point
+                                        
.hasAttributes(OpenTelemetryAttributes.PULSAR_RESPONSE_STATUS_FAILURE),

Review Comment:
   Should you validate the count?



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