From b98170c0f03fd9749ed002ec26c586fe60cf720e Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Sat, 21 Nov 2026 17:03:20 -0700 Subject: [PATCH 1/5] disable client side metrics outside default universe --- .../cloud/bigtable/data/_async/client.py | 8 ++- .../bigtable/data/_sync_autogen/client.py | 8 ++- .../tests/unit/data/_async/test_client.py | 69 +++++++++++++++++++ .../unit/data/_sync_autogen/test_client.py | 66 ++++++++++++++++++ 4 files changed, 149 insertions(+), 2 deletions(-) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py index 38792623749f..bfa006ca7506 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py @@ -38,6 +38,7 @@ import google.auth.credentials from google.api_core import client_options as client_options_lib from google.api_core import retry as retries +from google.api_core import universe from google.api_core.exceptions import ( Aborted, Cancelled, @@ -282,7 +283,12 @@ def __init__( kwargs.get("_disable_background_refresh", False) ) handlers: list[MetricsHandler] = [] - if self._emulator_host is None: + has_custom_endpoint = bool(client_options and client_options.api_endpoint) + if ( + self._emulator_host is None + and self.universe_domain == universe.DEFAULT_UNIVERSE + and not has_custom_endpoint + ): try: # create a metrics exporter using the same client configuration exporter = BigtableMetricsExporter( diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py index a485b53f78c4..2d3d74aa6a32 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py @@ -32,6 +32,7 @@ import google.auth.credentials from google.api_core import client_options as client_options_lib from google.api_core import retry as retries +from google.api_core import universe from google.api_core.exceptions import ( Aborted, Cancelled, @@ -208,7 +209,12 @@ def __init__( kwargs.get("_disable_background_refresh", False) ) handlers: list[MetricsHandler] = [] - if self._emulator_host is None: + has_custom_endpoint = bool(client_options and client_options.api_endpoint) + if ( + self._emulator_host is None + and self.universe_domain == universe.DEFAULT_UNIVERSE + and (not has_custom_endpoint) + ): try: exporter = BigtableMetricsExporter( credentials=self._credentials, client_options=client_options diff --git a/packages/google-cloud-bigtable/tests/unit/data/_async/test_client.py b/packages/google-cloud-bigtable/tests/unit/data/_async/test_client.py index 3eaffac1e639..3695f1c85485 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_async/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_async/test_client.py @@ -1342,6 +1342,75 @@ async def test_configured_universe_domain_mismatched_credentials(self): ) assert exc.value.args[0] == err_msg + @CrossSync.pytest + async def test_metrics_exporter_disabled_outside_gdu(self): + """BigtableMetricsExporter should be disabled when universe_domain != googleapis.com.""" + import os + + universe_domain = "custom-universe.test" + creds = AnonymousCredentials() + creds._universe_domain = universe_domain + options = client_options.ClientOptions(universe_domain=universe_domain) + with ( + mock.patch( + "google.cloud.bigtable.data._async.client.BigtableMetricsExporter" + ) as exporter_mock_async, + mock.patch( + "google.cloud.bigtable.data._sync_autogen.client.BigtableMetricsExporter" + ) as exporter_mock_sync, + ): + async with self._make_client( + project="project_id", + credentials=creds, + client_options=options, + use_emulator=False, + use_mtls="never", + ) as client: + assert client.universe_domain == universe_domain + assert client.api_endpoint == f"bigtable.{universe_domain}" + assert len(client._metrics.handlers) == 0 + exporter_mock_async.assert_not_called() + exporter_mock_sync.assert_not_called() + + with mock.patch.dict( + os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": universe_domain} + ): + async with self._make_client( + project="project_id", + credentials=creds, + use_emulator=False, + use_mtls="never", + ) as client: + assert client.universe_domain == universe_domain + assert client.api_endpoint == f"bigtable.{universe_domain}" + assert len(client._metrics.handlers) == 0 + exporter_mock_async.assert_not_called() + exporter_mock_sync.assert_not_called() + + @CrossSync.pytest + async def test_metrics_exporter_disabled_with_custom_api_endpoint(self): + """BigtableMetricsExporter should be disabled when a custom api_endpoint is set.""" + options = client_options.ClientOptions(api_endpoint="bigtable.custom.local:443") + with ( + mock.patch( + "google.cloud.bigtable.data._async.client.BigtableMetricsExporter" + ) as exporter_mock_async, + mock.patch( + "google.cloud.bigtable.data._sync_autogen.client.BigtableMetricsExporter" + ) as exporter_mock_sync, + ): + async with self._make_client( + project="project_id", + credentials=AnonymousCredentials(), + client_options=options, + use_emulator=False, + use_mtls="never", + ) as client: + assert client.api_endpoint == "bigtable.custom.local:443" + assert len(client._metrics.handlers) == 0 + exporter_mock_async.assert_not_called() + exporter_mock_sync.assert_not_called() + @CrossSync.pytest async def test_configured_universe_domain_matches_credentials(self): """Test that configured universe domain succeeds with matching universe diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py index 76910fea8852..dcca7366cd0e 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py @@ -1116,6 +1116,72 @@ def test_configured_universe_domain_mismatched_credentials(self): err_msg = f"The configured universe domain ({universe_domain}) does not match the universe domain found in the credentials ({creds.universe_domain}). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." assert exc.value.args[0] == err_msg + def test_metrics_exporter_disabled_outside_gdu(self): + """BigtableMetricsExporter should be disabled when universe_domain != googleapis.com.""" + import os + + universe_domain = "custom-universe.test" + creds = AnonymousCredentials() + creds._universe_domain = universe_domain + options = client_options.ClientOptions(universe_domain=universe_domain) + with ( + mock.patch( + "google.cloud.bigtable.data._async.client.BigtableMetricsExporter" + ) as exporter_mock_async, + mock.patch( + "google.cloud.bigtable.data._sync_autogen.client.BigtableMetricsExporter" + ) as exporter_mock_sync, + ): + with self._make_client( + project="project_id", + credentials=creds, + client_options=options, + use_emulator=False, + use_mtls="never", + ) as client: + assert client.universe_domain == universe_domain + assert client.api_endpoint == f"bigtable.{universe_domain}" + assert len(client._metrics.handlers) == 0 + exporter_mock_async.assert_not_called() + exporter_mock_sync.assert_not_called() + with mock.patch.dict( + os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": universe_domain} + ): + with self._make_client( + project="project_id", + credentials=creds, + use_emulator=False, + use_mtls="never", + ) as client: + assert client.universe_domain == universe_domain + assert client.api_endpoint == f"bigtable.{universe_domain}" + assert len(client._metrics.handlers) == 0 + exporter_mock_async.assert_not_called() + exporter_mock_sync.assert_not_called() + + def test_metrics_exporter_disabled_with_custom_api_endpoint(self): + """BigtableMetricsExporter should be disabled when a custom api_endpoint is set.""" + options = client_options.ClientOptions(api_endpoint="bigtable.custom.local:443") + with ( + mock.patch( + "google.cloud.bigtable.data._async.client.BigtableMetricsExporter" + ) as exporter_mock_async, + mock.patch( + "google.cloud.bigtable.data._sync_autogen.client.BigtableMetricsExporter" + ) as exporter_mock_sync, + ): + with self._make_client( + project="project_id", + credentials=AnonymousCredentials(), + client_options=options, + use_emulator=False, + use_mtls="never", + ) as client: + assert client.api_endpoint == "bigtable.custom.local:443" + assert len(client._metrics.handlers) == 0 + exporter_mock_async.assert_not_called() + exporter_mock_sync.assert_not_called() + def test_configured_universe_domain_matches_credentials(self): """Test that configured universe domain succeeds with matching universe domain credentials.""" From 2a81ac7b9e80224c5af5737f5d68628e3f99c83c Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 23 Nov 2026 20:24:27 -0700 Subject: [PATCH 2/5] use universe_domain in legacy client --- .../google/cloud/bigtable/client.py | 61 ++++++- .../tests/unit/v2_client/test_client.py | 152 ++++++++++++++++++ 2 files changed, 209 insertions(+), 4 deletions(-) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/client.py index 602997d000a4..d31ca950d413 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/client.py @@ -33,6 +33,7 @@ import warnings import grpc # type: ignore +from google.api_core import universe from google.api_core.gapic_v1 import client_info as client_info_lib from google.auth.credentials import AnonymousCredentials # type: ignore from google.cloud.client import ClientWithProject # type: ignore @@ -82,6 +83,13 @@ def inner(self): return inner +def _get_client_option(options, name): + """Read an attribute or dict key from ``options`` if present.""" + if isinstance(options, dict): + return options.get(name) + return getattr(options, name, None) + + class Client(ClientWithProject): """Client for interacting with Google Cloud Bigtable API. @@ -121,12 +129,16 @@ class Client(ClientWithProject): or :class:`dict` :param client_options: (Optional) Client options used to set user options on the client. API Endpoint should be set through client_options. + ``api_endpoint`` and ``universe_domain`` also apply to admin + operations, unless ``admin_client_options`` sets either one. :type admin_client_options: :class:`~google.api_core.client_options.ClientOptions` or :class:`dict` :param admin_client_options: (Optional) Client options used to set user options on the client. API Endpoint for admin operations should be set - through admin_client_options. + through admin_client_options. If neither ``api_endpoint`` nor + ``universe_domain`` is set, admin operations fall back to the values + from ``client_options``. :type channel: :instance: grpc.Channel :param channel (grpc.Channel): (Optional) DEPRECATED: @@ -225,13 +237,54 @@ def _emulator_channel(self, transport, options): channel_fn = grpc.insecure_channel return channel_fn(self._emulator_host, options=options) + def _resolve_admin_endpoint(self, client_class): + """Resolve the target host for GAPIC admin channels. + + Precedence order: + 1. ``admin_client_options.api_endpoint`` + 2. ``admin_client_options.universe_domain`` + 3. ``client_options.api_endpoint`` + 4. ``client_options.universe_domain`` + 5. ``GOOGLE_CLOUD_UNIVERSE_DOMAIN`` environment variable + 6. ``client_class.DEFAULT_ENDPOINT`` (``googleapis.com``) + + Within the same options object (or against the environment variable), + an explicit ``api_endpoint`` overrides ``universe_domain`` without + comparing hostnames, matching GAPIC behavior for regional, proxy, or + PSC endpoints. ``universe_domain`` is still validated first so an empty + string raises ``EmptyUniverseError`` even when ``api_endpoint`` is set. + """ + admin_universe = _get_client_option( + self._admin_client_options, "universe_domain" + ) + client_universe = _get_client_option(self._client_options, "universe_domain") + configured_universe = ( + admin_universe if admin_universe is not None else client_universe + ) + universe_domain = universe.determine_domain( + configured_universe, os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + ) + + admin_endpoint = _get_client_option(self._admin_client_options, "api_endpoint") + if admin_endpoint: + return admin_endpoint + + if admin_universe is None: + client_endpoint = _get_client_option(self._client_options, "api_endpoint") + if client_endpoint: + return client_endpoint + + if universe_domain == universe.DEFAULT_UNIVERSE: + return client_class.DEFAULT_ENDPOINT + return client_class._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=universe_domain + ) + def _create_gapic_client_channel(self, client_class, grpc_transport): if self._emulator_host is not None: api_endpoint = self._emulator_host - elif self._client_options and self._client_options.api_endpoint: - api_endpoint = self._client_options.api_endpoint else: - api_endpoint = client_class.DEFAULT_ENDPOINT + api_endpoint = self._resolve_admin_endpoint(client_class) if self._emulator_host is not None: channel = self._emulator_channel( diff --git a/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py b/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py index 611fce696b3b..0bf66ed80b56 100644 --- a/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py @@ -381,6 +381,158 @@ def test_client__create_gapic_client_channel_w_endpoint_w_emulator_host(): _create_gapic_client_channel_helper(endpoint=endpoint, emulator_host=host) +@pytest.mark.parametrize( + "client_options,admin_client_options,env_universe,expected_host", + [ + (None, None, None, "bigtableadmin.googleapis.com:443"), + # universe_domain via client_options or admin_client_options (dict or ClientOptions) + ({"universe_domain": "tpc.test"}, None, None, "bigtableadmin.tpc.test:443"), + (None, {"universe_domain": "tpc.test"}, None, "bigtableadmin.tpc.test:443"), + ( + {"universe_domain": "tpc.test"}, + {"universe_domain": "other.test"}, + None, + "bigtableadmin.other.test:443", + ), + # GOOGLE_CLOUD_UNIVERSE_DOMAIN used when no option sets universe_domain + (None, None, "tpc.test", "bigtableadmin.tpc.test:443"), + ( + {"universe_domain": "tpc.test"}, + None, + "other.test", + "bigtableadmin.tpc.test:443", + ), + ( + None, + {"universe_domain": "tpc.test"}, + "other.test", + "bigtableadmin.tpc.test:443", + ), + # explicit api_endpoint takes precedence over universe_domain within the same tier, + # while admin_client_options takes precedence over client_options + ({"api_endpoint": "custom.test:443"}, None, None, "custom.test:443"), + ( + {"api_endpoint": "custom.test:443", "universe_domain": "tpc.test"}, + None, + None, + "custom.test:443", + ), + ({"api_endpoint": "custom.test:443"}, None, "tpc.test", "custom.test:443"), + ( + {"api_endpoint": "custom.test:443"}, + {"api_endpoint": "admin.custom.test:443"}, + None, + "admin.custom.test:443", + ), + ( + {"universe_domain": "tpc.test"}, + {"api_endpoint": "admin.custom.test:443"}, + None, + "admin.custom.test:443", + ), + ( + {"api_endpoint": "data.custom.test:443"}, + {"universe_domain": "tpc.test"}, + None, + "bigtableadmin.tpc.test:443", + ), + ( + {"api_endpoint": "data.custom.test:443"}, + {"universe_domain": "googleapis.com"}, + None, + "bigtableadmin.googleapis.com:443", + ), + ], +) +def test_client_admin_clients_endpoint( + client_options, admin_client_options, env_universe, expected_host +): + import os + + from google.api_core.client_options import from_dict + + for as_client_options in (False, True): + co = ( + from_dict(client_options) + if (as_client_options and client_options) + else client_options + ) + aco = ( + from_dict(admin_client_options) + if (as_client_options and admin_client_options) + else admin_client_options + ) + with mock.patch.dict(os.environ, {}, clear=False): + if env_universe is None: + os.environ.pop("GOOGLE_CLOUD_UNIVERSE_DOMAIN", None) + else: + os.environ["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] = env_universe + client = _make_client( + project=PROJECT, + credentials=_make_credentials(), + admin=True, + client_options=co, + admin_client_options=aco, + ) + for admin_client in ( + client.table_admin_client, + client.instance_admin_client, + ): + assert admin_client.transport.host == expected_host + assert admin_client.api_endpoint == expected_host + + +def test_client_admin_clients_w_universe_env_set_after_construction(): + import os + + with mock.patch.dict(os.environ, {}, clear=False): + os.environ.pop("GOOGLE_CLOUD_UNIVERSE_DOMAIN", None) + client = _make_client( + project=PROJECT, credentials=_make_credentials(), admin=True + ) + os.environ["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] = "tpc.test" + + expected_host = "bigtableadmin.tpc.test:443" + assert client.table_admin_client.transport.host == expected_host + assert client.instance_admin_client.transport.host == expected_host + + +@pytest.mark.parametrize( + "client_options,admin_client_options,env_universe", + [ + ({"universe_domain": ""}, None, None), + (None, {"universe_domain": ""}, None), + (None, None, ""), + ({"universe_domain": "", "api_endpoint": "custom.test:443"}, None, None), + (None, {"universe_domain": "", "api_endpoint": "admin.custom.test:443"}, None), + ({"api_endpoint": "custom.test:443"}, None, ""), + ], +) +def test_client_admin_clients_w_empty_universe_domain( + client_options, admin_client_options, env_universe +): + import os + + from google.api_core.universe import EmptyUniverseError + + with mock.patch.dict(os.environ, {}, clear=False): + if env_universe is None: + os.environ.pop("GOOGLE_CLOUD_UNIVERSE_DOMAIN", None) + else: + os.environ["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] = env_universe + client = _make_client( + project=PROJECT, + credentials=_make_credentials(), + admin=True, + client_options=client_options, + admin_client_options=admin_client_options, + ) + with pytest.raises(EmptyUniverseError): + _ = client.table_admin_client + with pytest.raises(EmptyUniverseError): + _ = client.instance_admin_client + + def test_client_project_path(): credentials = _make_credentials() project = "PROJECT" From c76f12443657854e5596d7a0c9919edb44bc1933 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 23 Nov 2026 21:01:07 -0700 Subject: [PATCH 3/5] pass through universe into admin_client_options --- .../google/cloud/bigtable/client.py | 20 ++++- .../tests/unit/v2_client/test_client.py | 73 +++++++++++++++++-- 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/client.py index d31ca950d413..d1686fc89c45 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/client.py @@ -280,6 +280,22 @@ def _resolve_admin_endpoint(self, client_class): UNIVERSE_DOMAIN=universe_domain ) + def _resolve_admin_client_options(self): + """Return ``admin_client_options``, inheriting ``universe_domain`` from + ``client_options`` if unset so admin clients report the right universe.""" + admin_options = self._admin_client_options + client_universe = _get_client_option(self._client_options, "universe_domain") + if ( + not client_universe + or _get_client_option(admin_options, "universe_domain") is not None + ): + return admin_options + if admin_options is None or isinstance(admin_options, dict): + return {**(admin_options or {}), "universe_domain": client_universe} + admin_options = copy.copy(admin_options) + admin_options.universe_domain = client_universe + return admin_options + def _create_gapic_client_channel(self, client_class, grpc_transport): if self._emulator_host is not None: api_endpoint = self._emulator_host @@ -371,7 +387,7 @@ def table_admin_client(self): ) klass = _create_gapic_client( bigtable_admin_v2.BaseBigtableTableAdminClient, - client_options=self._admin_client_options, + client_options=self._resolve_admin_client_options(), transport=transport, ) self._table_admin_client = klass(self) @@ -408,7 +424,7 @@ def instance_admin_client(self): ) klass = _create_gapic_client( bigtable_admin_v2.BigtableInstanceAdminClient, - client_options=self._admin_client_options, + client_options=self._resolve_admin_client_options(), transport=transport, ) self._instance_admin_client = klass(self) diff --git a/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py b/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py index 0bf66ed80b56..aab7740928e7 100644 --- a/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py @@ -382,70 +382,102 @@ def test_client__create_gapic_client_channel_w_endpoint_w_emulator_host(): @pytest.mark.parametrize( - "client_options,admin_client_options,env_universe,expected_host", + "client_options,admin_client_options,env_universe,expected_host,expected_universe", [ - (None, None, None, "bigtableadmin.googleapis.com:443"), + (None, None, None, "bigtableadmin.googleapis.com:443", "googleapis.com"), # universe_domain via client_options or admin_client_options (dict or ClientOptions) - ({"universe_domain": "tpc.test"}, None, None, "bigtableadmin.tpc.test:443"), - (None, {"universe_domain": "tpc.test"}, None, "bigtableadmin.tpc.test:443"), + ( + {"universe_domain": "tpc.test"}, + None, + None, + "bigtableadmin.tpc.test:443", + "tpc.test", + ), + ( + None, + {"universe_domain": "tpc.test"}, + None, + "bigtableadmin.tpc.test:443", + "tpc.test", + ), ( {"universe_domain": "tpc.test"}, {"universe_domain": "other.test"}, None, "bigtableadmin.other.test:443", + "other.test", ), # GOOGLE_CLOUD_UNIVERSE_DOMAIN used when no option sets universe_domain - (None, None, "tpc.test", "bigtableadmin.tpc.test:443"), + (None, None, "tpc.test", "bigtableadmin.tpc.test:443", "tpc.test"), ( {"universe_domain": "tpc.test"}, None, "other.test", "bigtableadmin.tpc.test:443", + "tpc.test", ), ( None, {"universe_domain": "tpc.test"}, "other.test", "bigtableadmin.tpc.test:443", + "tpc.test", ), # explicit api_endpoint takes precedence over universe_domain within the same tier, # while admin_client_options takes precedence over client_options - ({"api_endpoint": "custom.test:443"}, None, None, "custom.test:443"), + ( + {"api_endpoint": "custom.test:443"}, + None, + None, + "custom.test:443", + "googleapis.com", + ), ( {"api_endpoint": "custom.test:443", "universe_domain": "tpc.test"}, None, None, "custom.test:443", + "tpc.test", + ), + ( + {"api_endpoint": "custom.test:443"}, + None, + "tpc.test", + "custom.test:443", + "tpc.test", ), - ({"api_endpoint": "custom.test:443"}, None, "tpc.test", "custom.test:443"), ( {"api_endpoint": "custom.test:443"}, {"api_endpoint": "admin.custom.test:443"}, None, "admin.custom.test:443", + "googleapis.com", ), ( {"universe_domain": "tpc.test"}, {"api_endpoint": "admin.custom.test:443"}, None, "admin.custom.test:443", + "tpc.test", ), ( {"api_endpoint": "data.custom.test:443"}, {"universe_domain": "tpc.test"}, None, "bigtableadmin.tpc.test:443", + "tpc.test", ), ( {"api_endpoint": "data.custom.test:443"}, {"universe_domain": "googleapis.com"}, None, "bigtableadmin.googleapis.com:443", + "googleapis.com", ), ], ) def test_client_admin_clients_endpoint( - client_options, admin_client_options, env_universe, expected_host + client_options, admin_client_options, env_universe, expected_host, expected_universe ): import os @@ -480,6 +512,31 @@ def test_client_admin_clients_endpoint( ): assert admin_client.transport.host == expected_host assert admin_client.api_endpoint == expected_host + assert admin_client.universe_domain == expected_universe + + +def test_client_admin_clients_inherit_universe_wo_mutating_options(): + from google.api_core.client_options import ClientOptions + + for admin_client_options in ( + {"api_endpoint": "admin.custom.test:443"}, + ClientOptions(api_endpoint="admin.custom.test:443"), + ): + client = _make_client( + project=PROJECT, + credentials=_make_credentials(), + admin=True, + client_options={"universe_domain": "tpc.test"}, + admin_client_options=admin_client_options, + ) + assert client.table_admin_client.universe_domain == "tpc.test" + assert client.instance_admin_client.universe_domain == "tpc.test" + # the options object passed in by the caller is left untouched + assert client._admin_client_options is admin_client_options + if isinstance(admin_client_options, dict): + assert admin_client_options == {"api_endpoint": "admin.custom.test:443"} + else: + assert admin_client_options.universe_domain is None def test_client_admin_clients_w_universe_env_set_after_construction(): From 6cda2e625b094e802b9b5f87879e404a4fe1d3eb Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 23 Nov 2026 21:07:42 -0700 Subject: [PATCH 4/5] updated docstring --- .../google/cloud/bigtable/client.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/client.py index d1686fc89c45..5dc825773cae 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/client.py @@ -128,17 +128,19 @@ class Client(ClientWithProject): :type client_options: :class:`~google.api_core.client_options.ClientOptions` or :class:`dict` :param client_options: (Optional) Client options used to set user options - on the client. API Endpoint should be set through client_options. - ``api_endpoint`` and ``universe_domain`` also apply to admin - operations, unless ``admin_client_options`` sets either one. + on the client. The credential settings, ``api_endpoint`` and + ``universe_domain`` set here are used for both data and admin + operations, unless ``admin_client_options`` overrides the last two + for admin operations. :type admin_client_options: :class:`~google.api_core.client_options.ClientOptions` or :class:`dict` - :param admin_client_options: (Optional) Client options used to set user - options on the client. API Endpoint for admin operations should be set - through admin_client_options. If neither ``api_endpoint`` nor - ``universe_domain`` is set, admin operations fall back to the values - from ``client_options``. + :param admin_client_options: (Optional) Overrides the ``api_endpoint`` + and ``universe_domain`` from ``client_options`` for admin operations + only. Data and admin operations are served by separate APIs, so use + this when admin operations need a different endpoint than data + operations. If neither is set here, the values from + ``client_options`` are used. :type channel: :instance: grpc.Channel :param channel (grpc.Channel): (Optional) DEPRECATED: From 01a4f5a46eaaa7bb8570efb054425bfb4c8ab3d3 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 23 Nov 2026 21:08:20 -0700 Subject: [PATCH 5/5] updated test --- .../tests/unit/v2_client/test_client.py | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py b/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py index aab7740928e7..5901ec14877c 100644 --- a/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/v2_client/test_client.py @@ -15,6 +15,7 @@ import mock import pytest +from google.api_core.client_options import ClientOptions from ._testing import _make_credentials @@ -515,28 +516,31 @@ def test_client_admin_clients_endpoint( assert admin_client.universe_domain == expected_universe -def test_client_admin_clients_inherit_universe_wo_mutating_options(): - from google.api_core.client_options import ClientOptions - - for admin_client_options in ( +@pytest.mark.parametrize( + "admin_client_options", + [ {"api_endpoint": "admin.custom.test:443"}, ClientOptions(api_endpoint="admin.custom.test:443"), - ): - client = _make_client( - project=PROJECT, - credentials=_make_credentials(), - admin=True, - client_options={"universe_domain": "tpc.test"}, - admin_client_options=admin_client_options, - ) - assert client.table_admin_client.universe_domain == "tpc.test" - assert client.instance_admin_client.universe_domain == "tpc.test" - # the options object passed in by the caller is left untouched - assert client._admin_client_options is admin_client_options - if isinstance(admin_client_options, dict): - assert admin_client_options == {"api_endpoint": "admin.custom.test:443"} - else: - assert admin_client_options.universe_domain is None + ], +) +def test_client_admin_clients_inherit_universe_wo_mutating_options( + admin_client_options, +): + client = _make_client( + project=PROJECT, + credentials=_make_credentials(), + admin=True, + client_options={"universe_domain": "tpc.test"}, + admin_client_options=admin_client_options, + ) + assert client.table_admin_client.universe_domain == "tpc.test" + assert client.instance_admin_client.universe_domain == "tpc.test" + # the options object passed in by the caller is left untouched + assert client._admin_client_options is admin_client_options + if isinstance(admin_client_options, dict): + assert admin_client_options == {"api_endpoint": "admin.custom.test:443"} + else: + assert admin_client_options.universe_domain is None def test_client_admin_clients_w_universe_env_set_after_construction():