Allow filtering metrics with custom properties
What does this MR do and why?
Related to #474804
We want to make it possible to filter custom properties [not just label
, property
and value
] in the metric definitions. This MR adds this functionality and a test metric that we can later use to verify everything is working correctly on production.
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.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
The new metric can be used to test these changes:
- Trigger the event that would pass metric's filter twice, for example by running in the Rails console:
Gitlab::InternalEvents.track_event('cvs_on_sbom_change', additional_properties: { known_affected_sbom_occurrences: 0 }); Gitlab::InternalEvents.track_event('cvs_on_sbom_change', additional_properties: { label: 'aa', value: 12, known_affected_sbom_occurrences: 0 })
- Trigger some noise events - ones that should not increment the metric counter:
Gitlab::InternalEvents.track_event('cvs_on_sbom_change', additional_properties: { value: 1, known_affected_sbom_occurrences: 1 }); Gitlab::InternalEvents.track_event('cvs_on_sbom_change', additional_properties: { value: 1 }); Gitlab::InternalEvents.track_event('i_search_total', additional_properties: { label: '1' })
- Calculate the metric for the next week [as we always calculate metrics using last week's data]:
require 'active_support/testing/time_helpers'; include ::ActiveSupport::Testing::TimeHelpers; sp = travel_to(Date.today + 7.days) { Gitlab::Usage::ServicePing::InstrumentedPayload.new(%w[counts.count_total_cvs_on_sbom_change_with_extra_filters_weekly], :with_value).build }
. This should return a hash with a value equal to2
.
We also need to test the cli
changes. To do that, run ./scripts/internal_events/cli.rb
and define an event/metric that includes additional property filters.
Edited by Michał Wielich