Skip to content

Conversation

dominikschubert
Copy link
Member

Based upon the analytics logger, @ackdav and I prototyped a fairly simple usage logger a few weeks ago.

One of the constraints for the prototype was to not add further pressure on the analytics backend, so we aggregate all captured data & "flush the logs" only on shutdown. This can be somewhat unreliable though, since in some cases the LocalStack instance might not be properly terminated and thus never wait for the shutdown to actually execute.

A few examples of what kind of information we wanted to collect:

  • Lambda runtimes
  • Usage of certain features (e.g. Lambda hot-reloading)
  • Supported CloudFormation models
  • Unsupported CloudFormation models

Most of this data can also be captured via structured logging and log aggregation but for our purposes (forwarding to the analytics backend) this seemed impractical.

@github-actions
Copy link

LocalStack integration with Pro

1 895 tests  +1   1 695 ✔️  - 2   1h 43m 0s ⏱️ + 23m 29s
       1 suites ±0      197 💤 ±0 
       1 files   ±0          3 +3 

For more details on these failures, see this check.

Results for commit 15cab04. ± Comparison against base commit b2cc972.

@dominikschubert dominikschubert requested a review from thrau April 24, 2023 10:06
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

Conceptually this looks pretty good to me! We can start collecting these metrics at shutdown for now and maybe in the future think about how we can make it a bit more robust against ungraceful termination (but first investigate whether that's even worth it).

the UsageSetCounter seems pretty solid. The UsageLogger i'm not too sure about.

documenting the internal API to get a better grip on how the constructs are supposed to be used would be great!

@github-actions
Copy link

github-actions bot commented Apr 28, 2023

LocalStack Community integration with Pro

1 998 tests   1 734 ✔️  1h 16m 35s ⏱️
       2 suites     264 💤
       2 files           0

Results for commit eeaabc3.

♻️ This comment has been updated with latest results.

Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

looks good now! a bit of documentation couldn't hurt, but other than that: let's give this a go :-) cc @ackdav

@dominikschubert dominikschubert changed the title POC: custom feature usage logger Introduce usage logger May 2, 2023
@dominikschubert dominikschubert marked this pull request as ready for review May 2, 2023 13:26
@dominikschubert dominikschubert requested review from ackdav and removed request for dfangl May 2, 2023 13:26
Copy link
Member

@ackdav ackdav left a comment

Choose a reason for hiding this comment

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

🚀 thx for pushing this from prototype to integrating it. I'm sure this enables some really interesting insights!

By the way - is this respecting the DISABLE_EVENTS config flag?

one nit - I would like to introduce some namespacing in the analytics events. Something like product:event_name - this will make sifting through data much easier in the future. (also calling it "usage" isn't really telling us much 😉). So could we rename this event ls:usage_analytics ? (happy for better ideas - naming is hard and we're not enforcing naming schemes yet)

Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Looking forward to these insights 🔮 🚀

main comment: potential demo hotreload instrumentation in list_functions and tests 🔴
otherwise just nits

@@ -336,6 +338,8 @@ def start(self, env_vars: dict[str, str]) -> None:
for source, target in container_config.copy_folders:
CONTAINER_CLIENT.copy_into_container(self.container_name, source, target)

end_time = time.perf_counter()
usage.initduration.record_value(end_time - start_time)
Copy link
Member

Choose a reason for hiding this comment

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

I guess that's the easiest way to reliably measure container initialization overhead. Terminology-wise, this is something completely different compared to what AWS refers to INIT https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html

In the config, we use LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT. Potential alternatives are container_init_duration or more generic env_init_duration.

I understand initduration; just wanted to mention the different meaning compared to AWS terminology so we are aware of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually that should be removed right now, since I also removed the initduration counter in a previous commit 😬

But your point is still valid 👍 We can think about adding this back at a later date

@dominikschubert dominikschubert added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label May 4, 2023
@dominikschubert dominikschubert self-assigned this May 4, 2023
@coveralls
Copy link

coveralls commented May 4, 2023

Coverage Status

Coverage: 82.098% (+0.006%) from 82.092% when pulling eeaabc3 on hackday-usage into c28ef9a on master.

@dominikschubert dominikschubert changed the title Introduce usage logger Introduce usage counters May 4, 2023
@dominikschubert dominikschubert merged commit f48dbda into master May 4, 2023
@dominikschubert dominikschubert deleted the hackday-usage branch May 4, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants