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

Commit 53669f7

Browse files
committed
simplified metric existance check
1 parent c5a08c5 commit 53669f7

1 file changed

Lines changed: 36 additions & 56 deletions

File tree

tests/system/data/test_system_async.py

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,65 +1337,45 @@ async def test_execute_metadata_on_empty_response(
13371337
SqlType.Bytes(), SqlType.Int64()
13381338
)
13391339

1340+
@pytest.fixture(scope="session")
1341+
def metrics_client(self, client):
1342+
yield client._gcp_metrics_exporter.client
1343+
13401344
@pytest.mark.order("last")
1341-
class TestExportedMetrics(SystemTestRunner):
1345+
@pytest.mark.parametrize(
1346+
"metric,methods",
1347+
[
1348+
("attempt_latencies", [m.value for m in OperationType]),
1349+
("operation_latencies", [m.value for m in OperationType]),
1350+
("retry_count", [m.value for m in OperationType]),
1351+
("first_response_latencies", [OperationType.READ_ROWS]),
1352+
("server_latencies", [m.value for m in OperationType]),
1353+
("connectivity_error_count", [m.value for m in OperationType]),
1354+
("application_blocking_latencies", [OperationType.READ_ROWS]),
1355+
],
1356+
)
1357+
@retry.Retry(predicate=retry.if_exception_type(AssertionError))
1358+
def test_metric_existence(
1359+
self, client, table_id, metrics_client, start_timestamp, metric, methods
1360+
):
13421361
"""
13431362
Checks to make sure metrics were exported by tests
13441363
1345-
Runs at the end of test suite, to allow other tests to write metrics
1364+
Runs at the end of test suite, to let other tests write metrics
13461365
"""
1347-
1348-
@pytest.fixture(scope="session")
1349-
def metrics_client(self, client):
1350-
yield client._gcp_metrics_exporter.client
1351-
1352-
@pytest.fixture(scope="session")
1353-
def time_interval(self, start_timestamp):
1354-
"""
1355-
Build a time interval between when system tests started, and the exported metric tests
1356-
1357-
Optionally adds LOOKBACK_MINUTES value for testing
1358-
"""
1359-
end_time = datetime.datetime.now(datetime.timezone.utc)
1360-
LOOKBACK_MINUTES = os.getenv("LOOKBACK_MINUTES")
1361-
if LOOKBACK_MINUTES is not None:
1362-
print(f"running with LOOKBACK_MINUTES={LOOKBACK_MINUTES}")
1363-
start_timestamp = start_timestamp - datetime.timedelta(
1364-
minutes=int(LOOKBACK_MINUTES)
1365-
)
1366-
return {"start_time": start_timestamp, "end_time": end_time}
1367-
1368-
@pytest.mark.parametrize(
1369-
"metric,methods",
1370-
[
1371-
("attempt_latencies", [m.value for m in OperationType]),
1372-
("operation_latencies", [m.value for m in OperationType]),
1373-
("retry_count", [m.value for m in OperationType]),
1374-
("first_response_latencies", [OperationType.READ_ROWS]),
1375-
("server_latencies", [m.value for m in OperationType]),
1376-
("connectivity_error_count", [m.value for m in OperationType]),
1377-
("application_blocking_latencies", [OperationType.READ_ROWS]),
1378-
],
1379-
)
1380-
@retry.Retry(predicate=retry.if_exception_type(AssertionError))
1381-
def test_metric_existence(
1382-
self, client, table_id, metrics_client, time_interval, metric, methods
1383-
):
1384-
"""
1385-
Checks existence of each metric in Cloud Monitoring
1386-
"""
1387-
for m in methods:
1388-
metric_filter = (
1389-
f'metric.type = "bigtable.googleapis.com/client/{metric}" '
1390-
+ f'AND metric.labels.client_name = "python-bigtable/{client._client_version()}" '
1391-
+ f'AND resource.labels.table = "{table_id}" '
1392-
)
1393-
results = list(
1394-
metrics_client.list_time_series(
1395-
name=f"projects/{client.project}",
1396-
filter=metric_filter,
1397-
interval=time_interval,
1398-
view=0,
1399-
)
1366+
end_timestamp = datetime.datetime.now(datetime.timezone.utc)
1367+
for m in methods:
1368+
metric_filter = (
1369+
f'metric.type = "bigtable.googleapis.com/client/{metric}" '
1370+
+ f'AND metric.labels.client_name = "python-bigtable/{client._client_version()}" '
1371+
+ f'AND resource.labels.table = "{table_id}" '
1372+
)
1373+
results = list(
1374+
metrics_client.list_time_series(
1375+
name=f"projects/{client.project}",
1376+
filter=metric_filter,
1377+
interval={"start_time": start_timestamp, "end_time": end_timestamp},
1378+
view=0,
14001379
)
1401-
assert len(results) > 0, f"No data found for {metric} {m}"
1380+
)
1381+
assert len(results) > 0, f"No data found for {metric} {m}"

0 commit comments

Comments
 (0)