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