-
Notifications
You must be signed in to change notification settings - Fork 135
fix: Refine connectivity metric for RPCs that receive no response and sent to Transport layer #4220
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
Closed
Closed
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions
53
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerGrpcStreamTracer.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,53 @@ | ||
| /* | ||
| * 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.spanner; | ||
|
|
||
| import io.grpc.ClientStreamTracer; | ||
| import io.grpc.Metadata; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| /** Captures the event when a request is sent from the gRPC client. */ | ||
| public class SpannerGrpcStreamTracer extends ClientStreamTracer { | ||
|
|
||
| private final AtomicBoolean outBoundMessageSent = new AtomicBoolean(false); | ||
|
|
||
| public SpannerGrpcStreamTracer() {} | ||
|
|
||
| public boolean isOutBoundMessageSent() { | ||
| return outBoundMessageSent.get(); | ||
| } | ||
|
|
||
| /** An outbound message has been serialized and sent to the transport. */ | ||
| @Override | ||
| public void outboundMessageSent(int seqNo, long optionalWireSize, long optionalUncompressedSize) { | ||
| outBoundMessageSent.set(true); | ||
| } | ||
|
|
||
| public static class Factory extends ClientStreamTracer.Factory { | ||
|
|
||
| SpannerGrpcStreamTracer spannerGrpcStreamTracer; | ||
|
|
||
| public Factory(SpannerGrpcStreamTracer spannerGrpcStreamTracer) { | ||
| this.spannerGrpcStreamTracer = spannerGrpcStreamTracer; | ||
| } | ||
|
|
||
| @Override | ||
| public ClientStreamTracer newClientStreamTracer( | ||
| ClientStreamTracer.StreamInfo info, Metadata headers) { | ||
| return spannerGrpcStreamTracer; | ||
| } | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -28,14 +28,9 @@ | |
| import com.google.common.cache.Cache; | ||
| import com.google.common.cache.CacheBuilder; | ||
| import com.google.spanner.admin.database.v1.DatabaseName; | ||
| import io.grpc.CallOptions; | ||
| import io.grpc.Channel; | ||
| import io.grpc.ClientCall; | ||
| import io.grpc.ClientInterceptor; | ||
| import io.grpc.*; | ||
| import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; | ||
| import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; | ||
| import io.grpc.Metadata; | ||
| import io.grpc.MethodDescriptor; | ||
| import io.grpc.alts.AltsContextUtil; | ||
| import io.opencensus.stats.MeasureMap; | ||
| import io.opencensus.stats.Stats; | ||
|
|
@@ -50,6 +45,7 @@ | |
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import java.util.regex.Matcher; | ||
|
|
@@ -102,7 +98,11 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | |
| ApiTracer tracer = callOptions.getOption(TRACER_KEY); | ||
| CompositeTracer compositeTracer = | ||
| tracer instanceof CompositeTracer ? (CompositeTracer) tracer : null; | ||
| return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { | ||
| final AtomicBoolean headersReceived = new AtomicBoolean(false); | ||
| SpannerGrpcStreamTracer streamTracer = new SpannerGrpcStreamTracer(); | ||
| CallOptions newOptions = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does customer have access to CallOptions? If yes, We need to make sure we are not overriding |
||
| callOptions.withStreamTracerFactory(new SpannerGrpcStreamTracer.Factory(streamTracer)); | ||
| return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, newOptions)) { | ||
| @Override | ||
| public void start(Listener<RespT> responseListener, Metadata headers) { | ||
| try { | ||
|
|
@@ -124,13 +124,33 @@ public void start(Listener<RespT> responseListener, Metadata headers) { | |
| new SimpleForwardingClientCallListener<RespT>(responseListener) { | ||
| @Override | ||
| public void onHeaders(Metadata metadata) { | ||
| headersReceived.set(true); | ||
| // Check if the call uses DirectPath by inspecting the ALTS context. | ||
| boolean isDirectPathUsed = AltsContextUtil.check(getAttributes()); | ||
| addDirectPathUsedAttribute(compositeTracer, isDirectPathUsed); | ||
| processHeader( | ||
| metadata, tagContext, attributes, span, compositeTracer, isDirectPathUsed); | ||
| super.onHeaders(metadata); | ||
| } | ||
|
|
||
| @Override | ||
| public void onClose(Status status, Metadata trailers) { | ||
| // Check if RPC was sent from gRPC client, but no response headers were received. | ||
| // This can happen in | ||
| // case of a timeout, for example. | ||
| if (streamTracer.isOutBoundMessageSent() && !headersReceived.get()) { | ||
| if (compositeTracer != null) { | ||
| compositeTracer.recordGfeHeaderMissingCount(1L); | ||
| // Disable afe_connectivity_error_count metric as AFE header is disabled in | ||
| // backend | ||
| // currently. | ||
| // if (GapicSpannerRpc.isEnableAFEServerTiming()) { | ||
| // compositeTracer.recordAfeHeaderMissingCount(1L); | ||
| // } | ||
| } | ||
| } | ||
| super.onClose(status, trailers); | ||
| } | ||
| }, | ||
| headers); | ||
| } catch (ExecutionException executionException) { | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an experimental API right? Until tracer is launched, we can't use it right? https://github.com/grpc/grpc-java/blob/master/api/src/main/java/io/grpc/ClientStreamTracer.java#L27