Skip to content

Commit ed09516

Browse files
committed
add replacements to owlbot.py
1 parent c4ce860 commit ed09516

File tree

7 files changed

+110
-10
lines changed

7 files changed

+110
-10
lines changed

google/cloud/spanner_v1/services/spanner/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
from google.cloud.spanner_v1.types import result_set
6969
from google.cloud.spanner_v1.types import spanner
7070
from google.cloud.spanner_v1.types import transaction
71+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
7172
from google.protobuf import struct_pb2 # type: ignore
7273
from google.protobuf import timestamp_pb2 # type: ignore
7374
from google.rpc import status_pb2 # type: ignore
@@ -715,6 +716,7 @@ def __init__(
715716
client_info=client_info,
716717
always_use_jwt_access=True,
717718
api_audience=self._client_options.api_audience,
719+
metrics_interceptor=MetricsInterceptor(),
718720
)
719721

720722
if "async" not in str(self._transport):

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from google.cloud.spanner_v1.types import result_set
3232
from google.cloud.spanner_v1.types import spanner
3333
from google.cloud.spanner_v1.types import transaction
34+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
3435
from google.protobuf import empty_pb2 # type: ignore
3536

3637
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -62,6 +63,7 @@ def __init__(
6263
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6364
always_use_jwt_access: Optional[bool] = False,
6465
api_audience: Optional[str] = None,
66+
metrics_interceptor: Optional[MetricsInterceptor] = None,
6567
**kwargs,
6668
) -> None:
6769
"""Instantiate the transport.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from google.cloud.spanner_v1.types import result_set
3535
from google.cloud.spanner_v1.types import spanner
3636
from google.cloud.spanner_v1.types import transaction
37+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
3738
from google.protobuf import empty_pb2 # type: ignore
3839
from .base import SpannerTransport, DEFAULT_CLIENT_INFO
3940

@@ -146,6 +147,7 @@ def __init__(
146147
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
147148
always_use_jwt_access: Optional[bool] = False,
148149
api_audience: Optional[str] = None,
150+
metrics_interceptor: Optional[MetricsInterceptor] = None,
149151
) -> None:
150152
"""Instantiate the transport.
151153
@@ -201,6 +203,7 @@ def __init__(
201203
self._grpc_channel = None
202204
self._ssl_channel_credentials = ssl_channel_credentials
203205
self._stubs: Dict[str, Callable] = {}
206+
self._metrics_interceptor = None
204207

205208
if api_mtls_endpoint:
206209
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
@@ -267,6 +270,13 @@ def __init__(
267270
],
268271
)
269272

273+
# Wrap the gRPC channel with the metric interceptor
274+
if metrics_interceptor is not None:
275+
self._metrics_interceptor = metrics_interceptor
276+
self._grpc_channel = grpc.intercept_channel(
277+
self._grpc_channel, metrics_interceptor
278+
)
279+
270280
self._interceptor = _LoggingClientInterceptor()
271281
self._logged_channel = grpc.intercept_channel(
272282
self._grpc_channel, self._interceptor

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from google.cloud.spanner_v1.types import result_set
3838
from google.cloud.spanner_v1.types import spanner
3939
from google.cloud.spanner_v1.types import transaction
40+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
4041
from google.protobuf import empty_pb2 # type: ignore
4142
from .base import SpannerTransport, DEFAULT_CLIENT_INFO
4243
from .grpc import SpannerGrpcTransport
@@ -195,6 +196,7 @@ def __init__(
195196
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
196197
always_use_jwt_access: Optional[bool] = False,
197198
api_audience: Optional[str] = None,
199+
metrics_interceptor: Optional[MetricsInterceptor] = None,
198200
) -> None:
199201
"""Instantiate the transport.
200202

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from google.cloud.spanner_v1.types import result_set
3838
from google.cloud.spanner_v1.types import spanner
3939
from google.cloud.spanner_v1.types import transaction
40+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
4041
from google.protobuf import empty_pb2 # type: ignore
4142

4243

@@ -919,6 +920,7 @@ def __init__(
919920
url_scheme: str = "https",
920921
interceptor: Optional[SpannerRestInterceptor] = None,
921922
api_audience: Optional[str] = None,
923+
metrics_interceptor: Optional[MetricsInterceptor] = None,
922924
) -> None:
923925
"""Instantiate the transport.
924926

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from google.cloud.spanner_v1.types import result_set
2929
from google.cloud.spanner_v1.types import spanner
3030
from google.cloud.spanner_v1.types import transaction
31+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
3132
from google.protobuf import empty_pb2 # type: ignore
3233

3334

@@ -53,6 +54,7 @@ def __init__(
5354
always_use_jwt_access: Optional[bool] = False,
5455
url_scheme: str = "https",
5556
api_audience: Optional[str] = None,
57+
metrics_interceptor: Optional[MetricsInterceptor] = None,
5658
) -> None:
5759
"""Instantiate the transport.
5860
Args:

owlbot.py

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,96 @@ def get_staging_dirs(
8080
shutil.rmtree("samples/generated_samples", ignore_errors=True)
8181
clean_up_generated_samples = False
8282

83+
# Customization for MetricsInterceptor
84+
85+
assert 6 == s.replace(
86+
[
87+
library / "google/cloud/spanner_v1/services/spanner/transports/*.py",
88+
library / "google/cloud/spanner_v1/services/spanner/client.py",
89+
],
90+
"""from google.cloud.spanner_v1.types import transaction""",
91+
"""from google.cloud.spanner_v1.types import transaction
92+
from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor""",
93+
)
94+
95+
assert 1 == s.replace(
96+
library / "google/cloud/spanner_v1/services/spanner/transports/*.py",
97+
"""api_audience: Optional\[str\] = None,
98+
\*\*kwargs,
99+
\) -> None:
100+
\"\"\"Instantiate the transport.""",
101+
"""api_audience: Optional[str] = None,
102+
metrics_interceptor: Optional[MetricsInterceptor] = None,
103+
**kwargs,
104+
) -> None:
105+
\"\"\"Instantiate the transport."""
106+
)
107+
108+
assert 4 == s.replace(
109+
library / "google/cloud/spanner_v1/services/spanner/transports/*.py",
110+
"""api_audience: Optional\[str\] = None,
111+
\) -> None:
112+
\"\"\"Instantiate the transport.""",
113+
"""api_audience: Optional[str] = None,
114+
metrics_interceptor: Optional[MetricsInterceptor] = None,
115+
) -> None:
116+
\"\"\"Instantiate the transport."""
117+
)
118+
119+
assert 1 == s.replace(
120+
library / "google/cloud/spanner_v1/services/spanner/transports/grpc.py",
121+
"""\)\n\n self._interceptor = _LoggingClientInterceptor\(\)""",
122+
""")
123+
124+
# Wrap the gRPC channel with the metric interceptor
125+
if metrics_interceptor is not None:
126+
self._metrics_interceptor = metrics_interceptor
127+
self._grpc_channel = grpc.intercept_channel(
128+
self._grpc_channel, metrics_interceptor
129+
)
130+
131+
self._interceptor = _LoggingClientInterceptor()"""
132+
)
133+
134+
assert 1 == s.replace(
135+
library / "google/cloud/spanner_v1/services/spanner/transports/grpc.py",
136+
"""self._stubs: Dict\[str, Callable\] = \{\}\n\n if api_mtls_endpoint:""",
137+
"""self._stubs: Dict[str, Callable] = {}
138+
self._metrics_interceptor = None
139+
140+
if api_mtls_endpoint:"""
141+
)
142+
143+
assert 1 == s.replace(
144+
library / "google/cloud/spanner_v1/services/spanner/client.py",
145+
"""# initialize with the provided callable or the passed in class
146+
self._transport = transport_init\(
147+
credentials=credentials,
148+
credentials_file=self._client_options.credentials_file,
149+
host=self._api_endpoint,
150+
scopes=self._client_options.scopes,
151+
client_cert_source_for_mtls=self._client_cert_source,
152+
quota_project_id=self._client_options.quota_project_id,
153+
client_info=client_info,
154+
always_use_jwt_access=True,
155+
api_audience=self._client_options.api_audience,
156+
\)""",
157+
"""# initialize with the provided callable or the passed in class
158+
self._transport = transport_init(
159+
credentials=credentials,
160+
credentials_file=self._client_options.credentials_file,
161+
host=self._api_endpoint,
162+
scopes=self._client_options.scopes,
163+
client_cert_source_for_mtls=self._client_cert_source,
164+
quota_project_id=self._client_options.quota_project_id,
165+
client_info=client_info,
166+
always_use_jwt_access=True,
167+
api_audience=self._client_options.api_audience,
168+
metrics_interceptor=MetricsInterceptor(),
169+
)""",
170+
)
171+
172+
83173
s.move(
84174
library,
85175
excludes=[
@@ -96,11 +186,6 @@ def get_staging_dirs(
96186
for library in get_staging_dirs(
97187
spanner_admin_instance_default_version, "spanner_admin_instance"
98188
):
99-
s.replace(
100-
library / "google/cloud/spanner_admin_instance_v*/__init__.py",
101-
"from google.cloud.spanner_admin_instance import gapic_version as package_version",
102-
f"from google.cloud.spanner_admin_instance_{library.name} import gapic_version as package_version",
103-
)
104189
s.move(
105190
library,
106191
excludes=["google/cloud/spanner_admin_instance/**", "*.*", "docs/index.rst", "noxfile.py", "**/gapic_version.py", "testing/constraints-3.7.txt",],
@@ -109,11 +194,6 @@ def get_staging_dirs(
109194
for library in get_staging_dirs(
110195
spanner_admin_database_default_version, "spanner_admin_database"
111196
):
112-
s.replace(
113-
library / "google/cloud/spanner_admin_database_v*/__init__.py",
114-
"from google.cloud.spanner_admin_database import gapic_version as package_version",
115-
f"from google.cloud.spanner_admin_database_{library.name} import gapic_version as package_version",
116-
)
117197
s.move(
118198
library,
119199
excludes=["google/cloud/spanner_admin_database/**", "*.*", "docs/index.rst", "noxfile.py", "**/gapic_version.py", "testing/constraints-3.7.txt",],

0 commit comments

Comments
 (0)