Skip to content

Commit 82d881f

Browse files
Revert "chore!: Remove opencensus (#2568)" (#2580)
* Revert "chore!: Remove opencensus (#2568)" This reverts commit 7a46352. * removing unrelated change
1 parent 7a46352 commit 82d881f

20 files changed

+2305
-32
lines changed

google-cloud-bigtable-deps-bom/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
<type>pom</type>
7979
<scope>import</scope>
8080
</dependency>
81+
<!-- Other opencensus packages' versions are pulled through com.google.cloud:third-party-dependencies, but has to be manually specified for this one. -->
82+
<dependency>
83+
<groupId>io.opencensus</groupId>
84+
<artifactId>opencensus-contrib-resource-util</artifactId>
85+
<version>0.31.1</version>
86+
</dependency>
8187
</dependencies>
8288
</dependencyManagement>
8389

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -382,23 +382,4 @@
382382
<method>*</method>
383383
<to>*</to>
384384
</difference>
385-
<!-- OpenCensus removal -->
386-
<difference>
387-
<differenceType>7002</differenceType>
388-
<className>com/google/cloud/bigtable/data/v2/BigtableDataSettings</className>
389-
<method>*OpenCensusStats*</method>
390-
</difference>
391-
<difference>
392-
<differenceType>8001</differenceType>
393-
<className>com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerFactory*</className>
394-
</difference>
395-
<difference>
396-
<differenceType>8001</differenceType>
397-
<className>com/google/cloud/bigtable/data/v2/stub/metrics/RpcMeasureConstants*</className>
398-
</difference>
399-
<difference>
400-
<differenceType>8001</differenceType>
401-
<className>com/google/cloud/bigtable/data/v2/stub/metrics/RpcViews*</className>
402-
</difference>
403-
<!-- /OpenCensus removal -->
404385
</differences>

google-cloud-bigtable/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@
138138
<groupId>com.google.code.gson</groupId>
139139
<artifactId>gson</artifactId>
140140
</dependency>
141+
<dependency>
142+
<groupId>io.opencensus</groupId>
143+
<artifactId>opencensus-api</artifactId>
144+
</dependency>
141145
<dependency>
142146
<groupId>io.grpc</groupId>
143147
<artifactId>grpc-alts</artifactId>
@@ -180,6 +184,10 @@
180184
<groupId>io.grpc</groupId>
181185
<artifactId>grpc-util</artifactId>
182186
</dependency>
187+
<dependency>
188+
<groupId>io.grpc</groupId>
189+
<artifactId>grpc-core</artifactId>
190+
</dependency>
183191
<dependency>
184192
<groupId>io.grpc</groupId>
185193
<artifactId>grpc-googleapis</artifactId>
@@ -316,6 +324,11 @@
316324
<artifactId>grpc-testing</artifactId>
317325
<scope>test</scope>
318326
</dependency>
327+
<dependency>
328+
<groupId>io.opencensus</groupId>
329+
<artifactId>opencensus-impl</artifactId>
330+
<scope>test</scope>
331+
</dependency>
319332
<dependency>
320333
<groupId>junit</groupId>
321334
<artifactId>junit</artifactId>
@@ -696,6 +709,20 @@
696709
</dependencies>
697710
</plugin>
698711

712+
<plugin>
713+
<groupId>org.apache.maven.plugins</groupId>
714+
<artifactId>maven-dependency-plugin</artifactId>
715+
<configuration>
716+
<!--
717+
grpc-auth is not directly used transitively, but is pulled to align with other grpc parts
718+
opencensus-impl-core is brought in transitively through opencensus-impl
719+
-->
720+
<ignoredUsedUndeclaredDependencies>
721+
<ignoredUsedUndeclaredDependency>io.opencensus:opencensus-impl-core</ignoredUsedUndeclaredDependency>
722+
</ignoredUsedUndeclaredDependencies>
723+
</configuration>
724+
</plugin>
725+
699726
<plugin>
700727
<artifactId>maven-failsafe-plugin</artifactId>
701728
<configuration>

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,62 @@ public static Builder newBuilderForEmulator(String hostname, int port) {
145145
return builder;
146146
}
147147

148+
/**
149+
* @deprecated OpenCensus support is deprecated and will be removed in a future version
150+
* Enables OpenCensus metric aggregations.
151+
*
152+
* <p>This will register Bigtable client relevant {@link io.opencensus.stats.View}s. When coupled
153+
* with an exporter, it allows users to monitor client behavior.
154+
*
155+
* <p>Please note that in addition to calling this method, the application must:
156+
* <ul>
157+
* <li>Include openensus-impl dependency on the classpath
158+
* <li>Configure an exporter like opencensus-exporter-stats-stackdriver
159+
* </ul>
160+
*
161+
* <p>Example usage for maven:
162+
* <pre>{@code
163+
* <dependency>
164+
* <groupId>io.opencensus</groupId>
165+
* <artifactId>opencensus-impl</artifactId>
166+
* <version>${opencensus.version}</version>
167+
* <scope>runtime</scope>
168+
* </dependency>
169+
*
170+
* <dependency>
171+
* <groupId>io.opencensus</groupId>
172+
* <artifactId>opencensus-exporter-stats-stackdriver</artifactId>
173+
* <version>${opencensus.version}</version>
174+
* </dependency>
175+
* </pre>
176+
*
177+
* Java:
178+
* <pre>{@code
179+
* StackdriverStatsExporter.createAndRegister();
180+
* BigtableDataSettings.enableOpenCensusStats();
181+
* }</pre>
182+
*/
183+
@Deprecated
184+
public static void enableOpenCensusStats() {
185+
com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientViews();
186+
// TODO(igorbernstein): Enable grpc views once we upgrade to grpc-java 1.24.0
187+
// Required change: https://github.com/grpc/grpc-java/pull/5996
188+
// io.opencensus.contrib.grpc.metrics.RpcViews.registerClientGrpcBasicViews();
189+
}
190+
191+
/**
192+
* @deprecated OpenCensus support is deprecated and will be removed in a future version Enables
193+
* OpenCensus GFE metric aggregations.
194+
* <p>This will register views for gfe_latency and gfe_header_missing_count metrics.
195+
* <p>gfe_latency measures the latency between Google's network receives an RPC and reads back
196+
* the first byte of the response. gfe_header_missing_count is a counter of the number of RPC
197+
* responses received without the server-timing header.
198+
*/
199+
@Deprecated
200+
public static void enableGfeOpenCensusStats() {
201+
com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientGfeViews();
202+
}
203+
148204
/**
149205
* Register built in metrics.
150206
*

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

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.api.gax.batching.BatcherImpl;
2929
import com.google.api.gax.batching.FlowController;
3030
import com.google.api.gax.core.BackgroundResource;
31+
import com.google.api.gax.grpc.GaxGrpcProperties;
3132
import com.google.api.gax.grpc.GrpcCallContext;
3233
import com.google.api.gax.grpc.GrpcCallSettings;
3334
import com.google.api.gax.grpc.GrpcRawCallableFactory;
@@ -47,6 +48,7 @@
4748
import com.google.api.gax.rpc.UnaryCallSettings;
4849
import com.google.api.gax.rpc.UnaryCallable;
4950
import com.google.api.gax.tracing.ApiTracerFactory;
51+
import com.google.api.gax.tracing.OpencensusTracerFactory;
5052
import com.google.api.gax.tracing.SpanName;
5153
import com.google.api.gax.tracing.TracedServerStreamingCallable;
5254
import com.google.api.gax.tracing.TracedUnaryCallable;
@@ -98,6 +100,8 @@
98100
import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerUnaryCallable;
99101
import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTracerFactory;
100102
import com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory;
103+
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsTracerFactory;
104+
import com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants;
101105
import com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable;
102106
import com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable;
103107
import com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable;
@@ -122,6 +126,7 @@
122126
import com.google.cloud.bigtable.data.v2.stub.sql.SqlRowMergingCallable;
123127
import com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm;
124128
import com.google.cloud.bigtable.gaxx.retrying.RetryInfoRetryAlgorithm;
129+
import com.google.common.annotations.VisibleForTesting;
125130
import com.google.common.base.Functions;
126131
import com.google.common.base.MoreObjects;
127132
import com.google.common.base.Preconditions;
@@ -130,6 +135,12 @@
130135
import com.google.common.util.concurrent.MoreExecutors;
131136
import com.google.protobuf.ByteString;
132137
import io.grpc.MethodDescriptor;
138+
import io.opencensus.stats.Stats;
139+
import io.opencensus.stats.StatsRecorder;
140+
import io.opencensus.tags.TagKey;
141+
import io.opencensus.tags.TagValue;
142+
import io.opencensus.tags.Tagger;
143+
import io.opencensus.tags.Tags;
133144
import io.opentelemetry.api.OpenTelemetry;
134145
import io.opentelemetry.api.common.Attributes;
135146
import java.io.IOException;
@@ -215,11 +226,47 @@ public static BigtableClientContext createBigtableClientContext(
215226
public static ApiTracerFactory createBigtableTracerFactory(
216227
EnhancedBigtableStubSettings settings, @Nullable OpenTelemetry openTelemetry)
217228
throws IOException {
229+
return createBigtableTracerFactory(
230+
settings, Tags.getTagger(), Stats.getStatsRecorder(), openTelemetry);
231+
}
218232

219-
ImmutableList.Builder<ApiTracerFactory> tracerFactories = ImmutableList.builder();
220-
221-
tracerFactories.add(settings.getTracerFactory());
233+
@VisibleForTesting
234+
public static ApiTracerFactory createBigtableTracerFactory(
235+
EnhancedBigtableStubSettings settings,
236+
Tagger tagger,
237+
StatsRecorder stats,
238+
@Nullable OpenTelemetry openTelemetry)
239+
throws IOException {
240+
String projectId = settings.getProjectId();
241+
String instanceId = settings.getInstanceId();
242+
String appProfileId = settings.getAppProfileId();
243+
244+
ImmutableMap<TagKey, TagValue> attributes =
245+
ImmutableMap.<TagKey, TagValue>builder()
246+
.put(RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(projectId))
247+
.put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID, TagValue.create(instanceId))
248+
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(appProfileId))
249+
.build();
222250

251+
ImmutableList.Builder<ApiTracerFactory> tracerFactories = ImmutableList.builder();
252+
tracerFactories
253+
.add(
254+
// Add OpenCensus Tracing
255+
new OpencensusTracerFactory(
256+
ImmutableMap.<String, String>builder()
257+
// Annotate traces with the same tags as metrics
258+
.put(RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(), projectId)
259+
.put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(), instanceId)
260+
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), appProfileId)
261+
// Also annotate traces with library versions
262+
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
263+
.put("grpc", GaxGrpcProperties.getGrpcVersion())
264+
.put("gapic", Version.VERSION)
265+
.build()))
266+
// Add OpenCensus Metrics
267+
.add(MetricsTracerFactory.create(tagger, stats, attributes))
268+
// Add user configured tracer
269+
.add(settings.getTracerFactory());
223270
BuiltinMetricsTracerFactory builtinMetricsTracerFactory =
224271
openTelemetry != null
225272
? BuiltinMetricsTracerFactory.create(openTelemetry, createBuiltinAttributes(settings))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* This callable will
3232
* <li>-Inject a {@link GrpcResponseMetadata} to access the headers returned by gRPC methods upon
3333
* completion. The {@link BigtableTracer} will process metrics that were injected in the
34-
* header/trailer and publish them. If {@link GrpcResponseMetadata#getMetadata()} returned null,
35-
* it probably means that the request has never reached GFE, and it'll increment the
36-
* gfe_header_missing_counter in this case.
34+
* header/trailer and publish them to OpenCensus. If {@link GrpcResponseMetadata#getMetadata()}
35+
* returned null, it probably means that the request has never reached GFE, and it'll increment
36+
* the gfe_header_missing_counter in this case.
3737
* <li>-This class will also access trailers from {@link GrpcResponseMetadata} to record zone and
3838
* cluster ids.
3939
* <li>-Call {@link BigtableTracer#onRequest(int)} to record the request events in a stream.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
* This callable will:
3131
* <li>- Inject a {@link GrpcResponseMetadata} to access the headers returned by gRPC methods upon
3232
* completion. The {@link BigtableTracer} will process metrics that were injected in the
33-
* header/trailer and publish them. If {@link GrpcResponseMetadata#getMetadata()} returned null,
34-
* it probably means that the request has never reached GFE, and it'll increment the
35-
* gfe_header_missing_counter in this case.
33+
* header/trailer and publish them to OpenCensus. If {@link GrpcResponseMetadata#getMetadata()}
34+
* returned null, it probably means that the request has never reached GFE, and it'll increment
35+
* the gfe_header_missing_counter in this case.
3636
* <li>-This class will also access trailers from {@link GrpcResponseMetadata} to record zone and
3737
* cluster ids.
3838
* <li>-This class will also inject a {@link BigtableGrpcStreamTracer} that'll record the time an

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ static TransportAttrs create(@Nullable String locality, @Nullable String backend
122122

123123
private TransportAttrs transportAttrs = null;
124124

125-
// Server histogram buckets use [start, end), however OpenTelemetry uses (start, end]. To work
126-
// around this, we measure all the latencies in nanoseconds and convert them
125+
// OpenCensus (and server) histogram buckets use [start, end), however OpenTelemetry uses (start,
126+
// end]. To work around this, we measure all the latencies in nanoseconds and convert them
127127
// to milliseconds and use DoubleHistogram. This should minimize the chance of a data
128128
// point fall on the bucket boundary that causes off by one errors.
129129
private final DoubleHistogram operationLatenciesHistogram;

0 commit comments

Comments
 (0)