-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feat][broker] PIP-264: Add OpenTelemetry producer metrics #22882
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
Merged
heesung-sohn
merged 24 commits into
apache:master
from
dragosvictor:dmisca-pip-264-producer-metrics
Jun 15, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
76d35e1
Add producer messaging counters
dragosvictor 9e6c1d1
Merge remote-tracking branch 'origin/master' into dmisca-pip-264-prod…
dragosvictor c225195
Add producer attributes
dragosvictor d5abd2d
Add draft OpenTelemetryProducerStats
dragosvictor d76e9ea
Update producer metric sources
dragosvictor 6b2883a
Add OpenTelemetryProducerStats field to PulsarService
dragosvictor 1ddf9d0
Merge branch 'master' into dmisca-pip-264-producer-metrics
dragosvictor 6316c26
Cosmetic fixes
dragosvictor 70bf82f
Reduce producer attribute count
dragosvictor 4226aa4
Cache attributes
dragosvictor 4826cfb
Add producer stats test
dragosvictor 92b2215
Update metric defs
dragosvictor d784728
Add totalValue field to Rate
dragosvictor 8184283
Revert interface changes
dragosvictor 8966aef
Relocate Producer.rateIn field to PublisherStatsImpl
dragosvictor eb24b9a
Remove unused method Producer.updateRates
dragosvictor cb3f236
Relocate Producer.chunkedMessageRate to PublisherStatsImpl
dragosvictor 5472bfe
Relocate Producer.msgDropRate to NonPersistentPublisherStatsImpl
dragosvictor 65b0d1c
Validate message drop metric
dragosvictor edb4d63
Fix BrokerServiceLookupTest.testMultipleBrokerLookup
dragosvictor 88a40be
Do not expose new fields in JSON
dragosvictor c6577c8
Use lower_underscore case format for access mode enum attribute
dragosvictor c24d7e8
Update OpenTelemetryProducerStats.java
dragosvictor 8b38b63
Merge remote-tracking branch 'origin/master' into dmisca-pip-264-prod…
dragosvictor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/OpenTelemetryProducerStats.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| 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(); | ||
|
|
||
| batchCallback = meter.batchCallback(() -> pulsar.getBrokerService() | ||
| .getTopics() | ||
| .values() | ||
| .stream() | ||
| .filter(future -> future.isDone() && !future.isCompletedExceptionally()) | ||
| .map(CompletableFuture::join) | ||
| .filter(Optional::isPresent) | ||
| .flatMap(topic -> topic.get().getProducers().values().stream()) | ||
| .forEach(this::recordMetricsForProducer), | ||
| messageInCounter, | ||
| bytesInCounter, | ||
| messageDropCounter); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| batchCallback.close(); | ||
| } | ||
|
|
||
| private void recordMetricsForProducer(Producer producer) { | ||
| var attributes = producer.getOpenTelemetryAttributes(); | ||
| var stats = producer.getStats(); | ||
|
|
||
| messageInCounter.record(stats.getMsgInCounter(), attributes); | ||
| bytesInCounter.record(stats.getBytesInCounter(), attributes); | ||
|
|
||
| if (stats instanceof NonPersistentPublisherStatsImpl nonPersistentStats) { | ||
| messageDropCounter.record(nonPersistentStats.getMsgDropCount(), attributes); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.