Migrate a AggregatedMetric to RedisHLL
What does this MR do and why?
As a first step to get rid of AggregatedMetric
(which functionality is also available using RedisHLL metrics or Internal Events), this MR migrates all AggregatedMetric
metric definitions to RedisHLL.
A few changes to the specs were also required to get this working.
The code for AggregatedMetric
will be removed in a follow-up issue. See #450589 (closed) for the complete plan.
I used the below script to rewrite the metric definitions:
Script
files = %w[
config/metrics/counts_7d/20210216180339_ide_edit_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210216184955_ecosystem_total_unique_counts_weekly.yml
config/metrics/counts_7d/20230417063146_i_container_registry_writes_user_weekly.yml
config/metrics/counts_7d/20210216184935_user_packages_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210216184848_deploy_token_packages_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210216184801_quickactions_total_unique_counts_weekly.yml
config/metrics/counts_7d/20220222215852_xmau_project_management.yml
config/metrics/counts_7d/20210216175014_analytics_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210216184452_code_review_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210216180620_incident_management_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210427103328_code_review_group_monthly_active_users.yml
config/metrics/counts_7d/20210216180515_incident_management_incidents_total_unique_counts.yml
config/metrics/counts_7d/20210216180429_search_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210427103407_code_review_category_monthly_active_users.yml
config/metrics/counts_7d/20220222215855_users_work_items.yml
config/metrics/counts_7d/20230112174745_i_testing_active_user_weekly.yml
config/metrics/counts_7d/20210216181503_issues_edit_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210216180513_incident_management_alerts_total_unique_counts.yml
config/metrics/counts_7d/20220615103711_incident_management_timeline_event_total_unique_counts_weekly.yml
config/metrics/counts_7d/20210427103452_code_review_extension_category_monthly_active_users.yml
config/metrics/counts_7d/20210216174908_analytics_unique_visits_for_any_target.yml
config/metrics/counts_7d/20220222215851_xmau_plan.yml
config/metrics/counts_7d/20210427105030_pipeline_authoring_total_unique_counts_weekly.yml
config/metrics/counts_7d/20220315223220_error_tracking_total_unique_counts_weekly.yml
config/metrics/schema/redis_hll.json
config/metrics/counts_28d/20220222215952_xmau_project_management.yml
config/metrics/counts_28d/20210216181504_issues_edit_total_unique_counts_monthly.yml
config/metrics/counts_28d/20220615103718_incident_management_timeline_event_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210427103119_code_review_group_monthly_active_users.yml
config/metrics/counts_28d/20210427105033_pipeline_authoring_total_unique_counts_monthly.yml
config/metrics/counts_28d/20230417064258_i_container_registry_writes_user_monthly.yml
config/metrics/counts_28d/20210216184803_quickactions_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210427103010_code_review_extension_category_monthly_active_users.yml
config/metrics/counts_28d/20210216180622_incident_management_total_unique_counts_monthly.yml
config/metrics/counts_28d/20220222215951_xmau_plan.yml
config/metrics/counts_28d/20210216184454_code_review_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210216175016_analytics_total_unique_counts_monthly.yml
config/metrics/counts_28d/20220315223227_error_tracking_total_unique_counts_monthly.yml
config/metrics/counts_28d/20230112174745_i_testing_active_user_monthly.yml
config/metrics/counts_28d/20210216180341_ide_edit_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210216184957_ecosystem_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210216180327_action_monthly_active_users_ide_edit.yml
config/metrics/counts_28d/20210216184937_user_packages_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210216184850_deploy_token_packages_total_unique_counts_monthly.yml
config/metrics/counts_28d/20220222215955_users_work_items.yml
config/metrics/counts_28d/20210216174910_analytics_unique_visits_for_any_target_monthly.yml
config/metrics/counts_28d/20210216180511_incident_management_incidents_total_unique_counts.yml
config/metrics/counts_28d/20210216180509_incident_management_alerts_total_unique_counts.yml
config/metrics/counts_28d/20210216180431_search_total_unique_counts_monthly.yml
config/metrics/counts_28d/20210427102618_code_review_category_monthly_active_users.yml
config/metrics/counts_28d/20210216183922_search_unique_visits_for_any_target_monthly.yml
ee/config/metrics/counts_7d/20210318183220_epics_usage_total_unique_counts_weekly.yml
ee/config/metrics/counts_7d/20210216183211_compliance_features_track_unique_visits_union.yml
ee/config/metrics/counts_7d/20231023133430_users_visiting_compliance_pages_weekly.yml
ee/config/metrics/counts_7d/20210216183914_compliance_unique_visits_for_any_target.yml
ee/config/metrics/counts_7d/20210216183920_search_unique_visits_for_any_target_weekly.yml
ee/config/metrics/counts_7d/20210507171838_epic_boards_usage_total_unique_counts_weekly.yml
ee/config/metrics/counts_7d/20230815130614_users_visiting_vulnerability_management_pages_weekly.yml
ee/config/metrics/counts_7d/20220803103442_issuable_resource_links_total_unique_counts_weekly.yml
ee/config/metrics/counts_7d/20230807121101_users_visiting_security_policies_pages_weekly.yml
ee/config/metrics/counts_7d/20210216183944_compliance_total_unique_counts_weekly.yml
ee/config/metrics/counts_7d/20210216183219_i_testing_paid_monthly_active_user_total.yml
ee/config/metrics/counts_7d/20230815131036_users_visiting_dependency_management_pages_weekly.yml
ee/config/metrics/counts_7d/20230807111736_users_visiting_govern_pages_weekly.yml
ee/config/metrics/counts_7d/20230815131251_users_visiting_threat_insights_pages_weekly.yml
ee/config/metrics/counts_28d/20230815130614_users_visiting_vulnerability_management_pages_monthly.yml
ee/config/metrics/counts_28d/20230815131251_users_visiting_threat_insights_pages_monthly.yml
ee/config/metrics/counts_28d/20220803103446_issuable_resource_links_total_unique_counts_monthly.yml
ee/config/metrics/counts_28d/20210216183946_compliance_total_unique_counts_monthly.yml
ee/config/metrics/counts_28d/20210216183201_compliance_features_track_unique_visits_union.yml
ee/config/metrics/counts_28d/20230815131036_users_visiting_dependency_management_pages_monthly.yml
ee/config/metrics/counts_28d/20210216183209_i_testing_paid_monthly_active_user_total.yml
ee/config/metrics/counts_28d/20210216183916_compliance_unique_visits_for_any_target_monthly.yml
ee/config/metrics/counts_28d/20231023133430_users_visiting_compliance_pages_monthly.yml
ee/config/metrics/counts_28d/20230807121101_users_visiting_security_policies_pages_monthly.yml
ee/config/metrics/counts_28d/20210318183733_epics_usage_total_unique_counts_monthly.yml
ee/config/metrics/counts_28d/20230807111737_users_visiting_govern_pages_monthly.yml
ee/config/metrics/counts_28d/20210507171840_epic_boards_usage_total_unique_counts_monthly.yml
]
def rewrite(file)
in_events = false
unique = 'TODO'
lines = []
File.read(file).lines.each do |line|
tokens = line.strip.split(' ')
if tokens[0] == 'instrumentation_class:'
lines << "instrumentation_class: RedisHLLMetric\n"
next
end
in_events = false if line[0] != ' '
if line.strip == 'events:'
lines << "events:\n"
in_events = true
next
end
if ['aggregate:', 'options:'].include?(line.strip)
next
end
if tokens[0] == 'attribute:'
unique = tokens.last
next
end
if in_events
event_name = line.strip.split(' ').last.gsub("'", "")
lines << "- name: #{event_name}\n"
lines << " unique: #{unique}\n"
next
end
lines << line
end
File.write(file, lines.join)
end
files.each do |file|
rewrite(file)
end
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
- Find an event that is used in one of the migrated metrics that you want to use for testing. We can use
users_visiting_security_policies
. - On
master
start the monitor:rails runner scripts/internal_events/monitor.rb users_visiting_security_policies
- Start
gdk rails console
and runGitlab::UsageDataCounters::HLLRedisCounter.track_event('users_visiting_security_policies', values: SecureRandom.uuid)
- The monitor should now look something like this:
- Note down the metric values
- Switch to the this branch, restart the monitor and restart
gdk rails console
- Verify that that the values you see in the monitor are the same as they were on
master
- Run
Gitlab::UsageDataCounters::HLLRedisCounter.track_event('users_visiting_security_policies', values: SecureRandom.uuid)
again. - Verify that the values in the monitor is updated as expected.
- Verify that all metrics listed in the monitor have instrumentation class
RedisHLLMetric
like this
Edited by Jonas Larsen