Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dd3a0e

Browse files
committed
Added Attempt failure test
1 parent c7a2f9c commit 2dd3a0e

15 files changed

+111
-17
lines changed

google/cloud/spanner_v1/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
from google.cloud.spanner_v1._helpers import _merge_query_options
4949
from google.cloud.spanner_v1._helpers import _metadata_with_prefix
5050
from google.cloud.spanner_v1.instance import Instance
51-
from google.cloud.spanner_v1.metrics.constants import ENABLE_SPANNER_METRICS_ENV_VAR
51+
from google.cloud.spanner_v1.metrics.constants import (
52+
ENABLE_SPANNER_METRICS_ENV_VAR,
53+
METRIC_EXPORT_INTERVAL_MS,
54+
)
5255
from google.cloud.spanner_v1.metrics.spanner_metrics_tracer_factory import (
5356
SpannerMetricsTracerFactory,
5457
)
@@ -227,7 +230,10 @@ def __init__(
227230
if not _get_spanner_emulator_host():
228231
meter_provider = MeterProvider(
229232
metric_readers=[
230-
PeriodicExportingMetricReader(CloudMonitoringMetricsExporter())
233+
PeriodicExportingMetricReader(
234+
CloudMonitoringMetricsExporter(),
235+
export_interval_millis=METRIC_EXPORT_INTERVAL_MS,
236+
)
231237
]
232238
)
233239
metrics.set_meter_provider(meter_provider)

google/cloud/spanner_v1/metrics/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -68,3 +67,5 @@
6867
METRIC_NAME_OPERATION_COUNT,
6968
METRIC_NAME_ATTEMPT_COUNT,
7069
]
70+
71+
METRIC_EXPORT_INTERVAL_MS = 60000 # 1 Minute

google/cloud/spanner_v1/metrics/metrics_capture.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC All rights reserved.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,7 +40,6 @@ def __enter__(self):
4140
MetricsCapture: The instance of the context manager.
4241
"""
4342
factory = SpannerMetricsTracerFactory()
44-
4543
# Define a new metrics tracer for the new operation
4644
SpannerMetricsTracerFactory.current_metrics_tracer = (
4745
factory.create_metrics_tracer()

google/cloud/spanner_v1/metrics/metrics_exporter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -351,7 +350,6 @@ def export(
351350
if not HAS_OPENTELEMETRY_INSTALLED:
352351
logger.warning("Metric exporter called without dependencies installed.")
353352
return False
354-
355353
time_series_list = self._resource_metrics_to_timeseries_pb(metrics_data)
356354
self._batch_write(time_series_list, timeout_millis)
357355
return True

google/cloud/spanner_v1/metrics/metrics_interceptor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -138,8 +137,8 @@ def intercept(self, invoked_method, request_or_iterator, call_details):
138137
method_name = self._remove_prefix(
139138
call_details.method, SPANNER_METHOD_PREFIX
140139
).replace("/", ".")
141-
SpannerMetricsTracerFactory.current_metrics_tracer.set_method(method_name)
142140

141+
SpannerMetricsTracerFactory.current_metrics_tracer.set_method(method_name)
143142
SpannerMetricsTracerFactory.current_metrics_tracer.record_attempt_start()
144143
response = invoked_method(request_or_iterator, call_details)
145144
SpannerMetricsTracerFactory.current_metrics_tracer.record_attempt_completion()
@@ -150,5 +149,4 @@ def intercept(self, invoked_method, request_or_iterator, call_details):
150149
SpannerMetricsTracerFactory.current_metrics_trace.record_gfe_metrics(
151150
metadata
152151
)
153-
154152
return response

google/cloud/spanner_v1/metrics/metrics_tracer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

google/cloud/spanner_v1/metrics/metrics_tracer_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,7 +35,10 @@
3635

3736
# Override Resource detector logging to not warn when GCP resources are not detected
3837
import logging
39-
logging.getLogger("opentelemetry.resourcedetector.gcp_resource_detector").setLevel(logging.ERROR)
38+
39+
logging.getLogger("opentelemetry.resourcedetector.gcp_resource_detector").setLevel(
40+
logging.ERROR
41+
)
4042

4143
HAS_OPENTELEMETRY_INSTALLED = True
4244
except ImportError: # pragma: NO COVER

google/cloud/spanner_v1/services/spanner/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def __init__(
124124
self._grpc_channel = None
125125
self._ssl_channel_credentials = ssl_channel_credentials
126126
self._stubs: Dict[str, Callable] = {}
127+
self._metrics_interceptor = None
127128

128129
if api_mtls_endpoint:
129130
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
@@ -192,6 +193,7 @@ def __init__(
192193

193194
# Wrap the gRPC channel with the metric interceptor
194195
if metrics_interceptor is not None:
196+
self._metrics_interceptor = metrics_interceptor
195197
self._grpc_channel = grpc.intercept_channel(
196198
self._grpc_channel, metrics_interceptor
197199
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"opentelemetry-semantic-conventions >= 0.43b0",
5353
"opentelemetry-resourcedetector-gcp >= 1.8.0a0",
5454
"google-cloud-monitoring >= 2.16.0",
55-
"mmh3 >= 5.0.1 ",
55+
"mmh3 >= 4.1.0 ",
5656
],
5757
"libcst": "libcst >= 0.2.5",
5858
}

0 commit comments

Comments
 (0)