-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[monitor][broker][metadata] add metrics for BatchMetadataStore #17072
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
codelipenghui
merged 16 commits into
apache:master
from
tjiuming:dev/batch_metadata_store_stats
Nov 1, 2022
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
18c7584
add BatchMetadataStoreStats
dao-jun 3e06fef
upate stats
dao-jun 51a2361
review fix
dao-jun 2c8d46c
Merge branch 'master' into dev/batch_metadata_store_stats
dao-jun 571a641
Merge branch 'master' into dev/batch_metadata_store_stats
tjiuming 65f8f1f
Merge branch 'master' into dev/batch_metadata_store_stats
dao-jun 5d5759f
fix
dao-jun 24f2dc4
review fix
dao-jun 869a0d9
fix
dao-jun 2eba39d
fix
dao-jun 6d9f167
Merge branch 'master' into dev/batch_metadata_store_stats
dao-jun 8f8719c
fix tests
dao-jun 316bcd0
fix metrics name
dao-jun 0d79b3f
Merge branch 'master' into dev/batch_metadata_store_stats
dao-jun 52b0b31
Merge branch 'master' into dev/batch_metadata_store_stats
dao-jun 5127d25
fix metrics name
dao-jun 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,8 @@ enum Type { | |
|
|
||
| int size(); | ||
|
|
||
| long created(); | ||
|
|
||
| default OpGet asGet() { | ||
| return (OpGet) this; | ||
| } | ||
|
|
||
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
104 changes: 104 additions & 0 deletions
104
...metadata/src/main/java/org/apache/pulsar/metadata/impl/stats/BatchMetadataStoreStats.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,104 @@ | ||
| /* | ||
| * 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.metadata.impl.stats; | ||
|
|
||
| import io.prometheus.client.Gauge; | ||
| import io.prometheus.client.Histogram; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| public final class BatchMetadataStoreStats implements AutoCloseable { | ||
| private static final double[] BUCKETS = new double[]{1, 5, 10, 20, 50, 100, 200, 500, 1000}; | ||
| private static final String NAME = "name"; | ||
|
|
||
| private static final Gauge EXECUTOR_QUEUE_SIZE = Gauge | ||
|
tjiuming marked this conversation as resolved.
|
||
| .build("pulsar_batch_metadata_store_executor_queue_size", "-") | ||
| .labelNames(NAME) | ||
| .register(); | ||
| private static final Histogram OPS_WAITING = Histogram | ||
| .build("pulsar_batch_metadata_store_queue_wait_time", "-") | ||
| .unit("ms") | ||
| .labelNames(NAME) | ||
| .buckets(BUCKETS) | ||
| .register(); | ||
| private static final Histogram BATCH_EXECUTE_TIME = Histogram | ||
| .build("pulsar_batch_metadata_store_batch_execute_time", "-") | ||
| .unit("ms") | ||
| .labelNames(NAME) | ||
| .buckets(BUCKETS) | ||
| .register(); | ||
| private static final Histogram OPS_PER_BATCH = Histogram | ||
| .build("pulsar_batch_metadata_store_batch_size", "-") | ||
| .labelNames(NAME) | ||
| .buckets(BUCKETS) | ||
| .register(); | ||
|
|
||
| private final AtomicBoolean closed = new AtomicBoolean(false); | ||
| private final ThreadPoolExecutor executor; | ||
| private final String metadataStoreName; | ||
|
|
||
| private final Histogram.Child batchOpsWaitingChild; | ||
| private final Histogram.Child batchExecuteTimeChild; | ||
| private final Histogram.Child opsPerBatchChild; | ||
|
|
||
| public BatchMetadataStoreStats(String metadataStoreName, ExecutorService executor) { | ||
| if (executor instanceof ThreadPoolExecutor tx) { | ||
| this.executor = tx; | ||
| } else { | ||
| this.executor = null; | ||
| } | ||
| this.metadataStoreName = metadataStoreName; | ||
|
|
||
| EXECUTOR_QUEUE_SIZE.setChild(new Gauge.Child() { | ||
| @Override | ||
| public double get() { | ||
| return BatchMetadataStoreStats.this.executor == null ? 0 : | ||
| BatchMetadataStoreStats.this.executor.getQueue().size(); | ||
| } | ||
| }, metadataStoreName); | ||
|
|
||
| this.batchOpsWaitingChild = OPS_WAITING.labels(metadataStoreName); | ||
| this.batchExecuteTimeChild = BATCH_EXECUTE_TIME.labels(metadataStoreName); | ||
| this.opsPerBatchChild = OPS_PER_BATCH.labels(metadataStoreName); | ||
|
|
||
| } | ||
|
|
||
| public void recordOpWaiting(long millis) { | ||
| this.batchOpsWaitingChild.observe(millis); | ||
| } | ||
|
|
||
| public void recordBatchExecuteTime(long millis) { | ||
| this.batchExecuteTimeChild.observe(millis); | ||
| } | ||
|
|
||
| public void recordOpsInBatch(int ops) { | ||
| this.opsPerBatchChild.observe(ops); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| if (closed.compareAndSet(false, true)) { | ||
| EXECUTOR_QUEUE_SIZE.remove(this.metadataStoreName); | ||
| OPS_WAITING.remove(this.metadataStoreName); | ||
| BATCH_EXECUTE_TIME.remove(this.metadataStoreName); | ||
| OPS_PER_BATCH.remove(metadataStoreName); | ||
| } | ||
| } | ||
| } | ||
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.