diff --git a/README.md b/README.md
index 1c1a2c985a67..ee2acd7fa530 100644
--- a/README.md
+++ b/README.md
@@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-bigtable'
If you are using Gradle without BOM, add this to your dependencies:
```Groovy
-implementation 'com.google.cloud:google-cloud-bigtable:2.10.3'
+implementation 'com.google.cloud:google-cloud-bigtable:2.11.0'
```
If you are using SBT, add this to your dependencies:
```Scala
-libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.10.3"
+libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.11.0"
```
## Authentication
diff --git a/google-cloud-bigtable-bom/pom.xml b/google-cloud-bigtable-bom/pom.xml
index 8dd219c4d7a9..daaf927cf123 100644
--- a/google-cloud-bigtable-bom/pom.xml
+++ b/google-cloud-bigtable-bom/pom.xml
@@ -9,6 +9,7 @@
com.google.cloud
google-cloud-shared-config
1.5.1
+
Google Cloud Bigtable BOM
diff --git a/google-cloud-bigtable-deps-bom/pom.xml b/google-cloud-bigtable-deps-bom/pom.xml
index a3a90f94db0f..52d87d441a9a 100644
--- a/google-cloud-bigtable-deps-bom/pom.xml
+++ b/google-cloud-bigtable-deps-bom/pom.xml
@@ -8,6 +8,7 @@
com.google.cloud
google-cloud-shared-config
1.5.1
+
com.google.cloud
diff --git a/google-cloud-bigtable-stats/pom.xml b/google-cloud-bigtable-stats/pom.xml
index 78e7cc5fc2a3..dfa00eb8b214 100644
--- a/google-cloud-bigtable-stats/pom.xml
+++ b/google-cloud-bigtable-stats/pom.xml
@@ -59,7 +59,7 @@
com.google.cloud
google-cloud-monitoring
-
+
com.google.http-client
diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml
index d565f746de1c..00014c374df2 100644
--- a/google-cloud-bigtable/pom.xml
+++ b/google-cloud-bigtable/pom.xml
@@ -54,17 +54,25 @@
pom
import
+
+ com.google.cloud
+ google-cloud-monitoring-bom
+ 3.4.1
+ pom
+ import
+
-
com.google.cloud
google-cloud-bigtable-stats
-
+
io.opencensus
@@ -254,6 +262,24 @@
+
+
+ io.grpc
+ grpc-xds
+ runtime
+
+
+ com.google.cloud
+ google-cloud-monitoring
+ test
+
+
+ com.google.api.grpc
+ proto-google-cloud-monitoring-v3
+ test
+
com.google.truth
truth
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java
new file mode 100644
index 000000000000..25ec8e442ee1
--- /dev/null
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2022 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.it;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.TruthJUnit.assume;
+
+import com.google.api.client.util.Lists;
+import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
+import com.google.cloud.bigtable.data.v2.models.Query;
+import com.google.cloud.bigtable.data.v2.models.Row;
+import com.google.cloud.bigtable.data.v2.models.RowMutation;
+import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
+import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
+import com.google.cloud.monitoring.v3.MetricServiceClient;
+import com.google.monitoring.v3.ListTimeSeriesRequest;
+import com.google.monitoring.v3.ListTimeSeriesResponse;
+import com.google.monitoring.v3.ProjectName;
+import com.google.monitoring.v3.TimeInterval;
+import com.google.protobuf.util.Timestamps;
+import java.io.IOException;
+import java.time.Duration;
+import java.util.ArrayList;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class BuiltinMetricsIT {
+ @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule();
+ public static MetricServiceClient metricClient;
+
+ public static String[] VIEWS = {
+ "operation_latencies",
+ "retry_count",
+ "attempt_latencies",
+ "server_latencies",
+ "connectivity_error_count",
+ "application_latencies"
+ };
+
+ @BeforeClass
+ public static void setUpClass() throws IOException {
+ assume()
+ .withMessage("Builtin metrics integration test is not supported by emulator")
+ .that(testEnvRule.env())
+ .isNotInstanceOf(EmulatorEnv.class);
+
+ // Enable built in metrics
+ BigtableDataSettings.enableBuiltinMetrics();
+
+ // Create a cloud monitoring client
+ metricClient = MetricServiceClient.create();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ if (metricClient != null) {
+ metricClient.close();
+ }
+ }
+
+ @Test
+ public void testBuiltinMetrics() throws Exception {
+ // Send a MutateRow and ReadRows request
+ testEnvRule
+ .env()
+ .getDataClient()
+ .mutateRow(
+ RowMutation.create(testEnvRule.env().getTableId(), "a-new-key")
+ .setCell(testEnvRule.env().getFamilyId(), "q", "abc"));
+ ArrayList rows =
+ Lists.newArrayList(
+ testEnvRule
+ .env()
+ .getDataClient()
+ .readRows(Query.create(testEnvRule.env().getTableId()).limit(10)));
+
+ // Sleep 5 minutes so the metrics could be published and precomputation is done
+ Thread.sleep(Duration.ofMinutes(5).toMillis());
+
+ ProjectName name = ProjectName.of(testEnvRule.env().getProjectId());
+
+ // Restrict time to last 10 minutes
+ long startMillis = System.currentTimeMillis() - Duration.ofMinutes(10).toMillis();
+ TimeInterval interval =
+ TimeInterval.newBuilder()
+ .setStartTime(Timestamps.fromMillis(startMillis))
+ .setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
+ .build();
+
+ for (String view : VIEWS) {
+ // Filter on instance and method name
+ // Verify that metrics are published for MutateRow request
+ String metricFilter =
+ String.format(
+ "metric.type=\"bigtable.googleapis.com/client/%s\" "
+ + "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.MutateRow\"",
+ view, testEnvRule.env().getInstanceId());
+ ListTimeSeriesRequest.Builder requestBuilder =
+ ListTimeSeriesRequest.newBuilder()
+ .setName(name.toString())
+ .setFilter(metricFilter)
+ .setInterval(interval)
+ .setView(ListTimeSeriesRequest.TimeSeriesView.FULL);
+ ListTimeSeriesResponse response =
+ metricClient.listTimeSeriesCallable().call(requestBuilder.build());
+ assertThat(response.getTimeSeriesCount()).isGreaterThan(0);
+
+ // Verify that metrics are published for ReadRows request
+ metricFilter =
+ String.format(
+ "metric.type=\"bigtable.googleapis.com/client/operation_latencies\" "
+ + "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.ReadRows\"",
+ testEnvRule.env().getInstanceId());
+ requestBuilder.setFilter(metricFilter);
+ response = metricClient.listTimeSeriesCallable().call(requestBuilder.build());
+ assertThat(response.getTimeSeriesCount()).isGreaterThan(0);
+ }
+ }
+}
diff --git a/pom.xml b/pom.xml
index b4d3e20b294e..88ca1199c540 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,7 @@
com.google.cloud
google-cloud-shared-config
1.5.3
+
@@ -339,6 +340,22 @@
+
+
+
+ with-shaded
+
+
+ !skip-shaded
+
+
+
+ google-cloud-bigtable-stats
+
+
@@ -347,7 +364,6 @@
grpc-google-cloud-bigtable-v2
proto-google-cloud-bigtable-admin-v2
proto-google-cloud-bigtable-v2
- google-cloud-bigtable-stats
google-cloud-bigtable-emulator-core
google-cloud-bigtable-emulator
google-cloud-bigtable-bom