Visitar URL original
Merge branch 'main' into renovate/shared-dependencies · googleapis/java-bigtable@206c61b · GitHub
Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

Commit 206c61b

Browse files
Merge branch 'main' into renovate/shared-dependencies
2 parents 25fdc13 + 4d3a7e6 commit 206c61b

5 files changed

Lines changed: 375 additions & 85 deletions

File tree

‎.readme-partials.yml‎

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -149,82 +149,9 @@ custom_content: |
149149
[CustomOpenTelemetryMetricsProvider](https://github.com/googleapis/java-bigtable/blob/main/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CustomOpenTelemetryMetricsProvider.java)
150150
on how to set it up.
151151
152-
## Client request tracing: OpenCensus Tracing
153-
154-
Cloud Bigtable client supports [OpenCensus Tracing](https://opencensus.io/tracing/),
155-
which gives insight into the client internals and aids in debugging production issues.
156-
By default, the functionality is disabled. For example to enable tracing using
157-
[Google Stackdriver](https://cloud.google.com/trace/docs/):
158-
159-
[//]: # (TODO: figure out how to keep opencensus version in sync with pom.xml)
160-
161-
If you are using Maven, add this to your pom.xml file
162-
```xml
163-
<dependency>
164-
<groupId>io.opencensus</groupId>
165-
<artifactId>opencensus-impl</artifactId>
166-
<version>0.31.1</version>
167-
<scope>runtime</scope>
168-
</dependency>
169-
<dependency>
170-
<groupId>io.opencensus</groupId>
171-
<artifactId>opencensus-exporter-trace-stackdriver</artifactId>
172-
<version>0.31.1</version>
173-
<exclusions>
174-
<exclusion>
175-
<groupId>io.grpc</groupId>
176-
<artifactId>*</artifactId>
177-
</exclusion>
178-
<exclusion>
179-
<groupId>com.google.auth</groupId>
180-
<artifactId>*</artifactId>
181-
</exclusion>
182-
</exclusions>
183-
</dependency>
184-
```
185-
If you are using Gradle, add this to your dependencies
186-
```Groovy
187-
compile 'io.opencensus:opencensus-impl:0.24.0'
188-
compile 'io.opencensus:opencensus-exporter-trace-stackdriver:0.24.0'
189-
```
190-
If you are using SBT, add this to your dependencies
191-
```Scala
192-
libraryDependencies += "io.opencensus" % "opencensus-impl" % "0.24.0"
193-
libraryDependencies += "io.opencensus" % "opencensus-exporter-trace-stackdriver" % "0.24.0"
194-
```
195-
196-
At the start of your application configure the exporter:
197-
198-
```java
199-
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceConfiguration;
200-
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter;
201-
202-
StackdriverTraceExporter.createAndRegister(
203-
StackdriverTraceConfiguration.builder()
204-
.setProjectId("YOUR_PROJECT_ID")
205-
.build());
206-
```
207-
208-
You can view the traces on the Google Cloud Platform Console
209-
[Trace](https://console.cloud.google.com/traces) page.
210-
211-
By default traces are [sampled](https://opencensus.io/tracing/sampling) at a rate of about 1/10,000.
212-
You can configure a higher rate by updating the active tracing params:
213-
214-
```java
215-
import io.opencensus.trace.Tracing;
216-
import io.opencensus.trace.samplers.Samplers;
217-
218-
Tracing.getTraceConfig().updateActiveTraceParams(
219-
Tracing.getTraceConfig().getActiveTraceParams().toBuilder()
220-
.setSampler(Samplers.probabilitySampler(0.01))
221-
.build()
222-
);
223-
```
224-
225152
### Disable Bigtbale traces
226153
227-
If your application already has OpenCensus Tracing integration and you want to disable Bigtable
154+
If your application already has tracing integration and you want to disable Bigtable
228155
traces, you can do the following:
229156
230157
```java

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public static Builder newBuilderForEmulator(String hostname, int port) {
146146
}
147147

148148
/**
149+
* @deprecated OpenCensus support is deprecated and will be removed in a future version
149150
* Enables OpenCensus metric aggregations.
150151
*
151152
* <p>This will register Bigtable client relevant {@link io.opencensus.stats.View}s. When coupled
@@ -179,7 +180,7 @@ public static Builder newBuilderForEmulator(String hostname, int port) {
179180
* BigtableDataSettings.enableOpenCensusStats();
180181
* }</pre>
181182
*/
182-
@BetaApi("OpenCensus stats integration is currently unstable and may change in the future")
183+
@Deprecated
183184
public static void enableOpenCensusStats() {
184185
com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientViews();
185186
// TODO(igorbernstein): Enable grpc views once we upgrade to grpc-java 1.24.0
@@ -188,15 +189,14 @@ public static void enableOpenCensusStats() {
188189
}
189190

190191
/**
191-
* Enables OpenCensus GFE metric aggregations.
192-
*
193-
* <p>This will register views for gfe_latency and gfe_header_missing_count metrics.
194-
*
195-
* <p>gfe_latency measures the latency between Google's network receives an RPC and reads back the
196-
* 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.
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.
198198
*/
199-
@BetaApi("OpenCensus stats integration is currently unstable and may change in the future")
199+
@Deprecated
200200
public static void enableGfeOpenCensusStats() {
201201
com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientGfeViews();
202202
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

18-
import com.google.api.core.BetaApi;
1918
import com.google.common.annotations.VisibleForTesting;
2019
import com.google.common.collect.ImmutableSet;
2120
import io.opencensus.stats.Stats;
2221
import io.opencensus.stats.View;
2322
import io.opencensus.stats.ViewManager;
2423

25-
@BetaApi
24+
@Deprecated
2625
public class RpcViews {
2726
@VisibleForTesting
2827
private static final ImmutableSet<View> BIGTABLE_CLIENT_VIEWS_SET =
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigtable.admin.v2.it;
18+
19+
import static com.google.common.truth.Truth.assertWithMessage;
20+
import static com.google.common.truth.TruthJUnit.assume;
21+
import static org.junit.Assert.fail;
22+
23+
import com.google.api.gax.rpc.NotFoundException;
24+
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient;
25+
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
26+
import com.google.cloud.bigtable.admin.v2.models.CreateLogicalViewRequest;
27+
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
28+
import com.google.cloud.bigtable.admin.v2.models.LogicalView;
29+
import com.google.cloud.bigtable.admin.v2.models.Table;
30+
import com.google.cloud.bigtable.admin.v2.models.UpdateLogicalViewRequest;
31+
import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
32+
import com.google.cloud.bigtable.test_helpers.env.PrefixGenerator;
33+
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
34+
import io.grpc.StatusRuntimeException;
35+
import java.util.List;
36+
import java.util.logging.Logger;
37+
import org.junit.Before;
38+
import org.junit.BeforeClass;
39+
import org.junit.ClassRule;
40+
import org.junit.Rule;
41+
import org.junit.Test;
42+
import org.junit.runner.RunWith;
43+
import org.junit.runners.JUnit4;
44+
45+
@RunWith(JUnit4.class)
46+
public class BigtableLogicalViewIT {
47+
@ClassRule public static final TestEnvRule testEnvRule = new TestEnvRule();
48+
@Rule public final PrefixGenerator prefixGenerator = new PrefixGenerator();
49+
private static final Logger LOGGER = Logger.getLogger(BigtableLogicalViewIT.class.getName());
50+
private static final int[] BACKOFF_DURATION = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
51+
52+
private static BigtableInstanceAdminClient client;
53+
private static Table testTable;
54+
55+
private String instanceId = testEnvRule.env().getInstanceId();
56+
57+
// TODO: Update this test once emulator supports InstanceAdmin operation
58+
// https://github.com/googleapis/google-cloud-go/issues/1069
59+
@BeforeClass
60+
public static void validatePlatform() {
61+
assume()
62+
.withMessage("BigtableInstanceAdminClient doesn't support on Emulator")
63+
.that(testEnvRule.env())
64+
.isNotInstanceOf(EmulatorEnv.class);
65+
}
66+
67+
@Before
68+
public void setUp() throws InterruptedException {
69+
client = testEnvRule.env().getInstanceAdminClient();
70+
testTable = createTestTable(testEnvRule.env().getTableAdminClient());
71+
}
72+
73+
@Test
74+
public void createLogicalViewAndGetLogicalViewTest() {
75+
String logicalViewId = "createLogicalViewAndGetLogicalViewTest-logical-view";
76+
77+
CreateLogicalViewRequest request =
78+
CreateLogicalViewRequest.of(instanceId, logicalViewId).setQuery(getQuery());
79+
try {
80+
LogicalView response = client.createLogicalView(request);
81+
assertWithMessage("Got wrong logical view Id in CreateLogicalView")
82+
.that(response.getId())
83+
.isEqualTo(logicalViewId);
84+
assertWithMessage("Got wrong query in CreateLogicalView")
85+
.that(response.getQuery())
86+
.isEqualTo(getQuery());
87+
88+
response = client.getLogicalView(instanceId, logicalViewId);
89+
assertWithMessage("Got wrong logical view Id in getLogicalView")
90+
.that(response.getId())
91+
.isEqualTo(logicalViewId);
92+
assertWithMessage("Got wrong query in getLogicalView")
93+
.that(response.getQuery())
94+
.isEqualTo(getQuery());
95+
} finally {
96+
client.deleteLogicalView(instanceId, logicalViewId);
97+
}
98+
}
99+
100+
@Test
101+
public void listLogicalViewsTest() {
102+
String logicalViewId = "listLogicalViewsTest-logical-view";
103+
104+
try {
105+
LogicalView logicalView = client.createLogicalView(createLogicalViewRequest(logicalViewId));
106+
107+
List<LogicalView> response = client.listLogicalViews(instanceId);
108+
assertWithMessage("Got wrong logical view Ids in listLogicalViews")
109+
.that(response)
110+
.contains(logicalView);
111+
} finally {
112+
client.deleteLogicalView(instanceId, logicalViewId);
113+
}
114+
}
115+
116+
@Test
117+
public void updateLogicalViewAndDeleteLogicalViewTest() throws InterruptedException {
118+
String logicalViewId = "updateLogicalViewAndDeleteLogicalViewTest-logical-view";
119+
120+
// Create a logical view.
121+
CreateLogicalViewRequest request = createLogicalViewRequest(logicalViewId);
122+
123+
LogicalView response = client.createLogicalView(request);
124+
125+
// Update the query of the logical view.
126+
String query = "SELECT 1 AS value";
127+
UpdateLogicalViewRequest updateRequest = UpdateLogicalViewRequest.of(response).setQuery(query);
128+
response = client.updateLogicalView(updateRequest);
129+
assertWithMessage("Got wrong query in UpdateLogicalView")
130+
.that(response.getQuery())
131+
.isEqualTo(query);
132+
133+
// Now we should be able to successfully delete the LogicalView.
134+
client.deleteLogicalView(instanceId, logicalViewId);
135+
try {
136+
for (int i = 0; i < BACKOFF_DURATION.length; i++) {
137+
client.getLogicalView(instanceId, logicalViewId);
138+
139+
LOGGER.info(
140+
"Wait for "
141+
+ BACKOFF_DURATION[i]
142+
+ " seconds for deleting logical view "
143+
+ logicalViewId);
144+
Thread.sleep(BACKOFF_DURATION[i] * 1000);
145+
}
146+
fail("LogicalView was not deleted.");
147+
} catch (NotFoundException e) {
148+
assertWithMessage("Incorrect exception type")
149+
.that(e.getCause())
150+
.isInstanceOf(StatusRuntimeException.class);
151+
}
152+
}
153+
154+
private CreateLogicalViewRequest createLogicalViewRequest(String logicalViewId) {
155+
return CreateLogicalViewRequest.of(instanceId, logicalViewId).setQuery(getQuery());
156+
}
157+
158+
private String getQuery() {
159+
return "SELECT _key, cf1['column'] as column FROM `" + testTable.getId() + "`";
160+
}
161+
162+
private static Table createTestTable(BigtableTableAdminClient tableAdmin)
163+
throws InterruptedException {
164+
String tableId = PrefixGenerator.newPrefix("BigtableLogicalViewIT#createTestTable");
165+
Table testTable = tableAdmin.createTable(CreateTableRequest.of(tableId).addFamily("cf1"));
166+
167+
return testTable;
168+
}
169+
}

0 commit comments

Comments
 (0)