Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add batch throttled ms metric (#888)
* feat: add throttled time to ApiTracer * fix abstract class * update based on review * fix format * updates on comments * make tests more readable * update year * fix test * make the test more readable
- Loading branch information
Showing
11 changed files
with
356 additions
and
22 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
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
50 changes: 50 additions & 0 deletions
50
.../main/java/com/google/cloud/bigtable/data/v2/stub/metrics/TracedBatcherUnaryCallable.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,50 @@ | ||
/* | ||
* Copyright 2021 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.InternalApi; | ||
import com.google.api.gax.batching.Batcher; | ||
import com.google.api.gax.rpc.ApiCallContext; | ||
import com.google.api.gax.rpc.UnaryCallable; | ||
import com.google.api.gax.tracing.ApiTracer; | ||
|
||
/** | ||
* This callable will extract total throttled time from {@link ApiCallContext} and add it to {@link | ||
* ApiTracer}. This class needs to be wrapped by a callable that injects the {@link ApiTracer}. | ||
*/ | ||
@InternalApi | ||
public final class TracedBatcherUnaryCallable<RequestT, ResponseT> | ||
extends UnaryCallable<RequestT, ResponseT> { | ||
private final UnaryCallable<RequestT, ResponseT> innerCallable; | ||
|
||
public TracedBatcherUnaryCallable(UnaryCallable innerCallable) { | ||
this.innerCallable = innerCallable; | ||
} | ||
|
||
@Override | ||
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext context) { | ||
if (context.getOption(Batcher.THROTTLED_TIME_KEY) != null) { | ||
ApiTracer tracer = context.getTracer(); | ||
// this should always be true | ||
if (tracer instanceof BigtableTracer) { | ||
((BigtableTracer) tracer) | ||
.batchRequestThrottled(context.getOption(Batcher.THROTTLED_TIME_KEY)); | ||
} | ||
} | ||
return innerCallable.futureCall(request, context); | ||
} | ||
} |
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.