Add metrics for Compliance Group
Why are we doing this work
In Govern SMAU Metric, we want to add tracking of govern-related activities. The metric should report only unique users and should use user ID
as a tracking value, so that events tracked from frontend via /increment_unique_users
don't create duplicates. There is a PoC which explored the possible implementation.
We want to generate metrics for each page, aggregate metrics for each of the 5 categories, aggregate metrics for each of the 3 groups and one aggregate metric for the entire stage.
In this issue, we want to add tracking for activities related to the Compliance Group.
Relevant links
Implementation plan
-
backend Generate usage metric definition for the aggregated group metric:
bin/rails generate gitlab:usage_metric_definition:redis_hll govern users_visiting_compliance_pages --ee
Use AggregatedMetric
as instrumentation class and include the events to aggregate:
instrumentation_class: AggregatedMetric
options:
aggregate:
operator: OR
attribute: user_id
events:
- g_compliance_dashboard
- users_visiting_audit_events
-
backend Add the events above also to the aggregated SMAU metric: users_visiting_govern_pages_monthly
users_visiting_govern_pages_weekly
-
backend Add tracking of project-level actions in the controllers using GovernUsageProjectTracking
:-
index
inee/app/controllers/projects/audit_events_controller.rb
-
-
backend Add tracking of group-level actions in the controllers using GovernUsageGroupTracking
:-
index
inee/app/controllers/groups/audit_events_controller.rb
-
Verification steps
- Visit one of the pages or perform any of the actions covered by the new events
- In the
rails console
, check for a non-zero counter value for the metric:Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: '<event-name>', start_date: Date.current.beginning_of_week, end_date: Date.current.next_week)
- You run the service ping worker with
GitlabServicePingWorker.new.perform('triggered_from_cron' => false)
- Check for the
weekly
andmonthly
aggregated metric:RawUsageData.last.payload['redis_hll_counters']['govern']
Verification steps in production
- Go to the metrics page and search for the new metrics added for the compliance pages.
https://metrics.gitlab.com/?q=govern.users_visiting_compliance_pages
-
For each metric, click on
copy query to clipboard
-
Go to Sisense > new exploration
-
copy the queries for each metric
-
Click on
RUN SQL
-
Verify the query result
Repeat the steps for the Audit Events metrics.
https://metrics.gitlab.com/?q=govern.users_visiting_audit_events