-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[feat][broker] PIP-264: Add OpenTelemetry metadata store stats #22952
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
lhotari
merged 9 commits into
apache:master
from
dragosvictor:dmisca-pip-264-metadata-store-stats
Jun 26, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca2747e
Draft metadata store stats
dragosvictor b3dc729
Draft metadata store stats
dragosvictor d2d8e0f
Merge remote-tracking branch 'origin/master' into dmisca-pip-264-meta…
dragosvictor 6f8c2b2
Build fix
dragosvictor 79db268
Add test draft
dragosvictor f494f8b
Add MetadataStoreConfig.openTelemetry default
dragosvictor e4015db
Metric refactoring
dragosvictor effea3c
Cosmetic fixes
dragosvictor 6021e21
Fix metric description
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
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
94 changes: 94 additions & 0 deletions
94
...ker/src/test/java/org/apache/pulsar/broker/stats/OpenTelemetryMetadataStoreStatsTest.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,94 @@ | ||
/* | ||
* 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 static org.apache.pulsar.broker.stats.BrokerOpenTelemetryTestUtil.assertMetricLongSumValue; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import io.opentelemetry.api.common.Attributes; | ||
import java.util.concurrent.ExecutorService; | ||
import lombok.Cleanup; | ||
import org.apache.commons.lang3.reflect.FieldUtils; | ||
import org.apache.pulsar.broker.BrokerTestUtil; | ||
import org.apache.pulsar.broker.service.BrokerTestBase; | ||
import org.apache.pulsar.broker.testcontext.NonClosingProxyHandler; | ||
import org.apache.pulsar.broker.testcontext.PulsarTestContext; | ||
import org.apache.pulsar.metadata.api.MetadataStore; | ||
import org.apache.pulsar.metadata.impl.stats.BatchMetadataStoreStats; | ||
import org.apache.pulsar.metadata.impl.stats.MetadataStoreStats; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
public class OpenTelemetryMetadataStoreStatsTest extends BrokerTestBase { | ||
|
||
@BeforeMethod(alwaysRun = true) | ||
@Override | ||
protected void setup() throws Exception { | ||
super.baseSetup(); | ||
setupDefaultTenantAndNamespace(); | ||
|
||
// In testing conditions, the metadata store gets initialized before Pulsar does, so the OpenTelemetry SDK is | ||
// not yet initialized. Work around this issue by recreating the stats object once we have access to the SDK. | ||
var localMetadataStore = (MetadataStore) NonClosingProxyHandler.getDelegate(pulsar.getLocalMetadataStore()); | ||
var currentStats = (MetadataStoreStats) FieldUtils.readField(localMetadataStore, "metadataStoreStats", true); | ||
var localMetadataStoreName = (String) FieldUtils.readField(currentStats, "metadataStoreName", true); | ||
|
||
currentStats.close(); | ||
var newStats = new MetadataStoreStats( | ||
localMetadataStoreName, pulsar.getOpenTelemetry().getOpenTelemetryService().getOpenTelemetry()); | ||
FieldUtils.writeField(localMetadataStore, "metadataStoreStats", newStats, true); | ||
|
||
var currentBatchedStats = (BatchMetadataStoreStats) FieldUtils.readField(localMetadataStore, "batchMetadataStoreStats", true); | ||
currentBatchedStats.close(); | ||
var currentExecutor = (ExecutorService) FieldUtils.readField(currentBatchedStats, "executor", true); | ||
var newBatchedStats = new BatchMetadataStoreStats( | ||
localMetadataStoreName, currentExecutor, pulsar.getOpenTelemetry().getOpenTelemetryService().getOpenTelemetry()); | ||
FieldUtils.writeField(localMetadataStore, "batchMetadataStoreStats", newBatchedStats, true); | ||
} | ||
|
||
@AfterMethod(alwaysRun = true) | ||
@Override | ||
protected void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
} | ||
|
||
@Override | ||
protected void customizeMainPulsarTestContextBuilder(PulsarTestContext.Builder pulsarTestContextBuilder) { | ||
super.customizeMainPulsarTestContextBuilder(pulsarTestContextBuilder); | ||
pulsarTestContextBuilder.enableOpenTelemetry(true); | ||
} | ||
|
||
@Test | ||
public void testMetadataStoreStats() throws Exception { | ||
var topicName = BrokerTestUtil.newUniqueName("persistent://public/default/test-metadata-store-stats"); | ||
|
||
@Cleanup | ||
var producer = pulsarClient.newProducer().topic(topicName).create(); | ||
|
||
producer.newMessage().value("test".getBytes()).send(); | ||
|
||
var attributes = Attributes.of(MetadataStoreStats.METADATA_STORE_NAME, "metadata-store"); | ||
|
||
var metrics = pulsarTestContext.getOpenTelemetryMetricReader().collectAllMetrics(); | ||
assertMetricLongSumValue(metrics, MetadataStoreStats.METADATA_STORE_PUT_BYTES_COUNTER_METRIC_NAME, | ||
attributes, value -> assertThat(value).isPositive()); | ||
assertMetricLongSumValue(metrics, BatchMetadataStoreStats.EXECUTOR_QUEUE_SIZE_METRIC_NAME, attributes, | ||
value -> assertThat(value).isPositive()); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
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.