Repository navigation
fix(spanner): record streaming operation completion when stream finishes - #18704
sinhasubham wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Spanner client's metrics tracking to ensure that streaming operation latencies are recorded immediately upon stream completion and exclude consumer processing delays. This is achieved by tracking stream completion in both synchronous and asynchronous snapshot iterators and recording metrics accordingly. However, the reviewer identified a critical issue in metrics_interceptor.py where the code attempts to check for a last attribute on the yielded stream items. Since the production PartialResultSet protobuf messages do not contain a last field, this check will always evaluate to False and act as dead code. It is recommended to remove these redundant checks.
| if getattr(item, "last", False) is True: | ||
| self._record_metrics() | ||
| return item |
There was a problem hiding this comment.
In production, the item yielded by the gRPC response iterator is a PartialResultSet protobuf message (or a proto-plus wrapper). The PartialResultSet proto definition does not contain a last field. Therefore, getattr(item, "last", False) will always return False in production, making this check dead code that never executes.
The integration tests pass only because they fully consume the stream (e.g., using list(results) or for _ in results), which raises StopIteration and triggers _record_metrics() in the except StopIteration block.
Since there is no last field in the Spanner PartialResultSet proto, we should remove this check to avoid dead code and false assumptions about the protobuf structure.
return item| if getattr(item, "last", False) is True: | ||
| await self._record_metrics() | ||
| return item |
There was a problem hiding this comment.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕