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

misc(usage): Scope usage caching to the charge filter level #2678

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

vincent-pochet
Copy link
Collaborator

Context

Today caching for usage data is scope to the charge.
When an event is received for a specific billable metric code will invalidate the cache for all charges attached to it for the customer's plan. The cache will leave until the end of the billing period or until a new event is received for the same billable metric code and subscription.
This logic avoid recomputing the complete charge aggregation every time the customer usage is requested.

This logic was fine until the introduction of charge filters.
Aggregation for filters are done one by one for every filter, and stored in cache using the same charge cache key (ie: all filtered aggregations are grouped inside the same charge cached bucket). When an event matching a filter is received it invalidate the cache for all filters, meaning that when fetching the usage we have to resegregate it for every single filter even if nothing new was received for the majority of them.

Description

This PR refactors some parts of the usage computation and adds a new caching logic to scope the caching up to the charge filter when applicable and keeping the actual caching when no filters are attached to the charge.

Copy link
Collaborator

@rsempe rsempe left a comment

Choose a reason for hiding this comment

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

🔥

@vincent-pochet vincent-pochet merged commit b99e3e3 into main Oct 21, 2024
6 checks passed
@vincent-pochet vincent-pochet deleted the misc-filter-caching branch October 21, 2024 08:20
vincent-pochet added a commit that referenced this pull request Oct 25, 2024
## Context

This PR is related to #2678.
The charge filter lookup that was added in the
`Events::PostProcessService` lead to some performance regression. The
reason behind this is that the `ChargeFilters::EventMatchingService` is
reloading systematically the charge filters and associated values even
if they were already pre-loaded in the `Events::PostProcessService`

## Description

The PR is checking the cached status of the `filters` association to
avoid the reload.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants