[DRAFT] fix(bigtable): standardize client side metrics#17899
[DRAFT] fix(bigtable): standardize client side metrics#17899daniel-sanche wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors how throttling and application latencies are recorded in OpenTelemetry. Specifically, throttling latencies are now recorded on operation completion rather than attempt completion, and only for bulk mutate rows operations. Additionally, application latencies no longer include backoff time. The review feedback highlights a potential TypeError if flow_throttling_time_ns is None during the operation completion check, recommending a defensive check and an accompanying unit test to handle this case safely.
| if ( | ||
| op.op_type == OperationType.BULK_MUTATE_ROWS | ||
| and op.flow_throttling_time_ns > 0 | ||
| ): | ||
| self.otel.throttling_latencies.record( | ||
| op.flow_throttling_time_ns / NS_TO_MS, labels | ||
| ) |
There was a problem hiding this comment.
If op.flow_throttling_time_ns is None, evaluating op.flow_throttling_time_ns > 0 will raise a TypeError at runtime. Adding a defensive check to ensure it is not None before comparison prevents potential crashes.
| if ( | |
| op.op_type == OperationType.BULK_MUTATE_ROWS | |
| and op.flow_throttling_time_ns > 0 | |
| ): | |
| self.otel.throttling_latencies.record( | |
| op.flow_throttling_time_ns / NS_TO_MS, labels | |
| ) | |
| if ( | |
| op.op_type == OperationType.BULK_MUTATE_ROWS | |
| and op.flow_throttling_time_ns is not None | |
| and op.flow_throttling_time_ns > 0 | |
| ): | |
| self.otel.throttling_latencies.record( | |
| op.flow_throttling_time_ns / NS_TO_MS, labels | |
| ) |
| @pytest.mark.parametrize( | ||
| "is_first_attempt,flow_throttling_ns", | ||
| [(True, 54321), (False, 0), (True, 0)], | ||
| "op_type,flow_throttling_ns,should_record", | ||
| [ | ||
| (OperationType.BULK_MUTATE_ROWS, 54321, True), | ||
| (OperationType.BULK_MUTATE_ROWS, 0, False), | ||
| (OperationType.READ_ROWS, 54321, False), | ||
| ], | ||
| ) |
There was a problem hiding this comment.
Add a test case where flow_throttling_ns is None to verify that the handler safely handles None values without raising a TypeError.
@pytest.mark.parametrize(
"op_type,flow_throttling_ns,should_record",
[
(OperationType.BULK_MUTATE_ROWS, 54321, True),
(OperationType.BULK_MUTATE_ROWS, 0, False),
(OperationType.BULK_MUTATE_ROWS, None, False),
(OperationType.READ_ROWS, 54321, False),
],
)
Made some adjustments to the client side metrics system after comparing against node and java implemenations (with gemini)
The diffs for each commit can be looked it in isolation
1 (0b3600d): throttling_latencies is now recorded once per operation
2 (b44895d): removing backoff time from application blocking latencies