Skip to content

Commit bba4183

Browse files
authored
fix: make client side metrics tag in sync with server (#2401)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Rollback plan is reviewed and LGTMed - [ ] All new data plane features have a completed end to end testing plan Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 2088a39 commit bba4183

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class BuiltinMetricsTracer extends BigtableTracer {
7979
private final AtomicInteger requestLeft = new AtomicInteger(0);
8080

8181
// Monitored resource labels
82-
private String tableId = "unspecified";
82+
private String tableId = "<unspecified>";
8383
private String zone = "global";
84-
private String cluster = "unspecified";
84+
private String cluster = "<unspecified>";
8585

8686
private final AtomicLong totalClientBlockingTime = new AtomicLong(0);
8787

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import com.google.api.gax.rpc.StatusCode.Code;
2525
import com.google.bigtable.v2.AuthorizedViewName;
2626
import com.google.bigtable.v2.CheckAndMutateRowRequest;
27+
import com.google.bigtable.v2.GenerateInitialChangeStreamPartitionsRequest;
2728
import com.google.bigtable.v2.MutateRowRequest;
2829
import com.google.bigtable.v2.MutateRowsRequest;
30+
import com.google.bigtable.v2.ReadChangeStreamRequest;
2931
import com.google.bigtable.v2.ReadModifyWriteRowRequest;
3032
import com.google.bigtable.v2.ReadRowsRequest;
3133
import com.google.bigtable.v2.ResponseParams;
@@ -127,14 +129,18 @@ static String extractTableId(Object request) {
127129
} else if (request instanceof ReadModifyWriteRowRequest) {
128130
tableName = ((ReadModifyWriteRowRequest) request).getTableName();
129131
authorizedViewName = ((ReadModifyWriteRowRequest) request).getAuthorizedViewName();
132+
} else if (request instanceof GenerateInitialChangeStreamPartitionsRequest) {
133+
tableName = ((GenerateInitialChangeStreamPartitionsRequest) request).getTableName();
134+
} else if (request instanceof ReadChangeStreamRequest) {
135+
tableName = ((ReadChangeStreamRequest) request).getTableName();
130136
}
131-
if (tableName == null && authorizedViewName == null) return "undefined";
132-
if (tableName.isEmpty() && authorizedViewName.isEmpty()) return "undefined";
133-
if (!tableName.isEmpty()) {
137+
if (tableName != null && !tableName.isEmpty()) {
134138
return TableName.parse(tableName).getTable();
135-
} else {
139+
}
140+
if (authorizedViewName != null && !authorizedViewName.isEmpty()) {
136141
return AuthorizedViewName.parse(authorizedViewName).getTable();
137142
}
143+
return "<unspecified>";
138144
}
139145

140146
/**

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public void testFailure() {
167167

168168
assertThat(pointData)
169169
.comparingElementsUsing(POINT_DATA_CLUSTER_ID_CONTAINS)
170-
.contains("unspecified");
170+
.contains("<unspecified>");
171171
assertThat(pointData).comparingElementsUsing(POINT_DATA_ZONE_ID_CONTAINS).contains("global");
172-
assertThat(clusterAttributes).contains("unspecified");
172+
assertThat(clusterAttributes).contains("<unspecified>");
173173
assertThat(zoneAttributes).contains("global");
174174
}
175175
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void testFailure() throws Exception {
182182

183183
assertThat(pointData)
184184
.comparingElementsUsing(POINT_DATA_CLUSTER_ID_CONTAINS)
185-
.contains("unspecified");
185+
.contains("<unspecified>");
186186
assertThat(pointData).comparingElementsUsing(POINT_DATA_ZONE_ID_CONTAINS).contains("global");
187187
List<String> clusterAttributes =
188188
pointData.stream()
@@ -193,7 +193,7 @@ public void testFailure() throws Exception {
193193
.map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY))
194194
.collect(Collectors.toList());
195195

196-
assertThat(clusterAttributes).contains("unspecified");
196+
assertThat(clusterAttributes).contains("<unspecified>");
197197
assertThat(zoneAttributes).contains("global");
198198
}
199199
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public void testGfeMetrics() {
395395
.put(STATUS_KEY, "UNAVAILABLE")
396396
.put(TABLE_ID_KEY, TABLE)
397397
.put(ZONE_ID_KEY, "global")
398-
.put(CLUSTER_ID_KEY, "unspecified")
398+
.put(CLUSTER_ID_KEY, "<unspecified>")
399399
.put(METHOD_KEY, "Bigtable.ReadRows")
400400
.put(CLIENT_NAME_KEY, CLIENT_NAME)
401401
.build();
@@ -549,7 +549,7 @@ public void testMutateRowAttemptsTagValues() {
549549
.put(STATUS_KEY, "UNAVAILABLE")
550550
.put(TABLE_ID_KEY, TABLE)
551551
.put(ZONE_ID_KEY, "global")
552-
.put(CLUSTER_ID_KEY, "unspecified")
552+
.put(CLUSTER_ID_KEY, "<unspecified>")
553553
.put(METHOD_KEY, "Bigtable.MutateRow")
554554
.put(CLIENT_NAME_KEY, CLIENT_NAME)
555555
.put(STREAMING_KEY, false)
@@ -619,7 +619,7 @@ public void testMutateRowsRpcError() {
619619
.put(STATUS_KEY, "NOT_FOUND")
620620
.put(TABLE_ID_KEY, BAD_TABLE_ID)
621621
.put(ZONE_ID_KEY, "global")
622-
.put(CLUSTER_ID_KEY, "unspecified")
622+
.put(CLUSTER_ID_KEY, "<unspecified>")
623623
.put(METHOD_KEY, "Bigtable.MutateRows")
624624
.put(CLIENT_NAME_KEY, CLIENT_NAME)
625625
.put(STREAMING_KEY, false)
@@ -640,7 +640,7 @@ public void testReadRowsAttemptsTagValues() {
640640
.put(STATUS_KEY, "UNAVAILABLE")
641641
.put(TABLE_ID_KEY, TABLE)
642642
.put(ZONE_ID_KEY, "global")
643-
.put(CLUSTER_ID_KEY, "unspecified")
643+
.put(CLUSTER_ID_KEY, "<unspecified>")
644644
.put(METHOD_KEY, "Bigtable.ReadRows")
645645
.put(CLIENT_NAME_KEY, CLIENT_NAME)
646646
.put(STREAMING_KEY, true)
@@ -751,7 +751,7 @@ public void testPermanentFailure() {
751751
.toBuilder()
752752
.put(STATUS_KEY, "NOT_FOUND")
753753
.put(TABLE_ID_KEY, BAD_TABLE_ID)
754-
.put(CLUSTER_ID_KEY, "unspecified")
754+
.put(CLUSTER_ID_KEY, "<unspecified>")
755755
.put(ZONE_ID_KEY, "global")
756756
.put(STREAMING_KEY, true)
757757
.put(METHOD_KEY, "Bigtable.ReadRows")
@@ -776,7 +776,7 @@ public void testRemainingDeadline() {
776776
.put(TABLE_ID_KEY, TABLE)
777777
.put(METHOD_KEY, "Bigtable.ReadRows")
778778
.put(ZONE_ID_KEY, "global")
779-
.put(CLUSTER_ID_KEY, "unspecified")
779+
.put(CLUSTER_ID_KEY, "<unspecified>")
780780
.put(STREAMING_KEY, true)
781781
.put(CLIENT_NAME_KEY, CLIENT_NAME)
782782
.build();

0 commit comments

Comments
 (0)