Skip to content

Commit 6abe73f

Browse files
committed
feat(spanner): make built-in metrics enabled by default
1 parent 4bb4622 commit 6abe73f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

google/cloud/spanner_v1/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
from google.cloud.spanner_v1._helpers import _metadata_with_prefix
5353
from google.cloud.spanner_v1.instance import Instance
5454
from google.cloud.spanner_v1.metrics.constants import (
55-
ENABLE_SPANNER_METRICS_ENV_VAR,
5655
METRIC_EXPORT_INTERVAL_MS,
5756
)
5857
from google.cloud.spanner_v1.metrics.spanner_metrics_tracer_factory import (
@@ -75,7 +74,7 @@
7574

7675
_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)
7776
EMULATOR_ENV_VAR = "SPANNER_EMULATOR_HOST"
78-
ENABLE_BUILTIN_METRICS_ENV_VAR = "SPANNER_ENABLE_BUILTIN_METRICS"
77+
SPANNER_DISABLE_BUILTIN_METRICS_ENV_VAR = "SPANNER_DISABLE_BUILTIN_METRICS"
7978
_EMULATOR_HOST_HTTP_SCHEME = (
8079
"%s contains a http scheme. When used with a scheme it may cause gRPC's "
8180
"DNS resolver to endlessly attempt to resolve. %s is intended to be used "
@@ -102,7 +101,7 @@ def _get_spanner_optimizer_statistics_package():
102101

103102

104103
def _get_spanner_enable_builtin_metrics():
105-
return os.getenv(ENABLE_SPANNER_METRICS_ENV_VAR) == "true"
104+
return os.getenv(SPANNER_DISABLE_BUILTIN_METRICS_ENV_VAR) != "true"
106105

107106

108107
class Client(ClientWithProject):

tests/unit/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from tests._builders import build_scoped_credentials
2323

2424

25+
@mock.patch.dict(os.environ, {"SPANNER_DISABLE_BUILTIN_METRICS": "true"})
2526
class TestClient(unittest.TestCase):
2627
PROJECT = "PROJECT"
2728
PATH = "projects/%s" % (PROJECT,)
@@ -161,8 +162,7 @@ def test_constructor_custom_client_info(self):
161162
creds = build_scoped_credentials()
162163
self._constructor_test_helper(expected_scopes, creds, client_info=client_info)
163164

164-
# Disable metrics to avoid google.auth.default calls from Metric Exporter
165-
@mock.patch.dict(os.environ, {"SPANNER_ENABLE_BUILTIN_METRICS": ""})
165+
# Metrics are disabled by default for tests in this class
166166
def test_constructor_implicit_credentials(self):
167167
from google.cloud.spanner_v1 import client as MUT
168168

@@ -255,8 +255,8 @@ def test_constructor_w_directed_read_options(self):
255255
expected_scopes, creds, directed_read_options=self.DIRECTED_READ_OPTIONS
256256
)
257257

258-
@mock.patch.dict(os.environ, {"SPANNER_ENABLE_BUILTIN_METRICS": "true"})
259258
@mock.patch("google.cloud.spanner_v1.client.SpannerMetricsTracerFactory")
259+
@mock.patch.dict(os.environ, {"SPANNER_DISABLE_BUILTIN_METRICS": "false"})
260260
def test_constructor_w_metrics_initialization_error(
261261
self, mock_spanner_metrics_factory
262262
):

0 commit comments

Comments
 (0)