From 9a0cdc8cb8e2c52fde403eb316d28bf99c55a1e7 Mon Sep 17 00:00:00 2001 From: Reza Karegar Date: Thu, 25 Jan 2024 15:24:15 -0500 Subject: [PATCH] feat: append version to the client name in client-side metrics. (#2062) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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://togithub.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 Fixes #2061 ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md). --- .../bigtable/stats/StatsRecorderWrapper.java | 1 - .../stats/StatsRecorderWrapperTest.java | 40 ++++++++++--------- .../data/v2/stub/EnhancedBigtableStub.java | 1 + 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/StatsRecorderWrapper.java b/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/StatsRecorderWrapper.java index 88eab077c3..6bf0988b91 100644 --- a/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/StatsRecorderWrapper.java +++ b/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/StatsRecorderWrapper.java @@ -123,7 +123,6 @@ private TagContextBuilder newTagContextBuilder(String tableId, String zone, Stri TagContextBuilder tagContextBuilder = tagger .toBuilder(parentContext) - .putLocal(BuiltinMeasureConstants.CLIENT_NAME, TagValue.create("bigtable-java")) .putLocal(BuiltinMeasureConstants.METHOD, TagValue.create(spanName.toString())) .putLocal(BuiltinMeasureConstants.TABLE, TagValue.create(tableId)) .putLocal(BuiltinMeasureConstants.ZONE, TagValue.create(zone)) diff --git a/google-cloud-bigtable-stats/src/test/java/com/google/cloud/bigtable/stats/StatsRecorderWrapperTest.java b/google-cloud-bigtable-stats/src/test/java/com/google/cloud/bigtable/stats/StatsRecorderWrapperTest.java index b68e4f1a1b..829202510c 100644 --- a/google-cloud-bigtable-stats/src/test/java/com/google/cloud/bigtable/stats/StatsRecorderWrapperTest.java +++ b/google-cloud-bigtable-stats/src/test/java/com/google/cloud/bigtable/stats/StatsRecorderWrapperTest.java @@ -51,6 +51,7 @@ public class StatsRecorderWrapperTest { private final String TABLE_ID = "fake-table-id"; private final String ZONE = "fake-zone"; private final String CLUSTER = "fake-cluster"; + private final String CLIENT_AND_VERSION = "bigtable-java/fake-version"; private final StatsComponent statsComponent = new StatsComponentImpl(); @@ -72,7 +73,9 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.INSTANCE_ID.getName(), INSTANCE_ID, BuiltinMeasureConstants.APP_PROFILE.getName(), - APP_PROFILE_ID), + APP_PROFILE_ID, + BuiltinMeasureConstants.CLIENT_NAME.getName(), + CLIENT_AND_VERSION), statsComponent.getStatsRecorder()); long operationLatency = 1234; @@ -107,7 +110,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.TABLE, TABLE_ID, BuiltinMeasureConstants.ZONE, ZONE, BuiltinMeasureConstants.CLUSTER, CLUSTER, - BuiltinMeasureConstants.CLIENT_NAME, "bigtable-java", + BuiltinMeasureConstants.CLIENT_NAME, CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "true"), PROJECT_ID, INSTANCE_ID, @@ -129,7 +132,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "true"), PROJECT_ID, @@ -152,7 +155,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java"), + CLIENT_AND_VERSION), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID, @@ -167,7 +170,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.STATUS, "OK", BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "true", BuiltinMeasureConstants.TABLE, @@ -196,7 +199,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "true"), PROJECT_ID, @@ -213,7 +216,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.STATUS, "OK", BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.TABLE, TABLE_ID, BuiltinMeasureConstants.ZONE, @@ -233,7 +236,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.TABLE, TABLE_ID, BuiltinMeasureConstants.ZONE, ZONE, BuiltinMeasureConstants.CLUSTER, CLUSTER, - BuiltinMeasureConstants.CLIENT_NAME, "bigtable-java"), + BuiltinMeasureConstants.CLIENT_NAME, CLIENT_AND_VERSION), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID, @@ -254,7 +257,7 @@ public void testStreamingOperation() throws InterruptedException { BuiltinMeasureConstants.STATUS, "OK", BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java"), + CLIENT_AND_VERSION), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID, @@ -271,7 +274,8 @@ public void testUnaryOperations() throws InterruptedException { ImmutableMap.of( BuiltinMeasureConstants.PROJECT_ID.getName(), PROJECT_ID, BuiltinMeasureConstants.INSTANCE_ID.getName(), INSTANCE_ID, - BuiltinMeasureConstants.APP_PROFILE.getName(), APP_PROFILE_ID), + BuiltinMeasureConstants.APP_PROFILE.getName(), APP_PROFILE_ID, + BuiltinMeasureConstants.CLIENT_NAME.getName(), CLIENT_AND_VERSION), statsComponent.getStatsRecorder()); long operationLatency = 1234; @@ -312,7 +316,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "false"), PROJECT_ID, @@ -335,7 +339,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "false"), PROJECT_ID, @@ -358,7 +362,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java"), + CLIENT_AND_VERSION), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID, @@ -373,7 +377,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.STATUS, "UNAVAILABLE", BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "false", BuiltinMeasureConstants.TABLE, @@ -402,7 +406,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.CLUSTER, CLUSTER, BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.STREAMING, "false"), PROJECT_ID, @@ -419,7 +423,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.STATUS, "UNAVAILABLE", BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java", + CLIENT_AND_VERSION, BuiltinMeasureConstants.TABLE, TABLE_ID, BuiltinMeasureConstants.ZONE, @@ -439,7 +443,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.TABLE, TABLE_ID, BuiltinMeasureConstants.ZONE, ZONE, BuiltinMeasureConstants.CLUSTER, CLUSTER, - BuiltinMeasureConstants.CLIENT_NAME, "bigtable-java"), + BuiltinMeasureConstants.CLIENT_NAME, CLIENT_AND_VERSION), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID, @@ -460,7 +464,7 @@ public void testUnaryOperations() throws InterruptedException { BuiltinMeasureConstants.STATUS, "UNAVAILABLE", BuiltinMeasureConstants.CLIENT_NAME, - "bigtable-java"), + CLIENT_AND_VERSION), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index b43b680e1a..9fb906c2d1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -259,6 +259,7 @@ public static ApiTracerFactory createBigtableTracerFactory( .put("project_id", projectId) .put("instance", instanceId) .put("app_profile", appProfileId) + .put("client_name", "bigtable-java/" + Version.VERSION) .build(); return new CompositeTracerFactory(