From 5545a7022ad6df498897858b88cc41d6b5b07016 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 30 Nov 2026 20:19:38 +0000 Subject: [PATCH] feat: add google.bigtable.enable.internal.metrics config key --- .../hbase/BigtableOptionsFactory.java | 17 ++++++- .../veneer/BigtableHBaseVeneerSettings.java | 5 ++ .../TestBigtableHBaseVeneerSettings.java | 46 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java index a8983f1cae..8a04ed704f 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java @@ -361,10 +361,25 @@ public class BigtableOptionsFactory { @VisibleForTesting public static final String BIGTABLE_TEST_IDLE_TIMEOUT_MS = "google.bigtable.idle.timeout.ms"; - /** Sets if client side metrics should be enabled. Client side metrics is enabled by default. */ + /** + * Sets whether client-side metrics should be enabled. Enabled by default. + * + *

Setting this to {@code false} configures the client-side {@link + * com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider} to {@link + * com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider#INSTANCE}. This does not + * disable exporting built-in internal metrics to Cloud Monitoring, which is controlled separately + * by {@link #BIGTABLE_ENABLE_INTERNAL_METRICS}. + */ public static final String BIGTABLE_ENABLE_CLIENT_SIDE_METRICS = "google.bigtable.enable.client.side.metrics"; + /** + * Sets whether built-in internal metrics exported to Cloud Monitoring should be enabled. Enabled + * by default. Set to {@code false} to disable exporting built-in metrics to Cloud Monitoring. + */ + public static final String BIGTABLE_ENABLE_INTERNAL_METRICS = + "google.bigtable.enable.internal.metrics"; + /** Override jwt audience in test environment. * */ @InternalApi public static final String BIGTABLE_JWT_AUDIENCE_KEY = "google.bigtable.jwt.audience"; diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/BigtableHBaseVeneerSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/BigtableHBaseVeneerSettings.java index 0fedaf3f87..5248ef46c3 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/BigtableHBaseVeneerSettings.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/BigtableHBaseVeneerSettings.java @@ -31,6 +31,7 @@ import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_ENABLE_BULK_MUTATION_FLOW_CONTROL; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_ENABLE_CLIENT_SIDE_METRICS; +import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_ENABLE_INTERNAL_METRICS; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_HOST_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_JWT_AUDIENCE_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_MUTATE_RPC_ATTEMPT_TIMEOUT_MS_KEY; @@ -368,6 +369,10 @@ private BigtableDataSettings buildBigtableDataSettings(ClientOperationTimeouts c dataBuilder.setMetricsProvider(NoopMetricsProvider.INSTANCE); } + if (!configuration.getBoolean(BIGTABLE_ENABLE_INTERNAL_METRICS, true)) { + dataBuilder.disableInternalMetrics(); + } + return dataBuilder.build(); } diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java index 70810566f7..86b9016fbf 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java @@ -25,6 +25,8 @@ import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_BULK_MAX_ROW_KEY_COUNT; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY; +import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_ENABLE_CLIENT_SIDE_METRICS; +import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_ENABLE_INTERNAL_METRICS; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_PORT_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_READ_RPC_ATTEMPT_TIMEOUT_MS_KEY; @@ -62,6 +64,8 @@ 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.stub.metrics.DefaultMetricsProvider; +import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider; import com.google.cloud.bigtable.hbase.BigtableConfiguration; import com.google.cloud.bigtable.hbase.BigtableHBaseVersion; import com.google.cloud.bigtable.hbase.BigtableOptionsFactory; @@ -561,6 +565,48 @@ public void testAdminSettingsWithEmulator() throws IOException { assertTrue(credProvider instanceof NoCredentialsProvider); } + @Test + public void testInternalMetricsEnabledByDefault() throws IOException { + BigtableHBaseVeneerSettings settings = BigtableHBaseVeneerSettings.create(configuration); + BigtableDataSettings dataSettings = settings.getDataSettings(); + + assertTrue(dataSettings.areInternalMetricsEnabled()); + assertEquals(DefaultMetricsProvider.INSTANCE, dataSettings.getMetricsProvider()); + } + + @Test + public void testDisableInternalMetrics() throws IOException { + configuration.set(BIGTABLE_ENABLE_INTERNAL_METRICS, "false"); + + BigtableHBaseVeneerSettings settings = BigtableHBaseVeneerSettings.create(configuration); + BigtableDataSettings dataSettings = settings.getDataSettings(); + + assertFalse(dataSettings.areInternalMetricsEnabled()); + assertEquals(DefaultMetricsProvider.INSTANCE, dataSettings.getMetricsProvider()); + } + + @Test + public void testEnableInternalMetricsExplicitly() throws IOException { + configuration.set(BIGTABLE_ENABLE_INTERNAL_METRICS, "true"); + + BigtableHBaseVeneerSettings settings = BigtableHBaseVeneerSettings.create(configuration); + BigtableDataSettings dataSettings = settings.getDataSettings(); + + assertTrue(dataSettings.areInternalMetricsEnabled()); + assertEquals(DefaultMetricsProvider.INSTANCE, dataSettings.getMetricsProvider()); + } + + @Test + public void testDisableClientSideMetricsDoesNotDisableInternalMetrics() throws IOException { + configuration.set(BIGTABLE_ENABLE_CLIENT_SIDE_METRICS, "false"); + + BigtableHBaseVeneerSettings settings = BigtableHBaseVeneerSettings.create(configuration); + BigtableDataSettings dataSettings = settings.getDataSettings(); + + assertEquals(NoopMetricsProvider.INSTANCE, dataSettings.getMetricsProvider()); + assertTrue(dataSettings.areInternalMetricsEnabled()); + } + @Ignore("Re-enable this test once veneer default align with hbase") @Test public void testRpcMethodWithoutRetry() throws IOException {