Skip to content

Move EE usage counters to metrics definitions

Michał Wielich requested to merge refactor-redis-counters-v5 into master

What does this MR do and why?

Related to #339445 (closed)

We want to move metrics-related code from our chunky UsageData class into a system of yml files including metrics definitions.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

This test should make sure that we didn't miss any metrics [eg, it is failing after removing the instrumentation_class: clause from any of the yml files].

To test that the actual values for events are also counted correctly:

  1. Checkout master branch
  2. Trigger some events related to the migrated metrics, for example:
  • go to a project > Security & Compliance > License Compliance
  • triggering the IncidentCounter events is a bit more complicated [it requires having a status page set up], so I would suggest to just run ::Gitlab::StatusPage::UsageDataCounters::IncidentCounter.count('publishes') and ::Gitlab::StatusPage::UsageDataCounters::IncidentCounter.count('unpublishes') a few times in the console.
  • the License Compliance events are probably also easiest to just trigger from the console, with: ::Gitlab::UsageDataCounters::LicenseTestingCounter.count('clicking_license_testing_visiting_external_website') and ::Gitlab::UsageDataCounters::LicenseTestingCounter.count('visiting_testing_license_compliance_full_report') commands.
  1. Run this in the console:
counter_classes = [
  ::Gitlab::UsageDataCounters::LicensesList,
  ::Gitlab::StatusPage::UsageDataCounters::IncidentCounter,
  ::Gitlab::UsageDataCounters::LicenseTestingCounter
]
raw_events = counter_classes.map {|cc| [cc, cc::KNOWN_EVENTS]}
events = raw_events.map do |cc, evs|
  evs.map { |ev| "#{cc::PREFIX}_#{ev}" }
end.flatten
service_ping = Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values)

values1 = service_ping[:counts].values_at(*events)
  • This will save the event statistics under the values1 variable. The values1 array should include some non-zero values if the events have been successfully triggered. Now what we will need to do is compare it with the result we get with this MR:
  1. Check out this MR's branch
  2. Run this in the console:
reload!
service_ping = Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values)
values2 = service_ping[:counts].values_at(*events)
  1. Now, the values1 and values2 should have the same value. This will prove that the events have been added to Service Ping data correctly.
values2 == values1
=> true

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Michał Wielich

Merge request reports