Skip to content

Validate uniqueness of key_path in usage metric definition generator

What does this MR do?

This adds uniqueness validation of the key_path argument in Gitlab::UsageMetricDefinitionGenerator.

The same key_path can't be used twice, since it determines where the key is nested in the Usage Ping JSON payload.

To prevent this, the key_path for a newly generated metric definition should be checked against existing files. A naive approach would be to comb through all YAML files in config/metrics/**/*.yml. Instead, a shortlist of files to check is created, using the fact that filenames contain the metric name (the last part of the key path), e.g. 20210216181345_g_project_management_issue_weight_changed_monthly.yml contains key path redis_hll_counters.issues_edit.g_project_management_issue_weight_changed_monthly.

Changed the key_path lookup to check in Gitlab::Usage::MetricDefinition.definitions as a single source of truth.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #299291 (closed)

Edited by Piotr Skorupa

Merge request reports