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

Commit b815674

Browse files
committed
added test for sample_row_keys
1 parent 542dfb9 commit b815674

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

google/cloud/bigtable/data/_async/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,7 @@ async def execute_rpc():
13531353
),
13541354
timeout=next(attempt_timeout_gen),
13551355
retry=None,
1356+
metadata=[operation_metric.interceptor_metadata],
13561357
)
13571358
return [(s.row_key, s.offset_bytes) async for s in results]
13581359

google/cloud/bigtable/data/_async/metrics_interceptor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from google.cloud.bigtable.data._metrics.data_model import ActiveOperationMetric
2222
from google.cloud.bigtable.data._metrics.data_model import OperationState
23+
from google.cloud.bigtable.data._metrics.data_model import OperationType
2324
from google.cloud.bigtable.data._metrics.handlers._base import MetricsHandler
2425

2526
from google.cloud.bigtable.data._cross_sync import CrossSync
@@ -129,7 +130,8 @@ async def intercept_unary_stream(
129130
):
130131
# TODO: benchmark
131132
async def response_wrapper(call):
132-
has_first_response = operation.first_response_latency is not None
133+
# only track has_first response for READ_ROWS
134+
has_first_response = operation.first_response_latency_ns is not None or operation.op_type != OperationType.READ_ROWS
133135
encountered_exc = None
134136
try:
135137
async for response in call:

tests/system/data/test_metrics_async.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,35 @@ async def target(self, client, table_id, instance_id, handler):
9797
table._metrics.add_handler(handler)
9898
yield table
9999

100+
@CrossSync.pytest
101+
async def test_sample_row_keys(self, target, temp_rows, handler, cluster_config):
102+
await target.sample_row_keys()
103+
# validate counts
104+
assert len(handler.completed_operations) == 1
105+
assert len(handler.completed_attempts) == 1
106+
assert len(handler.cancelled_operations) == 0
107+
# validate operation
108+
operation = handler.completed_operations[0]
109+
assert isinstance(operation, CompletedOperationMetric)
110+
assert operation.final_status.value[0] == 0
111+
assert operation.is_streaming is False
112+
assert operation.op_type.value == "SampleRowKeys"
113+
assert len(operation.completed_attempts) == 1
114+
assert operation.completed_attempts[0] == handler.completed_attempts[0]
115+
assert operation.cluster_id == next(iter(cluster_config.keys()))
116+
assert operation.zone == cluster_config[operation.cluster_id].location.split("/")[-1]
117+
assert operation.duration_ns > 0 and operation.duration_ns < 1e9
118+
assert operation.first_response_latency_ns is None # populated for read_rows only
119+
assert operation.flow_throttling_time_ns == 0
120+
# validate attempt
121+
attempt = handler.completed_attempts[0]
122+
assert attempt.duration_ns > 0 and attempt.duration_ns < operation.duration_ns
123+
assert attempt.end_status.value[0] == 0
124+
assert attempt.backoff_before_attempt_ns == 0
125+
assert attempt.gfe_latency_ns > 0 and attempt.gfe_latency_ns < attempt.duration_ns
126+
assert attempt.application_blocking_time_ns == 0
127+
assert attempt.grpc_throttling_time_ns == 0 # TODO: confirm
128+
100129
@CrossSync.pytest
101130
async def test_read_modify_write(self, target, temp_rows, handler, cluster_config):
102131
from google.cloud.bigtable.data.read_modify_write_rules import IncrementRule

0 commit comments

Comments
 (0)