From fa7a38b3ac90ffa8e10d7902d60f30c74f002b26 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Mon, 4 Nov 2024 16:26:40 -0500 Subject: [PATCH 1/3] fix: make client side metrics tag in sync with server --- .../data/v2/stub/metrics/BuiltinMetricsTracer.java | 4 ++-- .../cloud/bigtable/data/v2/stub/metrics/Util.java | 14 ++++++++++---- .../v2/stub/metrics/BuiltinMetricsTracerTest.java | 10 +++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java index d4e27ff2ce..8012edfaba 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java @@ -75,9 +75,9 @@ class BuiltinMetricsTracer extends BigtableTracer { private final AtomicInteger requestLeft = new AtomicInteger(0); // Monitored resource labels - private String tableId = "unspecified"; + private String tableId = ""; private String zone = "global"; - private String cluster = "unspecified"; + private String cluster = ""; private final AtomicLong totalClientBlockingTime = new AtomicLong(0); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java index 4c3fd7a42d..590917c814 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java @@ -24,8 +24,10 @@ import com.google.api.gax.rpc.StatusCode.Code; import com.google.bigtable.v2.AuthorizedViewName; import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.GenerateInitialChangeStreamPartitionsRequest; import com.google.bigtable.v2.MutateRowRequest; import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.ReadChangeStreamRequest; import com.google.bigtable.v2.ReadModifyWriteRowRequest; import com.google.bigtable.v2.ReadRowsRequest; import com.google.bigtable.v2.ResponseParams; @@ -127,14 +129,18 @@ static String extractTableId(Object request) { } else if (request instanceof ReadModifyWriteRowRequest) { tableName = ((ReadModifyWriteRowRequest) request).getTableName(); authorizedViewName = ((ReadModifyWriteRowRequest) request).getAuthorizedViewName(); + } else if (request instanceof GenerateInitialChangeStreamPartitionsRequest) { + tableName = ((GenerateInitialChangeStreamPartitionsRequest) request).getTableName(); + } else if (request instanceof ReadChangeStreamRequest) { + tableName = ((ReadChangeStreamRequest) request).getTableName(); } - if (tableName == null && authorizedViewName == null) return "undefined"; - if (tableName.isEmpty() && authorizedViewName.isEmpty()) return "undefined"; - if (!tableName.isEmpty()) { + if (tableName != null && !tableName.isEmpty()) { return TableName.parse(tableName).getTable(); - } else { + } + if (authorizedViewName != null && !authorizedViewName.isEmpty()) { return AuthorizedViewName.parse(authorizedViewName).getTable(); } + return ""; } /** diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java index cec518e2c3..e5e6cee867 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java @@ -381,7 +381,7 @@ public void testGfeMetrics() { .put(STATUS_KEY, "UNAVAILABLE") .put(TABLE_ID_KEY, TABLE) .put(ZONE_ID_KEY, "global") - .put(CLUSTER_ID_KEY, "unspecified") + .put(CLUSTER_ID_KEY, "") .put(METHOD_KEY, "Bigtable.ReadRows") .put(CLIENT_NAME_KEY, CLIENT_NAME) .build(); @@ -535,7 +535,7 @@ public void testMutateRowAttemptsTagValues() { .put(STATUS_KEY, "UNAVAILABLE") .put(TABLE_ID_KEY, TABLE) .put(ZONE_ID_KEY, "global") - .put(CLUSTER_ID_KEY, "unspecified") + .put(CLUSTER_ID_KEY, "") .put(METHOD_KEY, "Bigtable.MutateRow") .put(CLIENT_NAME_KEY, CLIENT_NAME) .put(STREAMING_KEY, false) @@ -605,7 +605,7 @@ public void testMutateRowsRpcError() { .put(STATUS_KEY, "NOT_FOUND") .put(TABLE_ID_KEY, BAD_TABLE_ID) .put(ZONE_ID_KEY, "global") - .put(CLUSTER_ID_KEY, "unspecified") + .put(CLUSTER_ID_KEY, "") .put(METHOD_KEY, "Bigtable.MutateRows") .put(CLIENT_NAME_KEY, CLIENT_NAME) .put(STREAMING_KEY, false) @@ -626,7 +626,7 @@ public void testReadRowsAttemptsTagValues() { .put(STATUS_KEY, "UNAVAILABLE") .put(TABLE_ID_KEY, TABLE) .put(ZONE_ID_KEY, "global") - .put(CLUSTER_ID_KEY, "unspecified") + .put(CLUSTER_ID_KEY, "") .put(METHOD_KEY, "Bigtable.ReadRows") .put(CLIENT_NAME_KEY, CLIENT_NAME) .put(STREAMING_KEY, true) @@ -737,7 +737,7 @@ public void testPermanentFailure() { .toBuilder() .put(STATUS_KEY, "NOT_FOUND") .put(TABLE_ID_KEY, BAD_TABLE_ID) - .put(CLUSTER_ID_KEY, "unspecified") + .put(CLUSTER_ID_KEY, "") .put(ZONE_ID_KEY, "global") .put(STREAMING_KEY, true) .put(METHOD_KEY, "Bigtable.ReadRows") From 66f9e478bd734eff410b1e5b52d8c5da355b12f5 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Wed, 13 Nov 2024 08:49:15 -0500 Subject: [PATCH 2/3] fix test --- .../cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java | 4 ++-- .../cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java index 84ab24f1c8..11da6a6c15 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java @@ -167,9 +167,9 @@ public void testFailure() { assertThat(pointData) .comparingElementsUsing(POINT_DATA_CLUSTER_ID_CONTAINS) - .contains("unspecified"); + .contains(""); assertThat(pointData).comparingElementsUsing(POINT_DATA_ZONE_ID_CONTAINS).contains("global"); - assertThat(clusterAttributes).contains("unspecified"); + assertThat(clusterAttributes).contains(""); assertThat(zoneAttributes).contains("global"); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java index 42adb8ea6e..a6e4f9e88b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java @@ -182,7 +182,7 @@ public void testFailure() throws Exception { assertThat(pointData) .comparingElementsUsing(POINT_DATA_CLUSTER_ID_CONTAINS) - .contains("unspecified"); + .contains(""); assertThat(pointData).comparingElementsUsing(POINT_DATA_ZONE_ID_CONTAINS).contains("global"); List clusterAttributes = pointData.stream() @@ -193,7 +193,7 @@ public void testFailure() throws Exception { .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY)) .collect(Collectors.toList()); - assertThat(clusterAttributes).contains("unspecified"); + assertThat(clusterAttributes).contains(""); assertThat(zoneAttributes).contains("global"); } } From e1d9f131ade10b3b581365a6566079477d9517f4 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 18 Nov 2024 22:51:52 -0500 Subject: [PATCH 3/3] update test from previously merged pr Change-Id: I7fdcac0d3b29e12421f7fd46309cf8a6c80b5f51 --- .../bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java index ada734d460..980b4fd169 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java @@ -777,7 +777,7 @@ public void testRemainingDeadline() { .put(TABLE_ID_KEY, TABLE) .put(METHOD_KEY, "Bigtable.ReadRows") .put(ZONE_ID_KEY, "global") - .put(CLUSTER_ID_KEY, "unspecified") + .put(CLUSTER_ID_KEY, "") .put(STREAMING_KEY, true) .put(CLIENT_NAME_KEY, CLIENT_NAME) .build();