Skip to content
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

Emulators for functions v2 not supporting different regions #7580

Open
KantiKuijk opened this issue Aug 21, 2024 · 1 comment
Open

Emulators for functions v2 not supporting different regions #7580

KantiKuijk opened this issue Aug 21, 2024 · 1 comment

Comments

@KantiKuijk
Copy link

[REQUIRED] Environment info

**firebase-tools:**13.15.4

**Platform:**macOS

[REQUIRED] Test case

index.ts:

import { onValueCreated } from "firebase-functions/v2/database";
import { setGlobalOptions } from "firebase-functions/v2";
import { region } from "firebase-functions/v1";

setGlobalOptions({ region: "europe-west1" });

export const NewInQueueV1 = region("europe-west1")
  .database.ref("mailing/queue/{pushID}/")
  .onCreate(() => {
    console.log("There is a new mail in the mailing queue (v1)");
  });

export const NewInQueueV2 = onValueCreated("mailing/queue/{pushID}/", () => {
  console.log("There is a new mail in the mailing queue (v2)");
});

[REQUIRED] Steps to reproduce

Create a new project with the default firebase in region europe-west1 and run the firebase functions and database emulators.
Using the emulators ui, import the following json:

{
  "mailing": {
    "queue": {
      "somePushID": {
        "email": "test@email.com",
        "action": "whitelist"
      }
    }
  }
}

making sure the checkbox "Also execute database triggers in the Functions emulator" is checked.
Observe the log.

[REQUIRED] Expected behavior

Both functions should be initialised without warning and on importing the json, both console.log statements should be executed indicating both functions were triggered.

[REQUIRED] Actual behavior

The v2 version warns about functions[europe-west1-NewInQueueV2]: function region is defined outside the database region, will not trigger.. On import, only the v1 functions Is triggered. Even when repeating the setup without the v1 function in index.ts (in case a second function triggering on the same path would be a problem), the v2 function does not get triggered.

I found the following code:

// TODO(colerogers): yank/change if RTDB emulator ever supports multiple regions
    if (region !== "us-central1") {
      this.logger.logLabeled(
        "WARN",
        `functions[${id}]`,
        `function region is defined outside the database region, will not trigger.`,
      );
    }

Where the comment together with the if clause seems to indicate that regions other than us-central1 are not supported in the emulators. (so I guess this might be interpreted as a feature request instead of an issue?)

Also, the warning message itself is misleading, since it infers the location of the database is wrong, but I believe the message is shown based on the region of the function. In this case, since the region is prepended to the function name, the warning seems to indicate that the referenced database is not in the preferred region europe-west1, when the warning is due to the region of the function, not the database.

@KantiKuijk
Copy link
Author

KantiKuijk commented Aug 23, 2024

A workaround is to not set the global region variable when the emulators are running:

if (process.env["FUNCTIONS_EMULATOR"] !== "true") {
  setGlobalOptions({ region: "europe-west1" });
}

If you set the region on a function-level, it may be more cumbersome to do so.

This makes the database functions trigger again, however, this will also apply to https functions, changing their URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants