Skip to content

refactor: move default region resolution to service interface#10586

Open
wandamora wants to merge 2 commits into
mainfrom
morawand-refactor-region-handling
Open

refactor: move default region resolution to service interface#10586
wandamora wants to merge 2 commits into
mainfrom
morawand-refactor-region-handling

Conversation

@wandamora
Copy link
Copy Markdown
Contributor

Description

This PR refactors the trigger default region resolution logic during Cloud Functions deployment to make it less brittle, easier to maintain, and more scalable.

Previously, prepare.ts contained complex service-specific logic and switch/if blocks to inspect different event types (Firestore, Cloud Storage, Realtime Database, etc.) and look up their corresponding default regions. This was highly brittle: if a new service or event type is added, developers would have to manually update prepare.ts, which could be easy to miss.

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 refactors trigger region resolution by delegating the default region lookup to individual services via a new getDefaultRegion method on the Service interface. It also consolidates multi-region mappings and the isUSRegion helper into src/gcp/location.ts. Feedback on the changes suggests avoiding the use of as any in serviceForEndpoint by using the in operator for type narrowing, and removing the unused endpoint parameter in AuthBlockingService.getDefaultRegion instead of disabling the ESLint rule.

Comment thread src/deploy/functions/services/index.ts
Comment thread src/deploy/functions/services/auth.ts Outdated
return "us-east1";
async function resolveRegionForTrigger(endpoint: build.Endpoint): Promise<string> {
const service = serviceForEndpoint(endpoint);
if (service.getDefaultRegion) {
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.

I will do a full review soon but taking a quick glance now.

Do you think we should make this a required method for the Service interface? Then we'd never forget it for new services. But I don't know if we want to hard code the us-central default in a million places. Something to mull over.

validateTrigger: noop,
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve("us-east1"),
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 use a constant for this region?

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.

3 participants