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

Commit a35a6b6

Browse files
committed
added start of system tests for metrics
2 parents bb55c46 + b57ab24 commit a35a6b6

7 files changed

Lines changed: 320 additions & 54 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ async def _run_attempt(self):
187187
),
188188
timeout=next(self.timeout_generator),
189189
retry=None,
190+
metadata=[self._operation_metric.interceptor_metadata],
190191
)
191192
async for result_list in result_generator:
192193
for result in result_list.entries:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def _read_rows_attempt(self) -> CrossSync.Iterable[Row]:
156156
self.request,
157157
timeout=next(self.attempt_timeout_gen),
158158
retry=None,
159+
metadata=[self._operation_metric.interceptor_metadata],
159160
)
160161
chunked_stream = self.chunk_stream(gapic_stream)
161162
return self.merge_rows(chunked_stream)

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

Lines changed: 6 additions & 2 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

@@ -1488,6 +1489,7 @@ async def mutate_row(
14881489
),
14891490
timeout=attempt_timeout,
14901491
retry=None,
1492+
metadata=[operation_metric.interceptor_metadata],
14911493
)
14921494
return await CrossSync.retry_target(
14931495
target,
@@ -1608,7 +1610,7 @@ async def check_and_mutate_row(
16081610
false_case_mutations = [false_case_mutations]
16091611
false_case_list = [m._to_pb() for m in false_case_mutations or []]
16101612

1611-
with self._metrics.create_operation(OperationType.CHECK_AND_MUTATE):
1613+
with self._metrics.create_operation(OperationType.CHECK_AND_MUTATE) as op:
16121614
result = await self.client._gapic_client.check_and_mutate_row(
16131615
request=CheckAndMutateRowRequest(
16141616
true_mutations=true_case_list,
@@ -1624,6 +1626,7 @@ async def check_and_mutate_row(
16241626
),
16251627
timeout=operation_timeout,
16261628
retry=None,
1629+
metadata=[op.interceptor_metadata],
16271630
)
16281631
return result.predicate_matched
16291632

@@ -1666,7 +1669,7 @@ async def read_modify_write_row(
16661669
if not rules:
16671670
raise ValueError("rules must contain at least one item")
16681671

1669-
with self._metrics.create_operation(OperationType.READ_MODIFY_WRITE):
1672+
with self._metrics.create_operation(OperationType.READ_MODIFY_WRITE) as op:
16701673
result = await self.client._gapic_client.read_modify_write_row(
16711674
request=ReadModifyWriteRowRequest(
16721675
rules=[rule._to_pb() for rule in rules],
@@ -1678,6 +1681,7 @@ async def read_modify_write_row(
16781681
),
16791682
timeout=operation_timeout,
16801683
retry=None,
1684+
metadata=[op.interceptor_metadata],
16811685
)
16821686
# construct Row from result
16831687
return Row._from_pb(result.row)

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/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,67 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import asyncio
17+
import pytest
18+
import uuid
19+
from google.cloud.bigtable.data._cross_sync import CrossSync
1620

1721
TEST_FAMILY = "test-family"
1822
TEST_FAMILY_2 = "test-family-2"
1923
TEST_AGGREGATE_FAMILY = "test-aggregate-family"
24+
25+
class SystemTestRunner:
26+
"""
27+
configures a system test class with configuration for clusters/tables/etc
28+
29+
used by standard system tests, and metrics tests
30+
"""
31+
32+
@CrossSync.drop
33+
@pytest.fixture(scope="session")
34+
def event_loop(self):
35+
loop = asyncio.get_event_loop()
36+
yield loop
37+
loop.stop()
38+
loop.close()
39+
40+
@pytest.fixture(scope="session")
41+
def init_table_id(self):
42+
"""
43+
The table_id to use when creating a new test table
44+
"""
45+
return f"test-table-{uuid.uuid4().hex}"
46+
47+
@pytest.fixture(scope="session")
48+
def cluster_config(self, project_id):
49+
"""
50+
Configuration for the clusters to use when creating a new instance
51+
"""
52+
from google.cloud.bigtable_admin_v2 import types
53+
54+
cluster = {
55+
"test-cluster": types.Cluster(
56+
location=f"projects/{project_id}/locations/us-central1-b",
57+
serve_nodes=1,
58+
)
59+
}
60+
return cluster
61+
62+
@pytest.fixture(scope="session")
63+
def column_family_config(self):
64+
"""
65+
specify column families to create when creating a new test table
66+
"""
67+
from google.cloud.bigtable_admin_v2 import types
68+
69+
int_aggregate_type = types.Type.Aggregate(
70+
input_type=types.Type(int64_type={"encoding": {"big_endian_bytes": {}}}),
71+
sum={},
72+
)
73+
return {
74+
TEST_FAMILY: types.ColumnFamily(),
75+
TEST_FAMILY_2: types.ColumnFamily(),
76+
TEST_AGGREGATE_FAMILY: types.ColumnFamily(
77+
value_type=types.Type(aggregate_type=int_aggregate_type)
78+
),
79+
}

0 commit comments

Comments
 (0)