Add interactive generator for internal events
What does this MR do and why?
Adds an interactive CLI for Internal Events. The purpose is to allow users to easily create event/metric definition files without needed to scour the docs for context or encountering unexpected errors.
Functionality currently in-scope:
- Creating new event definitions
- Creating new metric definitions for internal events
- Tailoring usage examples for the specific event
Code structure overview
Script code:
- Entrypoint for cli:
scripts/internal_events/cli.rb
- Entrypoint for each flow:
- scripts/internal_events/cli/event_definer.rb --> Define a new event
- scripts/internal_events/cli/metric_definer.rb --> Define a new metric
- scripts/internal_events/cli/usage_viewer.rb --> Show usage examples
- scripts/internal_events/cli/event.rb & scripts/internal_events/cli/metric.rb define structure of definitions
- Equivalent to generator_templates/gitlab_internal_events/*.yml --> I tried to re-use the existing generator, but it was ultimately simpler/cleaner to define these separately
- scripts/internal_events/cli/text.rb contains many block strings for easy editing
- All helpers in scripts/internal_events/cli/helpers/ are grouped in scripts/internal_events/cli/helpers.rb & available across the entire script
Spec code:
- test cases defined in spec/fixtures/scripts/internal_events/new_metrics.yml & spec/fixtures/scripts/internal_events/new_events.yml assert that for existing files & keystrokes, the correct definitions are created
- there are a handful of tests for rendering specific behavior, but my goal was to optimize the tests for maintainability as the tool is modified/grows.
- spec/scripts/internal_events/cli_spec.rb includes examples for all flows & edge cases
Should be in scope but isn't yet:
Manual testing instructions for triggering an event from rails console & verifying service ping outputSpit out command to run internal events monitor for event
Known problems:
- File/keypath naming for the aggregate metrics isn't good. It results in really long filenames. Also not sure about introducing this mechanism?
AggregatedMetric
seems massively overworked & does the same thing asRedisHll
when provided multiple events, so I wasn't sure of intent. - RedisHLL metrics are grouped under the
redis_hll_counters
key by feature category, but feature category isn't a required field for the metric definition anymore. I'm not sold on requesting it from the user. Seems annoying, but then again, so does the mess of info that is the service ping payload. Related: https://gitlab.slack.com/archives/CL3A7GFPF/p1701204578630149. The methodology for excluding existing metrics relies on the file name, but that's a completely bad assumption. It'll miss lots of things.I'm not sure about the truth of the frontend-related notes about event identifiers...😅
How to set up and validate locally
- Run
ruby scripts/internal_events/cli.rb
fromgitlab/
directory of gdk
Screenshots or screen recordings
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.
Edited by Sarah Yasonik