Skip to content

Remove meta programming from MetricDefinition

What does this MR do and why?

Objects of the class MetricDefinition are backed by a hash called attributes which is loaded directly from all the yaml files located in the directories config/metrics and ee/config/metrics.

Until now MetricDefinition implemented method_missing to let give access to the backing hash by using the hash keys as method names.

This property was not used a lot since we mostly go through the attributes property instead. E.g. instead of calling definition.data_source we call `definition.attributes[:data_source].

Last week, I spent a a lot of time trying to understand why the below code didn't work as expected:

data_source = 'redis_hll' if data_source == 'internal_events'

And why this worked:

if data_source == 'internal_events'
  data_source = 'redis_hll' 
end

Turns out that the meta programming was causing this misbehaviour.

Since we are not using this a lot, I want to simplify the code and prevent that anybody else falls into this trap in the future.

Note that is the first refactoring of MetricDefinition. The next MR will encapsulate attributes so we no longer expose the yaml files directly.

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.

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

Numbered steps to set up and validate the change are strongly suggested.

Edited by Jonas Larsen

Merge request reports