-
Notifications
You must be signed in to change notification settings - Fork 101
feat(bigtable): expose a metric to track the number of outstanding rpcs (unary , streaming) in channel pool #2696
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
Open
sushanb
wants to merge
8
commits into
googleapis:main
Choose a base branch
from
sushanb:book_keeping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,019
−571
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2522fe9
feat(bigtable): add bookkeeping per rpc type unary or streaming
sushanb f767983
fix"
sushanb a7952b6
fix
sushanb 672b78f
add outstanding metrics tracker
sushanb 39a92f6
wip
sushanb 4d272e6
fix a typo
sushanb 7c43031
fix
sushanb ba09467
comments
sushanb 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
111 changes: 111 additions & 0 deletions
111
...ain/java/com/google/cloud/bigtable/data/v2/stub/metrics/OutstandingRpcsMetricTracker.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,111 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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 com.google.cloud.bigtable.data.v2.stub.metrics; | ||
|
|
||
| import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METER_NAME; | ||
| import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.OUTSTANDING_RPCS_PER_CHANNEL_NAME; | ||
|
|
||
| import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelObserver; | ||
| import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolObserver; | ||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.LongHistogram; | ||
| import io.opentelemetry.api.metrics.Meter; | ||
| import java.util.List; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.ScheduledFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class OutstandingRpcsMetricTracker implements Runnable { | ||
| private static final int SAMPLING_PERIOD_SECONDS = 60; | ||
| private final LongHistogram outstandingRpcsHistogram; | ||
| private final AtomicReference<BigtableChannelPoolObserver> bigtableChannelInsightsProviderRef = | ||
| new AtomicReference<>(); | ||
| private final AtomicReference<String> lbPolicyRef = new AtomicReference<>(); | ||
|
|
||
| // Base attributes common to all recordings | ||
| private static final Attributes TRANSPORT_GRPC_ATTR = | ||
| Attributes.builder().put("transport_type", "grpc").build(); | ||
|
|
||
| // Attributes for unary and streaming RPCs, built on demand in run() | ||
| @Nullable private Attributes unaryAttributes; | ||
| @Nullable private Attributes streamingAttributes; | ||
|
|
||
| public OutstandingRpcsMetricTracker(OpenTelemetry openTelemetry) { | ||
| Meter meter = openTelemetry.getMeter(METER_NAME); | ||
| this.outstandingRpcsHistogram = | ||
| meter | ||
| .histogramBuilder(OUTSTANDING_RPCS_PER_CHANNEL_NAME) | ||
| .ofLongs() | ||
| .setDescription( | ||
| "A distribution of the number of outstanding RPCs per connection in the client pool, sampled periodically.") | ||
| .setUnit("1") | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Registers the provider for the channel pool entries. This should be called by the component | ||
| * that creates the BigtableChannelPool. | ||
| */ | ||
| public void registerChannelInsightsProvider(BigtableChannelPoolObserver channelInsightsProvider) { | ||
| this.bigtableChannelInsightsProviderRef.set(channelInsightsProvider); | ||
| } | ||
|
|
||
| /** Register the current lb policy * */ | ||
| public void registerLoadBalancingStrategy(String lbPolicy) { | ||
| this.lbPolicyRef.set(lbPolicy); | ||
| } | ||
|
|
||
| /** Starts the periodic collection. */ | ||
| public ScheduledFuture<?> start(ScheduledExecutorService scheduler) { | ||
| return scheduler.scheduleAtFixedRate( | ||
| this, SAMPLING_PERIOD_SECONDS, SAMPLING_PERIOD_SECONDS, TimeUnit.SECONDS); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| BigtableChannelPoolObserver channelInsightsProvider = bigtableChannelInsightsProviderRef.get(); | ||
| if (channelInsightsProvider == null) { | ||
| return; // Not registered yet | ||
| } | ||
| String lbPolicy = lbPolicyRef.get(); | ||
| if (lbPolicy == null) { | ||
sushanb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lbPolicy = "ROUND_ROBIN"; | ||
| } | ||
|
|
||
| // Build attributes if they haven't been built yet or were invalidated | ||
sushanb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (unaryAttributes == null || streamingAttributes == null) { | ||
| Attributes baseAttrs = TRANSPORT_GRPC_ATTR.toBuilder().put("lb_policy", lbPolicy).build(); | ||
| this.unaryAttributes = baseAttrs.toBuilder().put("streaming", false).build(); | ||
| this.streamingAttributes = baseAttrs.toBuilder().put("streaming", true).build(); | ||
| } | ||
| List<? extends BigtableChannelObserver> channelInsights = | ||
| channelInsightsProvider.getChannelInfos(); | ||
| if (channelInsights == null || channelInsights.isEmpty()) { | ||
| return; | ||
| } | ||
| for (BigtableChannelObserver info : channelInsights) { | ||
| long currentOutstandingUnaryRpcs = info.getOutstandingUnaryRpcs(); | ||
| long currentOutstandingStreamingRpcs = info.getOutstandingStreamingRpcs(); | ||
| // Record outstanding unary RPCs with streaming=false | ||
| outstandingRpcsHistogram.record(currentOutstandingUnaryRpcs, unaryAttributes); | ||
| // Record outstanding streaming RPCs with streaming=true | ||
| outstandingRpcsHistogram.record(currentOutstandingStreamingRpcs, streamingAttributes); | ||
| } | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...d-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelObserver.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,27 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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 com.google.cloud.bigtable.gaxx.grpc; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
|
|
||
| /** Provides observability about a single channel in the channel pool. */ | ||
| @InternalApi | ||
| public interface BigtableChannelObserver { | ||
| /** Gets the current number of outstanding Unary RPCs on this channel. */ | ||
| int getOutstandingUnaryRpcs(); | ||
|
|
||
| int getOutstandingStreamingRpcs(); | ||
| } |
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.