Skip to content

Stricter validation of metric definitions

Michał Wielich requested to merge michold-metrics-validation into master

What does this MR do and why?

Related to #416666 (closed)

We want to make metrics validation more strict. To make sure schema.json will not be growing indefinitely, we also want to split the rules into separate files.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Try to create/update a metric into something that doesn't pass the new validations:
    • a metric with internal_events data_source [eg. update this metric] and any of:
      • instrumentation_class undefined or has value other than RedisHLLMetric or TotalCountMetric
      • instrumentation_class is RedisHLLMetric and options not being exactly an object with an events property that is an array of strings
      • instrumentation_class is RedisHLLMetric and events not being an array of objects having exactly name and unique string properties
      • instrumentation_class is RedisHLLMetric and events[x].unique having a value other than "user.id", "project.id", or "namespace.id"
    • a metric with redis_hll data_source [eg. update this metric] and any of:
      • instrumentation_class other than RedisHLLMetric or AggregatedMetric
      • instrumentation_class as RedisHLLMetric but options is not exactly an object with events property that has an array of strings
    • a metric with redis data_source [eg. update this metric] and any of:
      • instrumentation_class other than RedisMetric or MergeRequestWidgetExtensionMetric
      • instrumentation_class set to MergeRequestWidgetExtensionMetric but options is not exactly an object with event and widget string properties
      • instrumentation_class set to RedisMetric but options is not exactly an object with event, prefix and optional include_usage_prefix properties
  2. Run a test file, for example bundle exec rspec spec/lib/gitlab/usage/metric_definition_spec.rb.
  3. This should raise an error due to invalid metrics: Gitlab::Usage::MetricDefinition::InvalidError

MR acceptance checklist

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

Edited by Michał Wielich

Merge request reports