-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track the latency a request is queued on the grpc channel (#1604)
For all operations, it tracks the latency of the request getting queued on a grpc channel. For batch operations, it's the aggregated value of grpc channel queued latency and batcher flow control latencies.
- Loading branch information
Showing
14 changed files
with
287 additions
and
17 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
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
62 changes: 62 additions & 0 deletions
62
...rc/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableGrpcStreamTracer.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,62 @@ | ||
/* | ||
* Copyright 2023 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 com.google.common.base.Stopwatch; | ||
import io.grpc.Attributes; | ||
import io.grpc.ClientStreamTracer; | ||
import io.grpc.Metadata; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Records the time a request is enqueued in a grpc channel queue. This a bridge between gRPC stream | ||
* tracing and Bigtable tracing. Its primary purpose is to measure the transition time between | ||
* asking gRPC to start an RPC and gRPC actually serializing that RPC. | ||
*/ | ||
class BigtableGrpcStreamTracer extends ClientStreamTracer { | ||
|
||
private final Stopwatch stopwatch = Stopwatch.createUnstarted(); | ||
private final BigtableTracer tracer; | ||
|
||
public BigtableGrpcStreamTracer(BigtableTracer tracer) { | ||
this.tracer = tracer; | ||
} | ||
|
||
@Override | ||
public void streamCreated(Attributes transportAttrs, Metadata headers) { | ||
stopwatch.start(); | ||
} | ||
|
||
@Override | ||
public void outboundMessageSent(int seqNo, long optionalWireSize, long optionalUncompressedSize) { | ||
tracer.grpcChannelQueuedLatencies(stopwatch.elapsed(TimeUnit.MILLISECONDS)); | ||
} | ||
|
||
static class Factory extends ClientStreamTracer.Factory { | ||
|
||
private final BigtableTracer tracer; | ||
|
||
Factory(BigtableTracer tracer) { | ||
this.tracer = tracer; | ||
} | ||
|
||
@Override | ||
public ClientStreamTracer newClientStreamTracer( | ||
ClientStreamTracer.StreamInfo info, Metadata headers) { | ||
return new BigtableGrpcStreamTracer(tracer); | ||
} | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...va/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableTracerBatchedUnaryCallable.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,55 @@ | ||
/* | ||
* Copyright 2023 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 com.google.api.core.ApiFuture; | ||
import com.google.api.core.ApiFutures; | ||
import com.google.api.core.InternalApi; | ||
import com.google.api.gax.grpc.GrpcResponseMetadata; | ||
import com.google.api.gax.rpc.ApiCallContext; | ||
import com.google.api.gax.rpc.UnaryCallable; | ||
import com.google.common.util.concurrent.MoreExecutors; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* This callable will do everything described in {@link BigtableTracerUnaryCallable} except that it | ||
* won't inject a {@link BigtableGrpcStreamTracer}. For batching calls, we only want to calculate | ||
* the total time client is blocked because of flow control. | ||
*/ | ||
@InternalApi | ||
public class BigtableTracerBatchedUnaryCallable<RequestT, ResponseT> | ||
extends BigtableTracerUnaryCallable<RequestT, ResponseT> { | ||
|
||
private UnaryCallable<RequestT, ResponseT> innerCallable; | ||
|
||
public BigtableTracerBatchedUnaryCallable( | ||
@Nonnull UnaryCallable<RequestT, ResponseT> innerCallable) { | ||
super(innerCallable); | ||
this.innerCallable = innerCallable; | ||
} | ||
|
||
@Override | ||
public ApiFuture futureCall(RequestT request, ApiCallContext context) { | ||
final GrpcResponseMetadata responseMetadata = new GrpcResponseMetadata(); | ||
BigtableTracerUnaryCallback<ResponseT> callback = | ||
new BigtableTracerUnaryCallback<ResponseT>( | ||
(BigtableTracer) context.getTracer(), responseMetadata); | ||
ApiFuture<ResponseT> future = | ||
innerCallable.futureCall(request, responseMetadata.addHandlers(context)); | ||
ApiFutures.addCallback(future, callback, MoreExecutors.directExecutor()); | ||
return future; | ||
} | ||
} |
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
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.