feat(flexible aggregation) - Support flexible aggregation on billable metric #2704
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Billable metrics only allow you to aggregate on 1 property field. Several customers like to have some sort of computation done, so they can be flexible on how they send the event data to Lago.
Here is an example: a customer wants to send
started_at
,ended_at
&replicas
as the properties and calculate the value as(ended_at - started_at) * replicas / 3600
.To facilitate this, this PR introduces a new pre-ingestion step. This step runs in between receiving the event and persisting it to the db (both Clickhouse & Postgres event stores are supported).
This ingestion step relies on allowing customers to define an ‘Expression’ that will be evaluated for every event.
The expression parsing and evaluation relies on the new https://github.com/getlago/lago-expression library