-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat][broker] PIP-264: Add replication subscription stats (#23026)
- Loading branch information
1 parent
dccc06b
commit ed14f21
Showing
7 changed files
with
146 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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 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
72 changes: 72 additions & 0 deletions
72
...rc/main/java/org/apache/pulsar/broker/stats/OpenTelemetryReplicatedSubscriptionStats.java
This file contains 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,72 @@ | ||
/* | ||
* 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.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.DoubleHistogram; | ||
import io.opentelemetry.api.metrics.LongCounter; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.pulsar.broker.PulsarService; | ||
import org.apache.pulsar.common.stats.MetricsUtil; | ||
|
||
public class OpenTelemetryReplicatedSubscriptionStats { | ||
|
||
public static final AttributeKey<String> SNAPSHOT_OPERATION_RESULT = | ||
AttributeKey.stringKey("pulsar.replication.subscription.snapshot.operation.result"); | ||
public enum SnapshotOperationResult { | ||
SUCCESS, | ||
TIMEOUT; | ||
private final Attributes attributes = Attributes.of(SNAPSHOT_OPERATION_RESULT, name().toLowerCase()); | ||
} | ||
|
||
public static final String SNAPSHOT_OPERATION_COUNT_METRIC_NAME = | ||
"pulsar.broker.replication.subscription.snapshot.operation.count"; | ||
private final LongCounter snapshotOperationCounter; | ||
|
||
public static final String SNAPSHOT_DURATION_METRIC_NAME = | ||
"pulsar.broker.replication.subscription.snapshot.operation.duration"; | ||
private final DoubleHistogram snapshotDuration; | ||
|
||
public OpenTelemetryReplicatedSubscriptionStats(PulsarService pulsar) { | ||
var meter = pulsar.getOpenTelemetry().getMeter(); | ||
snapshotOperationCounter = meter.counterBuilder(SNAPSHOT_OPERATION_COUNT_METRIC_NAME) | ||
.setDescription("The number of snapshot operations attempted") | ||
.setUnit("{operation}") | ||
.build(); | ||
snapshotDuration = meter.histogramBuilder(SNAPSHOT_DURATION_METRIC_NAME) | ||
.setDescription("Time taken to complete a consistent snapshot operation across clusters") | ||
.setUnit("s") | ||
.build(); | ||
} | ||
|
||
public void recordSnapshotStarted() { | ||
snapshotOperationCounter.add(1); | ||
} | ||
|
||
public void recordSnapshotTimedOut(long durationMs) { | ||
snapshotDuration.record(MetricsUtil.convertToSeconds(durationMs, TimeUnit.MILLISECONDS), | ||
SnapshotOperationResult.TIMEOUT.attributes); | ||
} | ||
|
||
public void recordSnapshotCompleted(long durationMs) { | ||
snapshotDuration.record(MetricsUtil.convertToSeconds(durationMs, TimeUnit.MILLISECONDS), | ||
SnapshotOperationResult.SUCCESS.attributes); | ||
} | ||
} |
This file contains 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 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.