Skip to content

refactor: resolve function regions during build phase to fix VPC connectors#10471

Merged
wandamora merged 5 commits into
mainfrom
ajp-speculative-tbd-fix-yolo
May 12, 2026
Merged

refactor: resolve function regions during build phase to fix VPC connectors#10471
wandamora merged 5 commits into
mainfrom
ajp-speculative-tbd-fix-yolo

Conversation

@wandamora
Copy link
Copy Markdown
Contributor

@wandamora wandamora commented May 7, 2026

This moves the resolution logic to be before we resolve the build to a backend to set the defaults in functions, and the correct region can be known when building the VPC connector identfier.

Scenarios Tested

Create function with VPC connector
firebase deploy --only functions on 15.16.0
Update function and use local firebase-tools build
firebase deploy --only functions
Update was successful.

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 the region resolution logic for Cloud Functions, shifting the resolution process from the Backend representation to the Build representation. This allows for correct VPC connector string construction earlier in the deployment process. The new resolveDefaultRegionsForBuild function integrates existing region matching and trigger-based resolution. Review feedback identifies a violation of the style guide regarding the use of the any type and suggests including the endpoint ID in resolver calls to avoid potential issues. Additionally, a suggestion was made to use falsy checks for array length in accordance with project conventions.

Comment thread src/deploy/functions/prepare.ts
Comment thread src/deploy/functions/prepare.ts Outdated
@wandamora wandamora changed the title Ajp speculative tbd fix yolo refactor: resolve function regions during build phase to fix VPC connectors May 7, 2026
@wandamora wandamora marked this pull request as ready for review May 7, 2026 22:48
Copy link
Copy Markdown
Contributor

@shettyvarun268 shettyvarun268 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shettyvarun268
Copy link
Copy Markdown
Contributor

Might want to rebase this PR to take in Joe's changes for the test cases failing.

@wiz-9635d3485b
Copy link
Copy Markdown

wiz-9635d3485b Bot commented May 11, 2026

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Software Management Finding Software Management Findings -
Total -

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

@wandamora wandamora force-pushed the ajp-speculative-tbd-fix-yolo branch from c9bded9 to 53f8bc3 Compare May 11, 2026 23:56
@wandamora wandamora enabled auto-merge (squash) May 12, 2026 15:31
@wandamora wandamora merged commit a605414 into main May 12, 2026
52 checks passed
@wandamora wandamora deleted the ajp-speculative-tbd-fix-yolo branch May 12, 2026 15:44
Copy link
Copy Markdown
Contributor

@ajperel ajperel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My AI review prompt had a few more good suggestions we can consider for a follow up PR.

} else {
// Match triggers.
try {
const fullEndpoint = { ...endpoint, id } as any;
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.

This is done because endpoint (of type build.Endpoint) does not have an id field, but resolveRegionForEventTrigger expects a backend.Endpoint which requires an id. While this works, it bypasses TypeScript's type checks. Consider defining a minimal interface for what resolveRegionForEventTrigger actually needs (it seems to only need project and eventTrigger) or casting to a specific type that fulfills that contract rather than any.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: #10504

if (build.isBlockingTriggered(endpoint)) {
resolvedRegion = resolveRegionForBlockingTrigger(fullEndpoint);
} else if (build.isEventTriggered(endpoint)) {
resolvedRegion = await resolveRegionForEventTrigger(fullEndpoint);
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.

If a user has many event-triggered functions, this will execute network calls (like fetching database or bucket locations) sequentially (because of the for loop it's in), which can slow down the prepare phase. Consider gathering the promises and using Promise.all to resolve them in parallel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daniel once advised against using Promise.all() since transient errors could bubble up in the CLI in a way that looks cryptic to the end user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10414 (comment) for reference

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.

Ok. That's a good counter argument. I think it'd be good for us to see what the cryptic error is and if we could fix it so things can be faster. But I guess let's save that for a day when we need to improve performance.

expect(want.endpoints["id"].region).to.deep.equal(["us-east1"]);
});

it("resolves region to us-east1 and correctly formats VPC connector path with us-east1", async () => {
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.

AI suggests also testing this case:

Pre-formatted VPC Connector Paths:
Scenario: An endpoint with a vpc.connector that is already a full resource path (e.g., projects/my-project/locations/us-east1/connectors/my-connector).
Purpose: Verify that the resolution logic does not attempt to prefix it again or corrupt it, even after the region is resolved. This ensures the check connector.includes("/") in build.ts works correctly in this flow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: #10505

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.

4 participants