Skip to content

Add lambda ESM analytics #11883

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 7 commits into from
Nov 28, 2024
Merged

Add lambda ESM analytics #11883

merged 7 commits into from
Nov 28, 2024

Conversation

joe4dev
Copy link
Member

@joe4dev joe4dev commented Nov 20, 2024

Motivation

Add usage analytics for Lambda ESM to learn more about potential errors we should tackle and usage of different event sources.

Changes

  • Add usage analytics for invocation (successful ones) and error (unexpected error; i.e., LS bug)
  • Add unit test for existing set counter (also serves to exemplify usage)

@joe4dev joe4dev added the semver: patch Non-breaking changes which can be included in patch releases label Nov 20, 2024
@joe4dev joe4dev added this to the 4.0 milestone Nov 20, 2024
@joe4dev joe4dev self-assigned this Nov 20, 2024
Copy link

github-actions bot commented Nov 20, 2024

LocalStack Community integration with Pro

    2 files      2 suites   1h 28m 23s ⏱️
2 787 tests 2 538 ✅ 249 💤 0 ❌
2 789 runs  2 538 ✅ 251 💤 0 ❌

Results for commit e28afdd.

♻️ This comment has been updated with latest results.

@joe4dev joe4dev marked this pull request as ready for review November 20, 2024 12:28
@joe4dev joe4dev requested a review from thrau as a code owner November 20, 2024 14:42
@joe4dev joe4dev requested a review from bentsku November 20, 2024 14:45

def record(self, key: str, value: str):
namespace = f"{self.namespace}:{key}"
set_counter = self._counters.setdefault(key, UsageSetCounter(namespace))
Copy link
Contributor

@bentsku bentsku Nov 20, 2024

Choose a reason for hiding this comment

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

I think using setdefault here might lead to an issue: when initializing a UsageSetCounter, it will register itself in the register with collector_registry[namespace] = self, overriding on the namespace key and the counter.

I think we should probably not create the entry if config.DISABLE_EVENTS is enabled.

edit: sorry I published as an individual comment instead of the review! 😬

I'm not sure about the analytics, if it allows nested dict, I think right now on the analytics we only have one dict: namespace -> key -> value, and now we get main_namespace -> sub_namespace -> key -> value

edit2: I think I misread it and didn't see how the namespace was created and aggregated. This actually is really good this way! Sorry for missing it! Just the registration is an issue 😄

edit3: after the sync, we realized we didn't need to aggregate this multiset, as the individual counters already register themselves.

Comment on lines 89 to 93
if namespace in self._counters:
set_counter = self._counters[namespace]
else:
set_counter = UsageSetCounter(namespace)
self._counters[namespace] = set_counter
Copy link
Member

Choose a reason for hiding this comment

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

This is not thread safe, we might unnecessarily instantiate some usagesetcounters with the same namespace here, which might override each other in an unprecedented way. This could for example happen in multiple event source mappings in multiple thread.

Since we cannot use setdefault, I'd rather just add a lock here.

Copy link
Member Author

Choose a reason for hiding this comment

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

great catch 💯

Is it thread-safe now?

Copy link
Member

@dfangl dfangl left a comment

Choose a reason for hiding this comment

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

LGTM now! Thanks for addressing the thread safety issue!

@thrau thrau removed this from the 4.0 milestone Nov 20, 2024
@thrau
Copy link
Member

thrau commented Nov 20, 2024

as discussed we've decided to postpone this for now and dive a bit deeper into the requirements first. i think it's worth delineating between usage analytics and observability, and perhaps understand more what we can learn from tracking things like errors. let's discuss post v4 :-)

@joe4dev joe4dev added this to the Playground milestone Nov 21, 2024
@joe4dev
Copy link
Member Author

joe4dev commented Nov 26, 2024

as discussed we've decided to postpone this for now and dive a bit deeper into the requirements first. i think it's worth delineating between usage analytics and observability, and perhaps understand more what we can learn from tracking things like errors. let's discuss post v4 :-)

I extracted the new ideas into a separate PR up for discussion (at a suitable time) #11934 and reduced the changes here to our existing analytics utility (i.e., the UsageSetCounter we use in other places).

This minimal version would help us track how much the data plane is used (vs. users just creating resources in the control plane) and which behavior features might need attention (indicated by a high error rate). @thrau Does this harm ATM?

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!

@joe4dev joe4dev merged commit 1a46f58 into master Nov 28, 2024
35 checks passed
@joe4dev joe4dev deleted the add-esm-pipes-analytics branch November 28, 2024 08:18
@bentsku bentsku mentioned this pull request Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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