Introduce filtering for total count metrics
Preface
Most of the changes in this MR was merged in !151646 (merged) and reverted in !152476 (merged) due to performance issues.
The performance issue was caused by EventDefintion.definitions
not being memorized.
definitions
are memorized as of this fix.
To improve performance further this MR, adds memorization to:
-
EventDefinition.find
to avoid scanning all event definitions (~500 objects). -
EventDefinition#event_selection_rules
to avoid scanning all metric definitions (~2900 objects)
In addition, this new MR avoids a bug that the original MR had which is described here
The below description is copy-pasted from the original MR.
What does this MR do and why?
Introduce filtering on additional properties for total count metrics.
Total count metrics can now be defined with a filter which decides if an event will update a metric or not.
Here is an example of a metric definition using filters. The count of the metric will be increased if a perform_epics_action
event with a label
value of abc
is emitted or if a perform_issues_action
with a label
value of xyz
and a property
value of hello
:
key_path: counts.count_total_perform_epics_action_label_abc_or_label_xyz_monthly
description: 'Monthly count of some events. This description should be better'
product_section: dev
product_stage: plan
product_group: product_planning
performance_indicator_type: []
value_type: number
status: active
milestone: '17.0'
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/151646
time_frame: 28d
data_source: internal_events
data_category: optional
distribution:
- ee
tier:
- premium
- ultimate
events:
- name: perform_epics_action
filter:
label: abc
- name: perform_issues_action
filter:
label: xyz
property: hello
Since only additional properties can be used in filters, the only valid keys for a filter
are label
, property
and value
.
The main focus has been to support the migration of Redis metrics to internal events like decribed here: #424893 (closed)
Future work
This future work will continue immediately after this MR is merged.
- Documentation will be added in a separate MR when we migrate the first metrics
- Add filters for RedisHLL metrics
- Add filter support to the generator
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- Create a few different metric definitions using the same event and different filters. You can get some like this
curl -s https://gitlab.com/gitlab-org/gitlab/-/commit/a6324efd6771bdac44654789178db064e1d39c03.diff | git apply -
- Start the monitor:
rails runner scripts/internal_events/monitor.rb perform_epics_action
- Start gdk and run the below commands one at a time and see the values in the monitor update as you expect.
Gitlab::InternalEvents.track_event('perform_epics_action', additional_properties: {label: 'abc'})
Gitlab::InternalEvents.track_event('perform_epics_action', additional_properties: {label: 'xyz'})
Gitlab::InternalEvents.track_event('perform_epics_action')
Gitlab::InternalEvents.track_event('perform_epics_action', additional_properties: {label: 'foo'})
Afterwards it should look like this:
Updated at 2024-05-02 07:55:36 UTC [PAUSED]
Monitored events: perform_epics_action
+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| RELEVANT METRICS |
+------------------------------------------------------------------------+----------------------+-----------------------+---------------+---------------+
| Key Path | Monitored Events | Instrumentation Class | Initial Value | Current Value |
+------------------------------------------------------------------------+----------------------+-----------------------+---------------+---------------+
| counts.count_total_perform_epics_action_label_abc_monthly | perform_epics_action | TotalCountMetric | 0 | 1 |
| counts.count_total_perform_epics_action_label_abc_or_label_xyz_monthly | perform_epics_action | TotalCountMetric | 0 | 2 |
| counts.count_total_perform_epics_action_label_xyz_monthly | perform_epics_action | TotalCountMetric | 0 | 1 |
| counts.count_total_perform_epics_action_monthly | perform_epics_action | TotalCountMetric | 0 | 4 |
+------------------------------------------------------------------------+----------------------+-----------------------+---------------+---------------+
+----------------------------------------------------------------------------------------------------------------------+
| SNOWPLOW EVENTS |
+----------------------+--------------------------+-----------------------+---------+--------------+------------+------+
| Event Name | Collector Timestamp | Category | user_id | namespace_id | project_id | plan |
+----------------------+--------------------------+-----------------------+---------+--------------+------------+------+
| perform_epics_action | 2024-05-02T07:55:32.657Z | InternalEventTracking | | | | |
| perform_epics_action | 2024-05-02T07:54:40.166Z | InternalEventTracking | | | | |
| perform_epics_action | 2024-05-02T07:53:41.407Z | InternalEventTracking | | | | |
| perform_epics_action | 2024-05-02T07:52:13.917Z | InternalEventTracking | | | | |
+----------------------+--------------------------+-----------------------+---------+--------------+------------+------+
Numbered steps to set up and validate the change are strongly suggested.
Related to #435338 (closed)
Merge request reports
Activity
changed milestone to %17.0
assigned to @j_lar
- A deleted user
1 Message CHANGELOG missing: If this merge request needs a changelog entry, add the
Changelog
trailer to the commit message you want to add to the changelog.If this merge request doesn't need a CHANGELOG entry, feel free to ignore this message.
Reviewer roulette
Category Reviewer Maintainer analytics instrumentation @nbelokolodov
(UTC+12, 10 hours ahead of author)
Maintainer review is optional for analytics instrumentation backend @radbatnag
(UTC+8, 6 hours ahead of author)
@acook.gitlab
(UTC-4, 6 hours behind author)
Please check reviewer's status!
Please refer to documentation page for guidance on how you can benefit from the Reviewer Roulette, or use the GitLab Review Workload Dashboard to find other available reviewers.
If needed, you can retry the
danger-review
job that generated this comment.Generated by
Dangeradded 142 commits
-
09898c30...6b079bd4 - 141 commits from branch
master
- eb0bdd0d - Introduce filtering for total count metrics
-
09898c30...6b079bd4 - 141 commits from branch
added pipelinetier-1 label
changed milestone to %17.1
Hi @pskorupa, can you please take a look at this since you're reviewed the original MR?
When you approve, please assign
@michold
for the maintainer review as he has the context.@j_lar Thanks, LGTM! Looks identical to the previous MR, of course minus the performance problems that led to the revert.
@michold Could you do the maintainer review?
@j_lar Overall the changes look good to me, but I wonder if they will actually address the issue
It seems like what caused the pipeline errors was theGitlab::Tracking::EventDefinition.definitions
call happening in each pipeline, which will still be getting triggered now (we're saving time when trying to locate the appropriate event in the files array, but the file loading part will still be happening the same amount of times). SinceGitlab::Tracking::EventDefinition.definitions
is memoized already, we might need to approach this issue from a different side.@engwan Do you know if there's a good way to verify if the changes from this MR will address gitlab-com/gl-infra/production#17982 (closed) ?Sorry for the mention, this has been solved in !152744 (merged)Edited by Michał Wielich@michold memorization was added to
Gitlab::Tracking::EventDefinition.definitions
after the revert of the original MR, so it should be fine. The event definitions files are no longer read from disk every timeGitlab::Tracking::EventDefinition.definitions
is called.Memorization was introduced in: !152744 (merged)
@j_lar I see, that's great, thank you! In this case, I will start the merging flow
@michold looks like we hit a broken master. I rebased and we have a fresh green pipeline now. Can you try again?
requested review from @pskorupa
removed review request for @pskorupa
added pipeline:mr-approved label
- Resolved by Michał Wielich
@pskorupa
, thanks for approving this merge request.This is the first time the merge request has been approved. To ensure we don't only run predictive pipelines, and we don't break
master
, a new pipeline will be started shortly.Please wait for the pipeline to start before resolving this discussion and set auto-merge for the new pipeline. See merging a merge request for more details.
added pipelinetier-3 label and removed pipelinetier-1 label
requested review from @michold
E2E Test Result Summary
allure-report-publisher
generated test report!e2e-test-on-gdk:
test report for c1807f0aexpand test summary
+------------------------------------------------------------------+ | suites summary | +-------------+--------+--------+---------+-------+-------+--------+ | | passed | failed | skipped | flaky | total | result | +-------------+--------+--------+---------+-------+-------+--------+ | Govern | 66 | 0 | 0 | 43 | 66 | ✅ | | Create | 111 | 0 | 9 | 94 | 120 | ✅ | | Analytics | 2 | 0 | 0 | 1 | 2 | ✅ | | Verify | 31 | 0 | 1 | 30 | 32 | ✅ | | Plan | 54 | 0 | 2 | 47 | 56 | ✅ | | Package | 19 | 0 | 12 | 19 | 31 | ✅ | | Data Stores | 31 | 0 | 0 | 22 | 31 | ✅ | | Monitor | 8 | 0 | 0 | 7 | 8 | ✅ | | Manage | 0 | 0 | 1 | 0 | 1 | ➖ | | Release | 5 | 0 | 0 | 5 | 5 | ✅ | +-------------+--------+--------+---------+-------+-------+--------+ | Total | 327 | 0 | 25 | 268 | 352 | ✅ | +-------------+--------+--------+---------+-------+-------+--------+
e2e-package-and-test:
test report for c1807f0aexpand test summary
+---------------------------------------------------------------------+ | suites summary | +----------------+--------+--------+---------+-------+-------+--------+ | | passed | failed | skipped | flaky | total | result | +----------------+--------+--------+---------+-------+-------+--------+ | Create | 297 | 0 | 31 | 0 | 328 | ✅ | | Monitor | 16 | 0 | 9 | 0 | 25 | ✅ | | GitLab Metrics | 2 | 0 | 1 | 0 | 3 | ✅ | | Plan | 22 | 0 | 2 | 0 | 24 | ✅ | | Data Stores | 11 | 0 | 0 | 0 | 11 | ✅ | | Package | 3 | 0 | 4 | 0 | 7 | ✅ | | Govern | 14 | 0 | 0 | 0 | 14 | ✅ | | Verify | 5 | 0 | 0 | 0 | 5 | ✅ | | Release | 1 | 0 | 0 | 0 | 1 | ✅ | +----------------+--------+--------+---------+-------+-------+--------+ | Total | 371 | 0 | 47 | 0 | 418 | ✅ | +----------------+--------+--------+---------+-------+-------+--------+
enabled an automatic merge when the pipeline for f483c09c succeeds
added workflowin review label and removed workflowin dev label
added 481 commits
-
20b91315...3f1c866b - 479 commits from branch
master
- d479f362 - Introduce filtering for total count metrics
- 124da912 - Memorize find and event_selection_rules
-
20b91315...3f1c866b - 479 commits from branch
added 22 commits
-
124da912...601efde1 - 20 commits from branch
master
- 56af2791 - Introduce filtering for total count metrics
- c1807f0a - Memorize find and event_selection_rules
-
124da912...601efde1 - 20 commits from branch
added analytics instrumentationapproved label and removed analytics instrumentationreview pending label
mentioned in commit 2c5c080b
added workflowstaging-canary label and removed workflowin review label
added workflowcanary label and removed workflowstaging-canary label
added workflowstaging label and removed workflowcanary label
added workflowproduction label and removed workflowstaging label
mentioned in merge request !151878 (merged)
added releasedcandidate label
added releasedpublished label and removed releasedcandidate label