Skip to content

Commit e0bd6c9

Browse files
authored
fix: rename HeaderTracer callables to BigtableTracer callables (#1276)
* feat: add built in metrics measure and views * remove status from application latency * Rename methods and add comments * update based on comments * feat: update tracers to use built in metrics * update on comments * fix: rename HeaderTracer callables to BigtableTracer callables * deflake test * fix broken test
1 parent df77560 commit e0bd6c9

File tree

6 files changed

+53
-43
lines changed

6 files changed

+53
-43
lines changed

google-cloud-bigtable/clirr-ignored-differences.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@
6161
<className>com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerUnaryCallable</className>
6262
<method>*</method>
6363
</difference>
64+
<!-- InternalApi that was removed -->
65+
<difference>
66+
<differenceType>8001</differenceType>
67+
<className>com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerStreamingCallable</className>
68+
</difference>
69+
<!-- InternalApi that was removed -->
70+
<difference>
71+
<differenceType>8001</differenceType>
72+
<className>com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerUnaryCallable</className>
73+
</difference>
6474
</differences>

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
import com.google.cloud.bigtable.data.v2.models.RowAdapter;
7171
import com.google.cloud.bigtable.data.v2.models.RowMutation;
7272
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
73+
import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerStreamingCallable;
74+
import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerUnaryCallable;
7375
import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTracerFactory;
7476
import com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory;
75-
import com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerStreamingCallable;
76-
import com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable;
7777
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsTracerFactory;
7878
import com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants;
7979
import com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable;
@@ -377,7 +377,7 @@ public <RowT> UnaryCallable<Query, RowT> createReadRowCallable(RowAdapter<RowT>
377377
* <li>Upon receiving the response stream, it will merge the {@link
378378
* com.google.bigtable.v2.ReadRowsResponse.CellChunk}s in logical rows. The actual row
379379
* implementation can be configured by the {@code rowAdapter} parameter.
380-
* <li>Add header tracer for tracking GFE metrics.
380+
* <li>Add bigtable tracer for tracking bigtable specific metrics.
381381
* <li>Retry/resume on failure.
382382
* <li>Filter out marker rows.
383383
* </ul>
@@ -428,13 +428,13 @@ public Map<String, String> extract(ReadRowsRequest readRowsRequest) {
428428
ServerStreamingCallable<ReadRowsRequest, RowT> watched =
429429
Callables.watched(merging, innerSettings, clientContext);
430430

431-
ServerStreamingCallable<ReadRowsRequest, RowT> withHeaderTracer =
432-
new HeaderTracerStreamingCallable<>(watched);
431+
ServerStreamingCallable<ReadRowsRequest, RowT> withBigtableTracer =
432+
new BigtableTracerStreamingCallable<>(watched);
433433

434434
// Retry logic is split into 2 parts to workaround a rare edge case described in
435435
// ReadRowsRetryCompletedCallable
436436
ServerStreamingCallable<ReadRowsRequest, RowT> retrying1 =
437-
new ReadRowsRetryCompletedCallable<>(withHeaderTracer);
437+
new ReadRowsRetryCompletedCallable<>(withBigtableTracer);
438438

439439
ServerStreamingCallable<ReadRowsRequest, RowT> retrying2 =
440440
Callables.retrying(retrying1, innerSettings, clientContext);
@@ -473,11 +473,11 @@ private <RowT> UnaryCallable<Query, List<RowT>> createBulkReadRowsCallable(
473473
UnaryCallable<Query, List<RowT>> tracedBatcher =
474474
new TracedBatcherUnaryCallable<>(readRowsUserCallable.all());
475475

476-
UnaryCallable<Query, List<RowT>> withHeaderTracer =
477-
new HeaderTracerUnaryCallable<>(tracedBatcher);
476+
UnaryCallable<Query, List<RowT>> withBigtableTracer =
477+
new BigtableTracerUnaryCallable<>(tracedBatcher);
478478

479479
UnaryCallable<Query, List<RowT>> traced =
480-
new TracedUnaryCallable<>(withHeaderTracer, clientContext.getTracerFactory(), span);
480+
new TracedUnaryCallable<>(withBigtableTracer, clientContext.getTracerFactory(), span);
481481

482482
return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
483483
}
@@ -519,11 +519,11 @@ public Map<String, String> extract(
519519
UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withStatsHeaders =
520520
new StatsHeadersUnaryCallable<>(spoolable);
521521

522-
UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withHeaderTracer =
523-
new HeaderTracerUnaryCallable<>(withStatsHeaders);
522+
UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withBigtableTracer =
523+
new BigtableTracerUnaryCallable<>(withStatsHeaders);
524524

525525
UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> retryable =
526-
Callables.retrying(withHeaderTracer, settings.sampleRowKeysSettings(), clientContext);
526+
Callables.retrying(withBigtableTracer, settings.sampleRowKeysSettings(), clientContext);
527527

528528
return createUserFacingUnaryCallable(
529529
methodName, new SampleRowKeysCallable(retryable, requestContext));
@@ -558,11 +558,11 @@ public Map<String, String> extract(MutateRowRequest mutateRowRequest) {
558558
UnaryCallable<MutateRowRequest, MutateRowResponse> withStatsHeaders =
559559
new StatsHeadersUnaryCallable<>(base);
560560

561-
UnaryCallable<MutateRowRequest, MutateRowResponse> withHeaderTracer =
562-
new HeaderTracerUnaryCallable<>(withStatsHeaders);
561+
UnaryCallable<MutateRowRequest, MutateRowResponse> withBigtableTracer =
562+
new BigtableTracerUnaryCallable<>(withStatsHeaders);
563563

564564
UnaryCallable<MutateRowRequest, MutateRowResponse> retrying =
565-
Callables.retrying(withHeaderTracer, settings.mutateRowSettings(), clientContext);
565+
Callables.retrying(withBigtableTracer, settings.mutateRowSettings(), clientContext);
566566

567567
return createUserFacingUnaryCallable(
568568
methodName, new MutateRowCallable(retrying, requestContext));
@@ -605,10 +605,10 @@ private UnaryCallable<BulkMutation, Void> createBulkMutateRowsCallable() {
605605
UnaryCallable<BulkMutation, Void> tracedBatcherUnaryCallable =
606606
new TracedBatcherUnaryCallable<>(userFacing);
607607

608-
UnaryCallable<BulkMutation, Void> withHeaderTracer =
609-
new HeaderTracerUnaryCallable<>(tracedBatcherUnaryCallable);
608+
UnaryCallable<BulkMutation, Void> withBigtableTracer =
609+
new BigtableTracerUnaryCallable<>(tracedBatcherUnaryCallable);
610610
UnaryCallable<BulkMutation, Void> traced =
611-
new TracedUnaryCallable<>(withHeaderTracer, clientContext.getTracerFactory(), spanName);
611+
new TracedUnaryCallable<>(withBigtableTracer, clientContext.getTracerFactory(), spanName);
612612

613613
return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
614614
}
@@ -746,11 +746,11 @@ public Map<String, String> extract(
746746
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withStatsHeaders =
747747
new StatsHeadersUnaryCallable<>(base);
748748

749-
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withHeaderTracer =
750-
new HeaderTracerUnaryCallable<>(withStatsHeaders);
749+
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withBigtableTracer =
750+
new BigtableTracerUnaryCallable<>(withStatsHeaders);
751751

752752
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> retrying =
753-
Callables.retrying(withHeaderTracer, settings.checkAndMutateRowSettings(), clientContext);
753+
Callables.retrying(withBigtableTracer, settings.checkAndMutateRowSettings(), clientContext);
754754

755755
return createUserFacingUnaryCallable(
756756
methodName, new CheckAndMutateRowCallable(retrying, requestContext));
@@ -787,11 +787,12 @@ public Map<String, String> extract(ReadModifyWriteRowRequest request) {
787787
new StatsHeadersUnaryCallable<>(base);
788788

789789
String methodName = "ReadModifyWriteRow";
790-
UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> withHeaderTracer =
791-
new HeaderTracerUnaryCallable<>(withStatsHeaders);
790+
UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> withBigtableTracer =
791+
new BigtableTracerUnaryCallable<>(withStatsHeaders);
792792

793793
UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> retrying =
794-
Callables.retrying(withHeaderTracer, settings.readModifyWriteRowSettings(), clientContext);
794+
Callables.retrying(
795+
withBigtableTracer, settings.readModifyWriteRowSettings(), clientContext);
795796

796797
return createUserFacingUnaryCallable(
797798
methodName, new ReadModifyWriteRowCallable(retrying, requestContext));
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@
2828
import javax.annotation.Nonnull;
2929

3030
/**
31-
* This callable will inject a {@link GrpcResponseMetadata} to access the headers and trailers
32-
* returned by gRPC methods upon completion. The {@link BigtableTracer} will process metrics that
33-
* were injected in the header/trailer and publish them to OpenCensus. If {@link
34-
* GrpcResponseMetadata#getMetadata()} returned null, it probably means that the request has never
35-
* reached GFE, and it'll increment the gfe_header_missing_counter in this case.
31+
* This callable will
3632
*
37-
* <p>If GFE metrics are not registered in {@link RpcViews}, skip injecting GrpcResponseMetadata.
38-
* This is for the case where direct path is enabled, all the requests won't go through GFE and
39-
* therefore won't have the server-timing header.
33+
* <p>-inject a {@link GrpcResponseMetadata} to access the headers and trailers returned by gRPC
34+
* methods upon completion. The {@link BigtableTracer} will process metrics that were injected in
35+
* the header/trailer and publish them to OpenCensus. If {@link GrpcResponseMetadata#getMetadata()}
36+
* returned null, it probably means that the request has never reached GFE, and it'll increment the
37+
* gfe_header_missing_counter in this case.
38+
*
39+
* <p>-Call {@link BigtableTracer#onRequest()} to record the request events in a stream.
4040
*
4141
* <p>This class is considered an internal implementation detail and not meant to be used by
4242
* applications.
4343
*/
4444
@InternalApi
45-
public class HeaderTracerStreamingCallable<RequestT, ResponseT>
45+
public class BigtableTracerStreamingCallable<RequestT, ResponseT>
4646
extends ServerStreamingCallable<RequestT, ResponseT> {
4747

4848
private final ServerStreamingCallable<RequestT, ResponseT> innerCallable;
4949

50-
public HeaderTracerStreamingCallable(
50+
public BigtableTracerStreamingCallable(
5151
@Nonnull ServerStreamingCallable<RequestT, ResponseT> callable) {
5252
this.innerCallable = Preconditions.checkNotNull(callable, "Inner callable must be set");
5353
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,16 @@
3434
* GrpcResponseMetadata#getMetadata()} returned null, it probably means that the request has never
3535
* reached GFE, and it'll increment the gfe_header_missing_counter in this case.
3636
*
37-
* <p>If GFE metrics are not registered in {@link RpcViews}, skip injecting GrpcResponseMetadata.
38-
* This is for the case where direct path is enabled, all the requests won't go through GFE and
39-
* therefore won't have the server-timing header.
40-
*
4137
* <p>This class is considered an internal implementation detail and not meant to be used by
4238
* applications.
4339
*/
4440
@InternalApi
45-
public class HeaderTracerUnaryCallable<RequestT, ResponseT>
41+
public class BigtableTracerUnaryCallable<RequestT, ResponseT>
4642
extends UnaryCallable<RequestT, ResponseT> {
4743

4844
private final UnaryCallable<RequestT, ResponseT> innerCallable;
4945

50-
public HeaderTracerUnaryCallable(@Nonnull UnaryCallable<RequestT, ResponseT> innerCallable) {
46+
public BigtableTracerUnaryCallable(@Nonnull UnaryCallable<RequestT, ResponseT> innerCallable) {
5147
this.innerCallable = Preconditions.checkNotNull(innerCallable, "Inner callable must be set");
5248
}
5349

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
import org.junit.runners.JUnit4;
6969

7070
@RunWith(JUnit4.class)
71-
public class HeaderTracerCallableTest {
71+
public class BigtableTracerCallableTest {
7272
private Server server;
7373
private Server serverNoHeader;
7474

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ public void testRetryCount() {
307307
stub.mutateRowCallable()
308308
.call(RowMutation.create(TABLE_ID, "random-row").setCell("cf", "q", "value"));
309309

310-
verify(statsRecorderWrapper).putRetryCount(retryCount.capture());
310+
// onOperationComplete() is called in TracerFinisher which will be called after the mutateRow
311+
// call is returned. So there's a race between when the call returns and when the putRetryCount
312+
// is called in onOperationCompletion().
313+
verify(statsRecorderWrapper, timeout(20)).putRetryCount(retryCount.capture());
311314

312315
assertThat(retryCount.getValue()).isEqualTo(fakeService.getAttemptCounter().get() - 1);
313316
}
@@ -328,7 +331,7 @@ public void testMutateRowAttempts() {
328331
// calls releaseWaiters(). onOperationComplete() is called in TracerFinisher which will be
329332
// called after the mutateRow call is returned. So there's a race between when the call returns
330333
// and when the record() is called in onOperationCompletion().
331-
verify(statsRecorderWrapper, timeout(10).times(fakeService.getAttemptCounter().get() + 1))
334+
verify(statsRecorderWrapper, timeout(20).times(fakeService.getAttemptCounter().get() + 1))
332335
.record(status.capture(), tableId.capture(), zone.capture(), cluster.capture());
333336
assertThat(zone.getAllValues()).containsExactly(UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED);
334337
assertThat(cluster.getAllValues()).containsExactly(UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED);

0 commit comments

Comments
 (0)