-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: remove groups from event post validation (#2280)
## Context The refresh of `last_hour_events_mv` can take a lot of time in our cloud instances. Some OSS users also reported issues with it. In some conditions the refresh could take more than one hour, leading missing validation on some events since the validation is supposed to refresh the view and loop over the event every hour. After investigation it appears that the issue comes mainly from the group validation. ## Description Since `groups` is now legacy and has been replaced by `filters`, it does not make any sense to keep this validation. This PR simply removes all the validation logic related to `groups`
- Loading branch information
1 parent
7e497f5
commit d15b8b9
Showing
5 changed files
with
73 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdateLastHourEventsMvV04 < ActiveRecord::Migration[7.1] | ||
def change | ||
drop_view :last_hour_events_mv, materialized: true | ||
create_view :last_hour_events_mv, materialized: true, version: 4 | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
WITH billable_metric_filters as ( | ||
SELECT | ||
billable_metrics.organization_id as bm_organization_id, | ||
billable_metrics.id AS bm_id, | ||
billable_metrics.code AS bm_code, | ||
filters.key AS filter_key, | ||
filters.values AS filter_values | ||
FROM billable_metrics | ||
INNER JOIN billable_metric_filters filters | ||
ON filters.billable_metric_id = billable_metrics.id | ||
WHERE | ||
billable_metrics.deleted_at IS NULL | ||
AND filters.deleted_at IS NULL | ||
) | ||
|
||
|
||
SELECT | ||
events.organization_id, | ||
events.transaction_id, | ||
events.properties, | ||
billable_metrics.code AS billable_metric_code, | ||
billable_metrics.aggregation_type != 0 AS field_name_mandatory, | ||
billable_metrics.aggregation_type IN (1,2,5,6) AS numeric_field_mandatory, | ||
events.properties ->> billable_metrics.field_name::text AS field_value, | ||
events.properties ->> billable_metrics.field_name::text ~ '^-?\d+(\.\d+)?$' AS is_numeric_field_value, | ||
events.properties ? billable_metric_filters.filter_key as has_filter_keys, | ||
(events.properties ->> billable_metric_filters.filter_key) = ANY (billable_metric_filters.filter_values) as has_valid_filter_values | ||
FROM | ||
events | ||
LEFT JOIN billable_metrics ON billable_metrics.code = events.code | ||
AND events.organization_id = billable_metrics.organization_id | ||
LEFT JOIN billable_metric_filters ON billable_metrics.id = billable_metric_filters.bm_id | ||
WHERE | ||
events.deleted_at IS NULL | ||
AND events.created_at >= date_trunc('hour', NOW()) - INTERVAL '1 hour' | ||
AND events.created_at < date_trunc('hour', NOW()) | ||
AND billable_metrics.deleted_at IS NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters