Only validate metrics definitions with test to reduce startup time
What does this MR do and why?
As the number of metrics definitions has increased over the years, validating all the metrics takes longer and longer.
The performance issue became evident when we started calling Gitlab::Usage::MetricDefinition.all
indirectly through the internal_events.rb
initializer. Until then the performance hit was taken by the first request using a RedisHLL
metric and we never realized it because it grew slowly as we added more and more metrics.
This MR remove the validation from the loading phase of metrics. The validation is now only executed as part of the test suite.
Before
./config/initializers/internal_events.rb
took 1133 ms.
> gitlab git:(414653-only-validate-metrics-definitions-during-test) bumbler -t 300 --initializers | grep internal_events
1133.47 ./config/initializers/internal_events.rb
After
./config/initializers/internal_events.rb
took 705 ms.
> gitlab git:(414653-only-validate-metrics-definitions-during-test) bumbler -t 300 --initializers | grep internal_events
705.19 ./config/initializers/internal_events.rb
How to set up and validate locally
Make sure you have the bumbler
gem installed.
- Run
bumbler -t 300 --initializers
onmaster
- Run
bumbler -t 300 --initializers
on this branch - See that the initializer takes ~30% less time to execute now
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #414653 (closed)