Repository navigation
Conversation
Monitoring active CreateBackup and CopyBackup operations filters DatabaseAdminClient.list_backup_operations by metadata type and resource. Add spanner_list_backup_operations.
|
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, list_backup_operations.py, along with its corresponding tests, to list CreateBackup and CopyBackup long-running operations on a Google Cloud Spanner instance. The feedback suggests using fully qualified resource paths instead of simple IDs in the API filters to avoid unintended substring matches and ensure precise filtering.
| create_filter = ( | ||
| "(metadata.@type:type.googleapis.com/" | ||
| "google.spanner.admin.database.v1.CreateBackupMetadata) " | ||
| f"AND (metadata.database:{database_id})" | ||
| ) | ||
| copy_filter = ( | ||
| "(metadata.@type:type.googleapis.com/" | ||
| "google.spanner.admin.database.v1.CopyBackupMetadata) " | ||
| f"AND (metadata.source_backup:{backup_id})" | ||
| ) |
There was a problem hiding this comment.
Using a simple ID like database_id or backup_id in the filter with the : operator can lead to incorrect matches. Because : is a substring/contains operator, if the ID is a substring of the project ID, instance ID, or another database/backup name, the filter will match unintended resources. Constructing and using the fully qualified resource path ensures precise filtering.
database_path = f"projects/{project_id}/instances/{instance_id}/databases/{database_id}"
backup_path = f"projects/{project_id}/instances/{instance_id}/backups/{backup_id}"
create_filter = (
"(metadata.@type:type.googleapis.com/"
"google.spanner.admin.database.v1.CreateBackupMetadata) "
f"AND (metadata.database:{database_path})"
)
copy_filter = (
"(metadata.@type:type.googleapis.com/"
"google.spanner.admin.database.v1.CopyBackupMetadata) "
f"AND (metadata.source_backup:{backup_path})"
)There was a problem hiding this comment.
Thanks! Keeping the ID-based filter: it keeps the sample simple, and it is meant to be run with IDs that are unique within the instance.
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/backups/tests/list_backup_operations_test.py
Description
Adds
spanner_list_backup_operationslistingCreateBackupMetadataandCopyBackupMetadataoperations on an instance.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions