Add token management events and metrics (rotation and admin_token api)

Related to #515679 (closed)

What does this MR do and why?

Adds 4 token management events and 11 metrics.

Events

  • rotate_pat
  • rotate_grat
  • rotate_prat
  • use_admin_token_api

Namespace Metrics

  • redis_hll_counters.count_distinct_namespace_id_from_rotate_grat
  • redis_hll_counters.count_distinct_namespace_id_from_rotate_pat
  • redis_hll_counters.count_distinct_namespace_id_from_rotate_prat
  • redis_hll_counters.count_distinct_namespace_id_from_use_admin_token_api

User Metrics

  • redis_hll_counters.count_distinct_user_id_from_rotate_grat
  • redis_hll_counters.count_distinct_user_id_from_rotate_pat
  • redis_hll_counters.count_distinct_user_id_from_rotate_prat
  • redis_hll_counters.count_distinct_user_id_from_use_admin_token_api

Cummulative Metrics

  • redis_hll_counters.count_distinct_namespace_id_from_token_management_actions
  • redis_hll_counters.count_distinct_user_id_from_token_management_actions
  • counts.count_total_token_management_actions

How to set up and validate locally

Checkout this MR

Namespace-level metrics

rotate_pat

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the rotate_pat event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_rotate_pat_weekly')
Gitlab::InternalEvents.track_event('rotate_pat', user: User.first, namespace: User.first.namespace, project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_rotate_pat_weekly')

rotate_grat

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the rotate_grat event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_rotate_grat_weekly')
Gitlab::InternalEvents.track_event('rotate_grat', user: User.first, namespace: Group.find(2), project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_rotate_grat_weekly')

rotate_prat

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the rotate_pat event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_rotate_prat_weekly')
Gitlab::InternalEvents.track_event('rotate_prat', user: User.first, namespace: Project.find(1).namespace, project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_rotate_prat_weekly')

use_admin_api_token

Make sure your user is an admin

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the use_admin_api_token event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_use_admin_token_api_weekly')
Gitlab::InternalEvents.track_event('use_admin_token_api', user: User.first, namespace: Group.find(1), project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_use_admin_token_api_weekly')
User-level metrics

rotate_pat

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the rotate_pat event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_rotate_pat_weekly')
Gitlab::InternalEvents.track_event('rotate_pat', user: User.first, namespace: User.first.namespace, project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_rotate_pat_weekly')

rotate_grat

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the rotate_grat event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_rotate_grat_weekly')
Gitlab::InternalEvents.track_event('rotate_grat', user: User.first, namespace: Group.find(2), project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_rotate_grat_weekly')

rotate_prat

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the rotate_pat event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_rotate_prat_weekly')
Gitlab::InternalEvents.track_event('rotate_prat', user: User.second, namespace: Project.find(1).namespace, project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_rotate_prat_weekly')

use_admin_api_token

Make sure your user is an admin

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count & trigger the use_admin_api_token event:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_use_admin_token_api_weekly')
Gitlab::InternalEvents.track_event('use_admin_token_api', user: User.first, namespace: Group.find(1), project: nil)
  1. Check to make sure that its respective metric was incremented:
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_use_admin_token_api_weekly')
Cummulative-level metrics

By the time you test this, you should have accumulated multiple metrics. If not, trigger an event using the instructions above

Namespaces

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_namespace_id_from_token_management_actions_weekly')

Users

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('redis_hll_counters.count_distinct_user_id_from_token_management_actions_weekly')

Total

  1. Run your rails console in your terminal:
gdk rails console
  1. Check initial metric count:
require_relative 'spec/support/helpers/service_ping_helpers.rb'
ServicePingHelpers.get_current_usage_metric_value('counts.count_total_token_management_actions')

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.

Edited by Hakeem Abdul-Razak

Merge request reports

Loading