Skip to content

chore: migrate Spanner core samples batch 4 (exact copy)#4279

Closed
angelcaamal wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
angelcaamal:migration-batch-4
Closed

chore: migrate Spanner core samples batch 4 (exact copy)#4279
angelcaamal wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
angelcaamal:migration-batch-4

Conversation

@angelcaamal
Copy link
Copy Markdown
Contributor

@angelcaamal angelcaamal commented Apr 8, 2026

Description

Fixes internal: b/500480522

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

@angelcaamal angelcaamal self-assigned this Apr 8, 2026
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 8, 2026
@angelcaamal angelcaamal removed their assignment Apr 8, 2026
@angelcaamal angelcaamal added samples Issues that are directly related to samples. and removed samples Issues that are directly related to samples. labels Apr 8, 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 introduces a comprehensive set of new Cloud Spanner code samples covering database management (default leader, DDL), instance configurations (CRUD, operations), instance partitions, sequences, and observability with OpenTelemetry. Additionally, it enables several system tests that were previously skipped. Feedback includes correcting a bug in instance-config-update.js where a global proto reference was being overwritten, improving safety when handling optional replicas in instance-config-create.js, and fixing a default parameter typo in observability-traces.js.

Comment on lines +67 to +69
updateMask: (protos.google.protobuf.FieldMask = {
paths: ['display_name', 'labels'],
}),
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.

high

The assignment to protos.google.protobuf.FieldMask inside the object literal is a bug. It overwrites the FieldMask reference in the protos object, which could lead to unexpected behavior in other parts of the application. It should simply be an object literal.

Suggested change
updateMask: (protos.google.protobuf.FieldMask = {
paths: ['display_name', 'labels'],
}),
updateMask: {
paths: ['display_name', 'labels'],
},

Comment on lines +74 to +76
replicas: baseInstanceConfig.replicas.concat(
baseInstanceConfig.optionalReplicas[0]
),
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.

medium

Accessing baseInstanceConfig.optionalReplicas[0] without checking if the array exists or has elements can lead to undefined being passed to concat. This results in an array containing undefined, which will likely cause the API request to fail. Using slice(0, 1) is a safer way to get at most one element as an array.

Suggested change
replicas: baseInstanceConfig.replicas.concat(
baseInstanceConfig.optionalReplicas[0]
),
replicas: baseInstanceConfig.replicas.concat(
(baseInstanceConfig.optionalReplicas || []).slice(0, 1)
),

async function main(
projectId = 'my-project-id',
instanceId = 'my-instance-id',
databaseId = 'my-project-id'
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.

medium

The default value for databaseId is incorrectly set to 'my-project-id'. It should likely be 'my-database-id' to match the pattern of other parameters.

Suggested change
databaseId = 'my-project-id'
databaseId = 'my-database-id'

@angelcaamal angelcaamal closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant