Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 011fd84

Browse files
committed
Merge branch 'csm_3_handlers' into csm_3_handlers->instrumentation
2 parents 7338c84 + 18afdb7 commit 011fd84

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@
3939
dependencies = [
4040
"google-api-core[grpc] >= 2.17.0, <3.0.0",
4141
"google-cloud-core >= 1.4.4, <3.0.0",
42+
"google-cloud-monitoring >= 2.0.0, <3.0.0dev",
4243
"google-auth >= 2.23.0, <3.0.0,!=2.24.0,!=2.25.0",
4344
"grpc-google-iam-v1 >= 0.12.4, <1.0.0",
4445
"proto-plus >= 1.22.3, <2.0.0",
4546
"proto-plus >= 1.25.0, <2.0.0; python_version>='3.13'",
4647
"protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
4748
"google-crc32c>=1.5.0, <2.0.0dev",
49+
"googleapis-common-protos[grpc] >= 1.57.0, <2.0.0dev",
50+
"opentelemetry-api >= 1.0.0, <2.0.0dev",
51+
"opentelemetry-sdk >= 1.0.0, <2.0.0dev",
4852
]
4953
extras = {"libcst": "libcst >= 0.2.5"}
5054

tests/system/data/test_metrics_async.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Google LLC
1+
# Copyright 2025 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -2187,3 +2187,72 @@ async def test_check_and_mutate_row_failure_unauthorized(
21872187
attempt.gfe_latency_ns >= 0
21882188
and attempt.gfe_latency_ns < operation.duration_ns
21892189
)
2190+
2191+
2192+
@CrossSync.convert_class(sync_name="TestExportedMetrics")
2193+
class TestExportedExportedMetricsAsync(SystemTestRunner):
2194+
2195+
@CrossSync.drop
2196+
@pytest.fixture(scope="session")
2197+
def event_loop(self):
2198+
loop = asyncio.get_event_loop()
2199+
yield loop
2200+
loop.stop()
2201+
loop.close()
2202+
2203+
def _make_client(self):
2204+
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
2205+
return CrossSync.DataClient(project=project)
2206+
2207+
@CrossSync.convert
2208+
@CrossSync.pytest_fixture(scope="session")
2209+
async def client(self):
2210+
async with self._make_client() as client:
2211+
yield client
2212+
2213+
@pytest.fixture(scope="session")
2214+
def metrics_client(self, client):
2215+
yield client._gcp_metrics_exporter.client
2216+
2217+
2218+
@CrossSync.convert
2219+
@CrossSync.pytest_fixture(scope="function")
2220+
async def temp_rows(self, table):
2221+
builder = CrossSync.TempRowBuilder(table)
2222+
yield builder
2223+
await builder.delete_rows()
2224+
2225+
@CrossSync.convert
2226+
@CrossSync.pytest_fixture(scope="session")
2227+
async def table(self, client, table_id, instance_id):
2228+
async with client.get_table(instance_id, table_id) as table:
2229+
yield table
2230+
2231+
@CrossSync.pytest
2232+
async def test_read_rows(self, table, temp_rows, metrics_client):
2233+
from datetime import datetime, timedelta, timezone
2234+
from google.cloud import monitoring_v3
2235+
2236+
await temp_rows.add_row(b"row_key_1")
2237+
await temp_rows.add_row(b"row_key_2")
2238+
row_list = await table.read_rows(ReadRowsQuery())
2239+
# read back metrics
2240+
2241+
# 1. Define the Time Interval
2242+
now = datetime.now(timezone.utc)
2243+
# The end time is inclusive
2244+
end_time = now
2245+
# The start time is exclusive, for an interval (startTime, endTime]
2246+
start_time = now - timedelta(minutes=5)
2247+
2248+
interval = {"start_time": start_time, "end_time": end_time}
2249+
metric_filter = (
2250+
'metric.type = "bigtable.googleapis.com/client/attempt_latencies" AND metric.labels.client_name != "go-bigtable/1.40.0"'
2251+
)
2252+
results = metrics_client.list_time_series(
2253+
name=f"projects/{table.client.project}",
2254+
filter=metric_filter,
2255+
interval=interval,
2256+
view=monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL,
2257+
)
2258+
print(results)

0 commit comments

Comments
 (0)