-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add warning nudges for cross-region event triggers #10408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
980f7bb
2cfd8a3
1b432e2
736308a
ce514fb
31a9f53
d506809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import * as backend from "./backend"; | ||
| import { serviceForEndpoint } from "./services"; | ||
| import * as utils from "../../utils"; | ||
|
|
||
| /** | ||
| * Ensures the trigger regions are set and correct | ||
| * @param want the list of function specs we want to deploy | ||
| * @param have the list of function specs we have deployed | ||
| */ | ||
| export async function ensureTriggerRegions(want: backend.Backend): Promise<void> { | ||
| const regionLookups: Array<Promise<void>> = []; | ||
|
|
@@ -16,4 +16,38 @@ export async function ensureTriggerRegions(want: backend.Backend): Promise<void> | |
| regionLookups.push(serviceForEndpoint(ep).ensureTriggerRegion(ep)); | ||
| } | ||
| await Promise.all(regionLookups); | ||
|
|
||
| // Warn if an event function defaults to or is assigned to us-central1 but its trigger is out of the US, | ||
| // to avoid unnecessary cross-region network hops (e.g., transatlantic). | ||
| if (process.env.FIREBASE_SUPPRESS_REGION_WARNING === "true") { | ||
| return; | ||
| } | ||
|
|
||
| const offendingFunctions: string[] = []; | ||
| for (const ep of backend.allEndpoints(want)) { | ||
| if (ep.platform === "gcfv1" || !backend.isEventTriggered(ep)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we ignoring v1 functions? Is there a reason those should stay with international hops?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still debating this. One one hand I agree that the v1 users might get the biggest benefit out of this since they might have deployed in different regions. But at the same time v1 functions would require some additional lookup which would make the deploy process slower for them(especially with multiple functions).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you quantify this at all? How complicated and slow is the additional lookup? If we're increasing the deployment time from like 1 minute to 1:02 ... I'm fine with that slowdown. If we were going from 0:30 to 1:30 that would be a problem.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For small projects with a few functions, we could probably parallelize the lookups keeping the delay under 1 to 2 seconds (so within your limit!). The problem really comes down to scale and permissions. If a user has 20+ V1 functions pointing at several distinct databases or buckets, making individual API hits to solve those missing region fields on V1 manifests could tack on 10+ seconds of dead weight to the deploy time. Also, doing high-speed sequential hits runs a risk of tagging rate limits or firing IAM check fails for developers on locked down corporate accounts. |
||
| continue; | ||
| } | ||
| const triggerRegion = ep.eventTrigger.region; | ||
| if (ep.region !== "us-central1" || !triggerRegion || triggerRegion === "global") { | ||
| continue; | ||
| } | ||
| if (!isUSRegion(triggerRegion)) { | ||
| offendingFunctions.push(`- ${ep.id} (us-central1, Trigger: ${triggerRegion})`); | ||
| } | ||
| } | ||
|
shettyvarun268 marked this conversation as resolved.
|
||
|
|
||
| if (offendingFunctions.length > 0) { | ||
| utils.logLabeledWarning( | ||
| "functions", | ||
| `The following functions have triggers in different regions than they are located:\n` + | ||
| offendingFunctions.join("\n") + | ||
| `\nTo avoid unnecessary cross-region network hops, consider assigning these functions to their trigger regions or collocating them. ` + | ||
| `To suppress this warning, set FIREBASE_SUPPRESS_REGION_WARNING=true in your environment variables.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function isUSRegion(region: string): boolean { | ||
| return region === "us" || region === "nam5" || region === "nam7" || region.startsWith("us-"); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.