Skip to content

[DRAFT] feat: added client side metric instrumentation to read_rows and mutate_rows#16758

Draft
daniel-sanche wants to merge 5 commits intobigtable_csm_1_basic_instrumentationfrom
bigtable_csm_2_instrumentation_advanced
Draft

[DRAFT] feat: added client side metric instrumentation to read_rows and mutate_rows#16758
daniel-sanche wants to merge 5 commits intobigtable_csm_1_basic_instrumentationfrom
bigtable_csm_2_instrumentation_advanced

Conversation

@daniel-sanche
Copy link
Copy Markdown
Contributor

Migration of googleapis/python-bigtable#1256 to the monorepo

Builds off of #16712 to add instrumentation to read_rows and mutate_rows, along with the mutation batcher

@daniel-sanche daniel-sanche changed the title Bigtable csm 2 instrumentation advanced [DRAFT] feat: added client side metric instrumentation to read_rows and mutate_rows Apr 21, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates client-side metrics tracking into Bigtable data operations, including ReadRows and MutateRows, for both asynchronous and synchronous implementations. It introduces tracked_retry to capture operation metrics and refactors read_row to utilize operation classes directly, supported by extensive new system and unit tests. Feedback identifies opportunities to improve the efficiency of read_row by using next() or __anext__ on generators instead of converting them to lists, and suggests adding a type ignore comment in the synchronous code for consistency.

sleep_generator,
operation_timeout,
exception_factory=_retry_exception_factory,
self._operation = lambda: tracked_retry(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did sleep_generator and exception_factory go? will this still wrap timeout exceptions correctly into Deadline Exceeded excetpion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise close_exception
except Exception as generic_exception:
# handle exceptions in retry wrapper
raise generic_exception
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try extract the status code from Exception and call end_with_status in this block also? For example, if the stream timed out mid stream, will it be captured in the metrics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the exceptions are being captured by the tracked_retry object. I tried to cover the various tracking strategies here: go/bigtable-csm-python

bt_exceptions.FailedMutationEntryError(idx, entry, cause_exc)
)
if all_errors:
raise bt_exceptions.MutationsExceptionGroup(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this affect extracting the grpc status code for the metric since we wrap it in a different exception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have logic for converting exceptions to statuses is here. When we encounter an exception group, we use the last failure as the status

bt_exceptions.FailedMutationEntryError(idx, entry, cause_exc)
)
if all_errors:
raise bt_exceptions.MutationsExceptionGroup(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here, will this error code get extracted correctly for metrics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants