Skip to content

Add total count metrics to Gitlab Internal Events

What does this MR do and why?

Adds support for all time counters (aka Redis counters) to Gitlab Internal Events Tracking.

Any event sent to track_event is now counted with a Redis counter. If a metric is defined on one or more events without a unique property and InternalEventsAllTimeTotalCountMetric as instrumentation_class it will be included in the service ping payload.

Example metric definition

key_path: count_total_click_terraform_mr_plan_button
description: Total number of times somebody clicked on the Terraform MR plan button
# ---------------- [snip] ----------------
time_frame: all
data_source: internal_events
instrumentation_class: InternalEventsAllTimeTotalCountMetric
options:
  events:
    - click_terraform_mr_plan_button
events:
  - name: click_terraform_mr_plan_button

The quick start guide will be updated in a separate MR.

Adding support for existing Redis metrics will be part of #424892 (closed).

How to set up and validate locally

  1. Create a new metric based on an existing event:

    bin/rails g gitlab:analytics:internal_events \
     --time_frames=all \
     --group=project_management \
     --stage=plan \
     --section=dev \
     --event=click_terraform_mr_plan_button \
     --mr=https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129618
  2. Start gdk rails console

  3. Check the current value of the metric: Gitlab::Usage::ServicePingReport.for(output: :non_sql_metrics_values)["count_total_click_terraform_mr_plan_button"]

  4. Trigger the event: Gitlab::InternalEvents.track_event("click_terraform_mr_plan_button")

  5. Verify that the metric value increased: Gitlab::Usage::ServicePingReport.for(output: :non_sql_metrics_values)["count_total_click_terraform_mr_plan_button"]

MR acceptance checklist

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

Related to #412999 (closed)

Edited by Jonas Larsen

Merge request reports