Repository navigation
Conversation
Custom Spanner topologies extend a Google-managed base configuration with optional read-only replicas via InstanceAdminClient.create_instance_config. Add spanner_create_instance_config.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new script and associated tests for creating custom Spanner instance configurations. The review feedback highlights a potential IndexError when accessing the first element of optional_replicas without verifying if the list is non-empty. It is recommended to add a safety check to prevent crashes when a base configuration lacks optional replicas.
|
|
||
| try: | ||
| base_config = client.get_instance_config(name=base_config_path) | ||
| replicas = list(base_config.replicas) + [base_config.optional_replicas[0]] |
There was a problem hiding this comment.
If the retrieved base_config does not contain any optional replicas, accessing base_config.optional_replicas[0] will raise an unhandled IndexError and crash the sample. It is safer to check if optional_replicas is non-empty before attempting to access its first element.
if not base_config.optional_replicas:
print(
f"error: base config '{base_config_id}' has no optional replicas.",
file=sys.stderr,
)
return
replicas = list(base_config.replicas) + [base_config.optional_replicas[0]]There was a problem hiding this comment.
Good catch, done: the sample now reports a clear error on stderr when the base config has no optional replicas, and a unit test covers it (a5d1c65).
Problem: review of this sample identified correctness and robustness improvements in the sample and its tests. Solution: apply the accepted review suggestions and extend the tests to cover the updated behavior. Details are in the review thread replies. Files updated: - spanner/instance_admin/src/spanner_instance_admin/create_instance_config.py - spanner/instance_admin/tests/create_instance_config_test.py
Description
Adds
spanner_create_instance_configcreating acustom-*user-managed Spanner instance configuration.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions