Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def set_global_options(
min_instances: int | Expression[int] | _util.Sentinel | None = None,
max_instances: int | Expression[int] | _util.Sentinel | None = None,
concurrency: int | Expression[int] | _util.Sentinel | None = None,
cpu: int | _typing.Literal["gcf_gen1"] | _util.Sentinel = "gcf_gen1",
cpu: int | _typing.Literal["gcf_gen1"] | _util.Sentinel | None = None,
Comment thread
IzaakGough marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm OK with this change as is (since it's focused on default) but should we also support Expression[int] here too (even if in the future)?

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.

@ajperel Agreed. The node sdk also leaves cpu as number | "gcf_gen1". Do you know if there is a reason why this was left out? If not, we can add it to both sdks in a follow-up.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't. We could look into it but I don't think it's a high priority if we've never gotten a feature request for it. But if it works... sure?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's land this as is first though.

vpc_connector: str | Expression[str] | _util.Sentinel | None = None,
vpc_connector_egress_settings: VpcEgressSetting | _util.Sentinel | None = None,
service_account: str | _util.Sentinel | None = None,
Expand Down
60 changes: 60 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,66 @@ def test_global_options_merged_with_provider_options():
)


def _endpoint_cpu(**fn_options):
@https_fn.on_request(**fn_options)
def fn(_):
return "hello world"

return fn.__firebase_endpoint__.cpu


def test_set_global_options_without_cpu_leaves_cpu_unset():
options.set_global_options(region="europe-west1")

assert options._GLOBAL_OPTIONS.cpu is None, "global cpu should not be set"
assert "cpu" not in options.HttpsOptions()._asdict_with_global_options()
assert _endpoint_cpu() is None, "endpoint cpu should not be set"


def test_set_global_options_without_cpu_omits_cpu_from_yaml():
options.set_global_options(region="europe-west1")

@https_fn.on_request()
def fn(_):
return "hello world"

assert "cpu" not in functions_as_yaml({"fn": fn})


def test_set_global_options_explicit_gcf_gen1_cpu_is_kept():
options.set_global_options(cpu="gcf_gen1")

assert _endpoint_cpu() == "gcf_gen1"


def test_set_global_options_numeric_cpu_is_kept():
options.set_global_options(cpu=2)

assert _endpoint_cpu() == 2
Comment thread
IzaakGough marked this conversation as resolved.


def test_function_cpu_overrides_global_cpu():
options.set_global_options(cpu=2)

assert _endpoint_cpu(cpu=4) == 4
assert _endpoint_cpu(cpu="gcf_gen1") == "gcf_gen1"


def test_set_global_options_reset_value_cpu_is_kept():
options.set_global_options(cpu=options.RESET_VALUE)

@https_fn.on_request()
def fn(_):
return "hello world"

assert fn.__firebase_endpoint__.cpu == options.RESET_VALUE
assert " cpu: null\n" in functions_as_yaml({"fn": fn})


def test_cpu_unset_without_global_options():
assert _endpoint_cpu() is None


@pytest.mark.parametrize(
"vpc_connector_expr_factory",
[
Expand Down
Loading