Repository navigation
feat(bigtable): pass user agent, tests and start timeout env variable - #18686
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a --caller-user-agent flag containing the Python client version to the accelerator flags in both the async and sync Bigtable data clients, along with corresponding unit tests. The feedback recommends importing google.cloud.bigtable locally within the configuration method to avoid potential circular imports, NameError, or AttributeError issues.
- Remove _AcceleratorUnverified alias (no longer needed) - Remove duplicate User-Agent flags block from _init_accelerator_config; keep only the early block so the flag is forwarded even when the daemon is blocked - Move _AcceleratorIdentityError handling into _start_accelerator: close daemon, warn 'could not verify daemon identity', return without re-raising - Remove test_binary_path_param_bypasses_lookup (binary_path is a test-only knob already exercised implicitly) - Add test_close_clears_all_state to verify _proc/_tempdir/_uds_path/_log_path/_auth_secret are all None after close() - Add --app-profile to TestCliFlags.test_cli_flags_appended_to_argv - Add assert not t._accelerator_breaker.bypass() to test_non_grpc_exception_reraises in both TestMutateRowViaAccelerator and TestReadRowViaAccelerator Change-Id: Iff4489acc63a6e71211939c23db04ff1a5df10ba
- Remove _AcceleratorUnverified alias (no longer needed) - Remove duplicate User-Agent flags block from _init_accelerator_config; keep only the early block so the flag is forwarded even when the daemon is blocked - Add local import google.cloud.bigtable inside _init_accelerator_config to avoid potential circular import at module level - Move _AcceleratorIdentityError handling into _start_accelerator: close daemon, warn 'could not verify daemon identity', return without re-raising - Remove test_binary_path_param_bypasses_lookup (binary_path is a test-only knob already exercised implicitly) - Add --app-profile to TestCliFlags.test_cli_flags_appended_to_argv - Add assert not t._accelerator_breaker.bypass() to test_non_grpc_exception_reraises in both TestMutateRowViaAccelerator and TestReadRowViaAccelerator Change-Id: I43b354ad6517a2c0b9f6a2294cdd2d1639d7fe8c
- Remove _AcceleratorUnverified alias (no longer needed) - Remove duplicate User-Agent flags block from _init_accelerator_config; keep only the early block so the flag is forwarded even when the daemon is blocked - Move _AcceleratorIdentityError handling into _start_accelerator: close daemon, warn 'could not verify daemon identity', return without re-raising - Remove test_binary_path_param_bypasses_lookup (binary_path is a test-only knob already exercised implicitly) - Add test_close_clears_all_state to verify _proc/_tempdir/_uds_path/_log_path/_auth_secret are all None after close() - Add --app-profile to TestCliFlags.test_cli_flags_appended_to_argv - Add assert not t._accelerator_breaker.bypass() to test_non_grpc_exception_reraises in both TestMutateRowViaAccelerator and TestReadRowViaAccelerator Change-Id: Iff4489acc63a6e71211939c23db04ff1a5df10ba review(bigtable): address PR #18686 reviewer comments - Remove _AcceleratorUnverified alias (no longer needed) - Remove duplicate User-Agent flags block from _init_accelerator_config; keep only the early block so the flag is forwarded even when the daemon is blocked - Add local import google.cloud.bigtable inside _init_accelerator_config to avoid potential circular import at module level - Move _AcceleratorIdentityError handling into _start_accelerator: close daemon, warn 'could not verify daemon identity', return without re-raising - Remove test_binary_path_param_bypasses_lookup (binary_path is a test-only knob already exercised implicitly) - Add --app-profile to TestCliFlags.test_cli_flags_appended_to_argv - Add assert not t._accelerator_breaker.bypass() to test_non_grpc_exception_reraises in both TestMutateRowViaAccelerator and TestReadRowViaAccelerator Change-Id: I43b354ad6517a2c0b9f6a2294cdd2d1639d7fe8c test(bigtable): add TestCleanupTempdir to verify _cleanup_tempdir clears all state Change-Id: I6d6ec51cc039c78d884451502b368862fe8d4ae3
…User-Agent prefixing Pass --caller-user-agent python-v<version> when spawning the daemon so it can construct the full User-Agent prefix (e.g. python-v3.0.0a0-go-accelerator-v3.x.x) for accurate audit logging and traffic attribution. Change-Id: I621217335ad54377a84d44ab4b9af88770dd2958
…patch, and daemon lifecycle
- Remove _AcceleratorUnverified alias (no longer needed) - Remove duplicate User-Agent flags block from _init_accelerator_config; keep only the early block so the flag is forwarded even when the daemon is blocked - Move _AcceleratorIdentityError handling into _start_accelerator: close daemon, warn 'could not verify daemon identity', return without re-raising - Remove test_binary_path_param_bypasses_lookup (binary_path is a test-only knob already exercised implicitly) - Add test_close_clears_all_state to verify _proc/_tempdir/_uds_path/_log_path/_auth_secret are all None after close() - Add --app-profile to TestCliFlags.test_cli_flags_appended_to_argv - Add assert not t._accelerator_breaker.bypass() to test_non_grpc_exception_reraises in both TestMutateRowViaAccelerator and TestReadRowViaAccelerator Change-Id: Iff4489acc63a6e71211939c23db04ff1a5df10ba review(bigtable): address PR #18686 reviewer comments - Remove _AcceleratorUnverified alias (no longer needed) - Remove duplicate User-Agent flags block from _init_accelerator_config; keep only the early block so the flag is forwarded even when the daemon is blocked - Add local import google.cloud.bigtable inside _init_accelerator_config to avoid potential circular import at module level - Move _AcceleratorIdentityError handling into _start_accelerator: close daemon, warn 'could not verify daemon identity', return without re-raising - Remove test_binary_path_param_bypasses_lookup (binary_path is a test-only knob already exercised implicitly) - Add --app-profile to TestCliFlags.test_cli_flags_appended_to_argv - Add assert not t._accelerator_breaker.bypass() to test_non_grpc_exception_reraises in both TestMutateRowViaAccelerator and TestReadRowViaAccelerator Change-Id: I43b354ad6517a2c0b9f6a2294cdd2d1639d7fe8c test(bigtable): add TestCleanupTempdir to verify _cleanup_tempdir clears all state Change-Id: I6d6ec51cc039c78d884451502b368862fe8d4ae3
…e auth session Change-Id: I78f226004fdffe98d83f7d24b04557a24e9fc7a7
…o prevent orphaned daemon on BaseException Change-Id: I6f4c18f5b03da26efa9b70ed8c6b4d20f9d4a8df
| self._accelerator_env["GOOGLE_APPLICATION_CREDENTIALS"] = ( | ||
| credentials_file | ||
| ) | ||
|
|
||
| def _resolve_principal(self) -> str | None: |
There was a problem hiding this comment.
Missing blank line between the end of _init_accelerator_config and def _resolve_principal — PEP 8 / black / flake8 (E301) want one. Looks like a CrossSync regen artifact; adding the blank line in the async source and re-running the generator should restore it in the sync file.
| self._accelerator_env["GOOGLE_APPLICATION_CREDENTIALS"] = ( | |
| credentials_file | |
| ) | |
| def _resolve_principal(self) -> str | None: | |
| self._accelerator_env["GOOGLE_APPLICATION_CREDENTIALS"] = ( | |
| credentials_file | |
| ) | |
| def _resolve_principal(self) -> str | None: |
| import google.cloud.bigtable # local import avoids circular dependency | ||
|
|
||
| self._accelerator_flags += [ | ||
| "--caller-user-agent", | ||
| f"python-v{google.cloud.bigtable.__version__}", | ||
| ] |
There was a problem hiding this comment.
Pulling in the entire google.cloud.bigtable package on every Table init is overkill when all we want is the version string. Switch to importlib.metadata (stdlib since 3.8), which avoids the circular-dep motivation entirely:
| import google.cloud.bigtable # local import avoids circular dependency | |
| self._accelerator_flags += [ | |
| "--caller-user-agent", | |
| f"python-v{google.cloud.bigtable.__version__}", | |
| ] | |
| from importlib.metadata import version as _pkg_version | |
| self._accelerator_flags += [ | |
| "--caller-user-agent", | |
| f"python-v{_pkg_version('google-cloud-bigtable')}", | |
| ] |
(Can be hoisted to a module-level import if you'd rather; local keeps it self-contained with the use site.)
There was a problem hiding this comment.
removed the import line. I think this is already imported.
…n accelerator blocked, regenerate sync client Change-Id: Ia71d293208e7340bf9cab5cfa9f7e81ce7bb20b5
sushanb
left a comment
There was a problem hiding this comment.
LGTM with the inline suggestions above (docstring, user-agent placement, blank-line regen, inf/nan guard, importlib.metadata). None are blockers; happy to see them land as follow-ups or folded in before merge.
Stack created with GitHub Stacks CLI • Give Feedback 💬