8000 re-introduce eager service loading by bentsku · Pull Request #12657 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

re-introduce eager service loading #12657

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

Merged
merged 3 commits into from
Jun 4, 2025
Merged

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented May 23, 2025

Motivation

It seems we deleted eager service loading behavior with #11202 by accident.

Now with the new runtime framework, we can simply eager load services via hooks.

I've also added a proper bootstrap test to avoid deleting the behavior again without realizing it.

I updated the eager loading logic to not eager load all services if set, as it will most likely just wait forever.

My biggest question is where this hook declaration should live?

\cc @thrau @alexrashed

Changes

  • re-add eager loading via hooks
  • add bootstrap tests
  • add eager loading logic to not eager load all possible services

@bentsku bentsku added this to the 4.5 milestone May 23, 2025
@bentsku bentsku added area: infrastructure Installation and startup of LocalStack and components semver: patch Non-breaking changes which can be included in patch releases labels May 23, 2025
@bentsku bentsku self-assigned this May 23, 2025
Copy link
github-actions bot commented May 23, 2025

Test Results - Preflight, Unit

21 595 tests  ±0   19 940 ✅ ±0   6m 59s ⏱️ +48s
     1 suites ±0    1 655 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 047a213. ± Comparison against base commit 8b3dcdd.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 23, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 10s ⏱️ -13s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 047a213. ± Comparison against base commit 8b3dcdd.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 23, 2025

Test Results - Alternative Providers

986 tests  ±0   568 ✅ ±0   22m 26s ⏱️ -23s
  4 suites ±0   418 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit 047a213. ± Comparison against base commit 8b3dcdd.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 23, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 42m 6s ⏱️ +9s
4 870 tests ±0  4 094 ✅ ±0  776 💤 ±0  0 ❌ ±0 
4 872 runs  ±0  4 094 ✅ ±0  778 💤 ±0  0 ❌ ±0 

Results for commit 047a213. ± Comparison against base commit 8b3dcdd.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 23, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files  ±0      5 suites  ±0   2h 21m 26s ⏱️ -34s
5 227 tests +2  4 299 ✅ +2  928 💤 ±0  0 ❌ ±0 
5 233 runs  +2  4 299 ✅ +2  934 💤 ±0  0 ❌ ±0 

Results for commit 047a213. ± Comparison against base commit 8b3dcdd.

This pull request removes 1 and adds 3 tests. Note that renamed tests count towards both.
tests.bootstrap.test_strict_service_loading ‑ test_strict_service_loading
tests.bootstrap.test_service_loading ‑ test_eager_and_strict_service_loading
tests.bootstrap.test_service_loading ‑ test_eager_service_loading
tests.bootstrap.test_service_loading ‑ test_strict_service_loading

♻️ This comment has been updated with latest results.

@bentsku bentsku requested a review from dfangl May 24, 2025 01:23
@bentsku bentsku marked this pull request as ready for review May 24, 2025 01:23
@bentsku bentsku requested a review from simonrw as a code owner May 24, 2025 01:23
Copy link
Member
@pinzon pinzon left a comment

Choose a reason for hiding this comment

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

Interesting how we lost a feature and no one noticed 😅

@bentsku bentsku requested a review from dominikschubert May 30, 2025 09:00
wait_for_localstack_ready,
aws_client_factory,
):
# this is undocumented behavior, to allow eager loading of specific services while not restricting services loading
Copy link
@jeremygiberson jeremygiberson Jun 3, 2025

Choose a reason for hiding this comment

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

FYI I arrived at this PR because I was specifically trying to figure out how to eager load specific services in a specific order without loading everything or preventing services from ever being enabled. Lucky issue searching turned up this PR.

My use case is building integration tests that have isolated localstack containers and building/deploying images to ecr for lambda as well as spinning up RDS. I ended up getting tripped up because depending on whether RDS or ECR was started first, ECR might be 4510 or 4511.

All that is to say, at least one person (me) finds this behavior useful and would appreciate the behavior being documented!

Looking forward to see this PR land either way.

Copy link
Member

Choose a reason for hiding this comment

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

@jeremygiberson please keep in mind though that we still don't technically guarantee that these port assignments would be deterministic.

Copy link
Member
@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

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

Thanks @bentsku for tackling this and for particularly for making sure we have regression tests in place now to avoid a similar occurence in the future! 🚀

We can get input from @thrau once he's back but having the hook live close to the service plugins / manager seems like a sensible choice to me. 👍

I updated the eager loading logic to not eager load all services if set, as it will most likely just wait forever.

As far as I understood, this would be a major change though, since it would break how users expect EAGER_SERVICE_LOADING=1 to work in isolation. 🤔 Did you find any occurence where we communicated this differently?

assert services.get("cloudwatch") == "disabled"


def test_eager_service_loading(
Copy link
Member

Choose a reason for hiding this comment

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

nice 👏 thanks for adding these.

Might also be good to add a case for {"EAGER_SERVICE_LOADING": "0", "SERVICES": "s3,sqs,sns"} just to make sure we have no regression there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this would be covered by the test above: test_strict_service_loading. STRICT_SERVICE_LOADING is set to 1 by default in LocalStack, and EAGER_SERVICE_LOADING to 0.

If something were to change with eager loading, I believe the test above would start failing as we're asserting that the services are available and not running? But we could make that explicit as well, here we are depending on default values.

wait_for_localstack_ready,
aws_client_factory,
):
# this is undocumented behavior, to allow eager loading of specific services while not restricting services loading
Copy link
Member

Choose a reason for hiding this comment

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

@jeremygiberson please keep in mind though that we still don't technically guarantee that these port assignments would be deterministic.

@bentsku
Copy link
Contributor Author
bentsku commented Jun 3, 2025

As far as I understood, this would be a major change though, since it would break how users expect EAGER_SERVICE_LOADING=1 to work in isolation. 🤔 Did you find any occurence where we communicated this differently?

@dominikschubert this is fair. Knowing that we lost the feature for almost a year now and had a major release since, I thought that this would be a fair change that we could document going forward. I had a PR branch* ready in the documentation that EAGER_SERVICE_LOADING=1 would need to be used in conjunction with SERVICES (didn't open the PR yet as I wasn't sure about this PR).
Technically not a "breaking" change since using EAGER_SERVICE_LOADING=1 without SERVICES would do nothing, like it is doing right now... 😄

I'm not sure we ever communicated about EAGER_SERVICE_LOADING in isolation, at least I'm not aware of such communication, I think we implemented eager loading after the new implementation of lazy loading of services, so it was done when people were still using the SERVICES variable. I'm not sure we ever officially supported eager loading in isolation, and if it ever really worked.

I tried to start LocalStack with EAGER_SERVICE_LOADING=1 and no SERVICES while working on this change, and it never succeeded to start for me, having so many services starting at once is... incredibly expensive, some services will start Postgres or start downloading their dependencies, one after the other.

I'm also fine to leave the behavior as it was before, and prepare this change for 5.0.

@dominikschubert
Copy link
Member

@bentsku Even though it's extremely expensive, I'd argue we should keep the behavior for now since someone might depend on it. We can discuss next week and onward if we want to change that behavior and if we want to do so via a major or minor release. Protecting users from potentially unintended mistakes is of course great, but the use case of trying to make sure everything is up and running is a valid one as well 🤷‍♂️ , so we need to consider that in a bit more detail.

In the meantime we can also investigate why it's never actually starting up when eagerly loading all services. I'd argue that's a bug to address separately 🐞

@bentsku bentsku force-pushed the re-implement-eager-loading branch from 551b4ab to 047a213 Compare June 4, 2025 08:56
@bentsku
Copy link
Contributor Author
bentsku commented Jun 4, 2025

@dominikschubert got it, I've updated the PR now 👍

I see it is as half a bug and half a feature, as starting each individual service will take a long time, maybe I didn't have a lot of patience either 😄 but not sure we have users using every single service we have, but that's another question! We can keep this discussion offline. Thanks for the review 🙏

@bentsku bentsku requested a review from dominikschubert June 4, 2025 09:00
Copy link
Member
@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for getting this regression fixed and addressing my earlier concerns 👍

@bentsku bentsku merged commit 9692260 into master Jun 4, 2025
57 checks passed
@bentsku bentsku deleted the re-implement-eager-loading branch June 4, 2025 12:44
@thrau
Copy link
Member
thrau commented Jun 4, 2025

just reading the title i thought we're moving away from lazy loading. before i had all the context my heart rate went up significantly, lol.

but this is a great PR, thanks for fixing this @bentsku! the implementation is really clean, i think the hook you added is one of the cleanest ways to do this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: infrastructure Installation and startup of LocalStack and components semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0