GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — update comments · googleapis/java-bigtable@9c71da9

This repository was archived by the owner on Aug 30, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google-cloud-bigtable/src
    • main/java/com/google/cloud/bigtable/data/v2/stub
      • EnhancedBigtableStub.java
      • metrics
        • BuiltinMetricsTracer.java
        • BuiltinMetricsTracerFactory.java
        • HeaderTracerStreamingCallable.java
        • MetricsTracer.java
    • test/java/com/google/cloud/bigtable/data/v2/stub/metrics
      • BuiltinMetricsTracerTest.java
      • MetricsTracerTest.java
  • pom.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable;
9191
import com.google.cloud.bigtable.data.v2.stub.readrows.RowMergingCallable;
9292
import com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm;
93-
import com.google.cloud.bigtable.stats.StatsWrapper;
9493
import com.google.common.base.MoreObjects;
9594
import com.google.common.base.Preconditions;
9695
import com.google.common.collect.ImmutableList;
@@ -154,7 +153,6 @@ public static EnhancedBigtableStubSettings finalizeSettings(
154153
EnhancedBigtableStubSettings settings, Tagger tagger, StatsRecorder stats)
155154
throws IOException {
156155
EnhancedBigtableStubSettings.Builder builder = settings.toBuilder();
157-
StatsWrapper statsWrapper = StatsWrapper.create();
158156

159157
// TODO: this implementation is on the cusp of unwieldy, if we end up adding more features
160158
// consider splitting it up by feature.
@@ -227,7 +225,7 @@ public static EnhancedBigtableStubSettings finalizeSettings(
227225
.build()),
228226
// Add OpenCensus Metrics
229227
MetricsTracerFactory.create(tagger, stats, attributes),
230-
BuiltinMetricsTracerFactory.create(statsWrapper, builtinAttributes),
228+
BuiltinMetricsTracerFactory.create(builtinAttributes),
231229
// Add user configured tracer
232230
settings.getTracerFactory())));
233231
return builder.build();
Collapse file

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java‎

Copy file name to clipboardExpand all lines: google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java
+9-48Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

18-
import com.google.api.gax.tracing.ApiTracerFactory;
18+
import static com.google.api.gax.tracing.ApiTracerFactory.OperationType;
19+
1920
import com.google.api.gax.tracing.SpanName;
2021
import com.google.cloud.bigtable.stats.StatsRecorderWrapper;
21-
import com.google.cloud.bigtable.stats.StatsWrapper;
22+
import com.google.common.annotations.VisibleForTesting;
2223
import com.google.common.base.Stopwatch;
23-
import java.util.Map;
2424
import java.util.concurrent.CancellationException;
2525
import java.util.concurrent.TimeUnit;
2626
import java.util.concurrent.atomic.AtomicBoolean;
@@ -36,7 +36,7 @@ class BuiltinMetricsTracer extends BigtableTracer {
3636

3737
private final StatsRecorderWrapper recorder;
3838

39-
private final ApiTracerFactory.OperationType operationType;
39+
private final OperationType operationType;
4040
private final SpanName spanName;
4141

4242
// Operation level metrics
@@ -51,8 +51,7 @@ class BuiltinMetricsTracer extends BigtableTracer {
5151

5252
// Total application latency
5353
// Total application latency needs to be atomic because it's accessed from different threads. E.g.
54-
// request() from
55-
// user thread and attempt failed from grpc thread.
54+
// request() from user thread and attempt failed from grpc thread.
5655
private final AtomicLong totalApplicationLatency = new AtomicLong(0);
5756
// Stopwatch is not thread safe so this is a workaround to check if the stopwatch changes is
5857
// flushed to memory.
@@ -67,20 +66,12 @@ class BuiltinMetricsTracer extends BigtableTracer {
6766
// gfe stats
6867
private AtomicLong gfeMissingHeaders = new AtomicLong(0);
6968

69+
@VisibleForTesting
7070
BuiltinMetricsTracer(
71-
ApiTracerFactory.OperationType operationType,
72-
SpanName spanName,
73-
Map<String, String> attributes,
74-
StatsWrapper statsWrapper,
75-
@Nullable StatsRecorderWrapper statsRecorderWrapper) {
71+
OperationType operationType, SpanName spanName, StatsRecorderWrapper recorder) {
7672
this.operationType = operationType;
7773
this.spanName = spanName;
78-
if (statsRecorderWrapper != null) {
79-
// A workaround for test to pass in a mock StatsRecorderWrapper
80-
this.recorder = statsRecorderWrapper;
81-
} else {
82-
this.recorder = new StatsRecorderWrapper(operationType, spanName, attributes, statsWrapper);
83-
}
74+
this.recorder = recorder;
8475
}
8576

8677
@Override
@@ -143,26 +134,6 @@ public void attemptFailed(Throwable error, Duration delay) {
143134
recordAttemptCompletion(error);
144135
}
145136

146-
@Override
147-
public void attemptFailedRetriesExhausted(Throwable error) {
148-
super.attemptFailedRetriesExhausted(error);
149-
}
150-
151-
@Override
152-
public void attemptPermanentFailure(Throwable error) {
153-
super.attemptPermanentFailure(error);
154-
}
155-
156-
@Override
157-
public void lroStartFailed(Throwable error) {
158-
super.lroStartFailed(error);
159-
}
160-
161-
@Override
162-
public void lroStartSucceeded() {
163-
super.lroStartSucceeded();
164-
}
165-
166137
@Override
167138
public void onRequest() {
168139
if (applicationLatencyTimerIsRunning.compareAndSet(true, false)) {
@@ -181,16 +152,6 @@ public void responseReceived() {
181152
}
182153
}
183154

184-
@Override
185-
public void requestSent() {
186-
super.requestSent();
187-
}
188-
189-
@Override
190-
public void batchRequestSent(long elementCount, long requestSize) {
191-
super.batchRequestSent(elementCount, requestSize);
192-
}
193-
194155
@Override
195156
public int getAttempt() {
196157
return attempt;
@@ -235,7 +196,7 @@ private void recordOperationCompletion(@Nullable Throwable status) {
235196

236197
recorder.putOperationLatencies(operationTimer.elapsed(TimeUnit.MILLISECONDS));
237198

238-
if (operationType == ApiTracerFactory.OperationType.ServerStreaming
199+
if (operationType == OperationType.ServerStreaming
239200
&& spanName.getMethodName().equals("ReadRows")) {
240201
recorder.putFirstResponseLatencies(firstResponsePerOpTimer.elapsed(TimeUnit.MILLISECONDS));
241202
}
Collapse file

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerFactory.java‎

Copy file name to clipboardExpand all lines: google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerFactory.java
+6-23Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import com.google.api.gax.tracing.ApiTracerFactory;
2121
import com.google.api.gax.tracing.BaseApiTracerFactory;
2222
import com.google.api.gax.tracing.SpanName;
23-
import com.google.cloud.bigtable.stats.StatsRecorderWrapper;
2423
import com.google.cloud.bigtable.stats.StatsWrapper;
25-
import com.google.common.annotations.VisibleForTesting;
2624
import com.google.common.collect.ImmutableMap;
2725

2826
/**
@@ -33,35 +31,20 @@
3331
public class BuiltinMetricsTracerFactory extends BaseApiTracerFactory {
3432

3533
private final ImmutableMap<String, String> statsAttributes;
36-
private final StatsWrapper statsWrapper;
37-
private final StatsRecorderWrapper statsRecorderWrapper;
3834

39-
public static BuiltinMetricsTracerFactory create(
40-
StatsWrapper statsWrapper, ImmutableMap<String, String> statsAttributes) {
41-
return new BuiltinMetricsTracerFactory(statsWrapper, statsAttributes, null);
35+
public static BuiltinMetricsTracerFactory create(ImmutableMap<String, String> statsAttributes) {
36+
return new BuiltinMetricsTracerFactory(statsAttributes);
4237
}
4338

44-
// A workaround for test to pass in a mock StatsRecorderWrapper
45-
@VisibleForTesting
46-
static BuiltinMetricsTracerFactory createWithRecorder(
47-
StatsWrapper statsWrapper,
48-
ImmutableMap<String, String> statsAttributes,
49-
StatsRecorderWrapper statsRecorderWrapper) {
50-
return new BuiltinMetricsTracerFactory(statsWrapper, statsAttributes, statsRecorderWrapper);
51-
}
52-
53-
private BuiltinMetricsTracerFactory(
54-
StatsWrapper statsWrapper,
55-
ImmutableMap<String, String> statsAttributes,
56-
StatsRecorderWrapper statsRecorderWrapper) {
39+
private BuiltinMetricsTracerFactory(ImmutableMap<String, String> statsAttributes) {
5740
this.statsAttributes = statsAttributes;
58-
this.statsWrapper = statsWrapper;
59-
this.statsRecorderWrapper = statsRecorderWrapper;
6041
}
6142

6243
@Override
6344
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
6445
return new BuiltinMetricsTracer(
65-
operationType, spanName, statsAttributes, statsWrapper, statsRecorderWrapper);
46+
operationType,
47+
spanName,
48+
StatsWrapper.createRecorder(operationType, spanName, statsAttributes));
6649
}
6750
}
Collapse file

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerStreamingCallable.java‎

Copy file name to clipboardExpand all lines: google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerStreamingCallable.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private class HeaderTracerResponseObserver<ResponseT> implements ResponseObserve
8282

8383
@Override
8484
public void onStart(final StreamController controller) {
85-
final StreamController tracedController = new TracedStreamController(controller, tracer);
85+
StreamController tracedController = new TracedStreamController(controller, tracer);
8686
outerObserver.onStart(tracedController);
8787
}
8888

Collapse file

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java‎

Copy file name to clipboardExpand all lines: google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java
-35Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ private void recordOperationCompletion(@Nullable Throwable throwable) {
125125
measures.record(tagCtx.build());
126126
}
127127

128-
@Override
129-
public void connectionSelected(String s) {
130-
// noop: cardinality for connection ids is too high to use as tags
131-
}
132-
133128
@Override
134129
public void attemptStarted(int attemptNumber) {
135130
attempt = attemptNumber;
@@ -180,16 +175,6 @@ private void recordAttemptCompletion(@Nullable Throwable throwable) {
180175
measures.record(tagCtx.build());
181176
}
182177

183-
@Override
184-
public void lroStartFailed(Throwable throwable) {
185-
// noop
186-
}
187-
188-
@Override
189-
public void lroStartSucceeded() {
190-
// noop
191-
}
192-
193178
@Override
194179
public void responseReceived() {
195180
if (firstResponsePerOpTimer.isRunning()) {
@@ -199,16 +184,6 @@ public void responseReceived() {
199184
operationResponseCount++;
200185
}
201186

202-
@Override
203-
public void requestSent() {
204-
// noop: no operations are client streaming
205-
}
206-
207-
@Override
208-
public void batchRequestSent(long elementCount, long requestSize) {
209-
// noop
210-
}
211-
212187
@Override
213188
public int getAttempt() {
214189
return attempt;
@@ -253,14 +228,4 @@ private TagContextBuilder newTagCtxBuilder() {
253228

254229
return tagCtx;
255230
}
256-
257-
@Override
258-
public void setLocations(String zone, String cluster) {
259-
// noop
260-
}
261-
262-
@Override
263-
public void onRequest() {
264-
// noop
265-
}
266231
}
Collapse file

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

Copy file name to clipboardExpand all lines: google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java
+39-5Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

18+
import static com.google.api.gax.tracing.ApiTracerFactory.OperationType;
1819
import static com.google.common.truth.Truth.assertThat;
20+
import static org.mockito.ArgumentMatchers.any;
1921
import static org.mockito.Mockito.times;
2022
import static org.mockito.Mockito.verify;
23+
import static org.mockito.Mockito.when;
2124

2225
import com.google.api.client.util.Lists;
2326
import com.google.api.core.SettableApiFuture;
2427
import com.google.api.gax.rpc.ClientContext;
2528
import com.google.api.gax.rpc.ResponseObserver;
2629
import com.google.api.gax.rpc.StreamController;
30+
import com.google.api.gax.tracing.SpanName;
2731
import com.google.bigtable.v2.BigtableGrpc;
2832
import com.google.bigtable.v2.MutateRowRequest;
2933
import com.google.bigtable.v2.MutateRowResponse;
@@ -37,9 +41,7 @@
3741
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
3842
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
3943
import com.google.cloud.bigtable.stats.StatsRecorderWrapper;
40-
import com.google.cloud.bigtable.stats.StatsWrapper;
4144
import com.google.common.base.Stopwatch;
42-
import com.google.common.collect.ImmutableMap;
4345
import com.google.common.collect.Range;
4446
import com.google.protobuf.ByteString;
4547
import com.google.protobuf.BytesValue;
@@ -59,13 +61,16 @@
5961
import org.junit.Before;
6062
import org.junit.Rule;
6163
import org.junit.Test;
64+
import org.junit.runner.RunWith;
65+
import org.junit.runners.JUnit4;
6266
import org.mockito.ArgumentCaptor;
6367
import org.mockito.Captor;
6468
import org.mockito.Mock;
6569
import org.mockito.junit.MockitoJUnit;
6670
import org.mockito.junit.MockitoRule;
6771
import org.threeten.bp.Duration;
6872

73+
@RunWith(JUnit4.class)
6974
public class BuiltinMetricsTracerTest {
7075
private static final String PROJECT_ID = "fake-project";
7176
private static final String INSTANCE_ID = "fake-instance";
@@ -118,6 +123,7 @@ public class BuiltinMetricsTracerTest {
118123

119124
private EnhancedBigtableStub stub;
120125

126+
@Mock private BuiltinMetricsTracerFactory mockFactory;
121127
@Mock private StatsRecorderWrapper statsRecorderWrapper;
122128

123129
@Captor private ArgumentCaptor<Long> longValue;
@@ -169,9 +175,7 @@ public void sendHeaders(Metadata headers) {
169175
.mutateRowSettings()
170176
.retrySettings()
171177
.setInitialRetryDelay(Duration.ofMillis(200));
172-
stubSettingsBuilder.setTracerFactory(
173-
BuiltinMetricsTracerFactory.createWithRecorder(
174-
StatsWrapper.create(), ImmutableMap.of(), statsRecorderWrapper));
178+
stubSettingsBuilder.setTracerFactory(mockFactory);
175179

176180
EnhancedBigtableStubSettings stubSettings = stubSettingsBuilder.build();
177181
stub = new EnhancedBigtableStub(stubSettings, ClientContext.create(stubSettings));
@@ -185,6 +189,12 @@ public void tearDown() {
185189

186190
@Test
187191
public void testOperationLatencies() {
192+
when(mockFactory.newTracer(any(), any(), any()))
193+
.thenReturn(
194+
new BuiltinMetricsTracer(
195+
OperationType.ServerStreaming,
196+
SpanName.of("Bigtable", "ReadRows"),
197+
statsRecorderWrapper));
188198
Stopwatch stopwatch = Stopwatch.createStarted();
189199
Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID)).iterator());
190200
long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
@@ -196,6 +206,13 @@ public void testOperationLatencies() {
196206

197207
@Test
198208
public void testGfeMetrics() {
209+
when(mockFactory.newTracer(any(), any(), any()))
210+
.thenReturn(
211+
new BuiltinMetricsTracer(
212+
OperationType.ServerStreaming,
213+
SpanName.of("Bigtable", "ReadRows"),
214+
statsRecorderWrapper));
215+
199216
Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID)));
200217

201218
verify(statsRecorderWrapper).putGfeLatencies(longValue.capture());
@@ -207,6 +224,13 @@ public void testGfeMetrics() {
207224

208225
@Test
209226
public void testReadRowsApplicationLatency() throws Exception {
227+
when(mockFactory.newTracer(any(), any(), any()))
228+
.thenReturn(
229+
new BuiltinMetricsTracer(
230+
OperationType.ServerStreaming,
231+
SpanName.of("Bigtable", "ReadRows"),
232+
statsRecorderWrapper));
233+
210234
final long applicationLatency = 1000;
211235
final SettableApiFuture future = SettableApiFuture.create();
212236
final AtomicInteger counter = new AtomicInteger(0);
@@ -258,6 +282,11 @@ public void onComplete() {
258282

259283
@Test
260284
public void testRetryCount() {
285+
when(mockFactory.newTracer(any(), any(), any()))
286+
.thenReturn(
287+
new BuiltinMetricsTracer(
288+
OperationType.Unary, SpanName.of("Bigtable", "MutateRow"), statsRecorderWrapper));
289+
261290
stub.mutateRowCallable()
262291
.call(RowMutation.create(TABLE_ID, "random-row").setCell("cf", "q", "value"));
263292

@@ -268,6 +297,11 @@ public void testRetryCount() {
268297

269298
@Test
270299
public void testMutateRowAttempts() {
300+
when(mockFactory.newTracer(any(), any(), any()))
301+
.thenReturn(
302+
new BuiltinMetricsTracer(
303+
OperationType.Unary, SpanName.of("Bigtable", "MutateRow"), statsRecorderWrapper));
304+
271305
stub.mutateRowCallable()
272306
.call(RowMutation.create(TABLE_ID, "random-row").setCell("cf", "q", "value"));
273307

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.