Add ability to increment counts metric by custom amount

Problem

With InternalEvents we have ability to create counter metrics which count events triggering (i.e. amount of the events). This allows users to count events like page visit, tab clicks, project imports.

Periodically we see requests to trigger events with custom amount as values. For example, after running a CI pipeline a goal could be to count the elapsed time and get a weekly metric on it. Or to count license components

While its possible to create such metric in GitLab.com using snowplow and custom values, on SM instances it's not implementable.

Desired Outcome

Add ability to increment counts metric by custom amount.

Potential Solution

Modifying the exiting Redis metric

When an event called with non nil value, if counts metric exists, increment this metric by the value amount.

For example:

InternalEvents.track_event('ci_duration_captured', value: 120)
InternalEvents.track_event('ci_duration_captured', value: 100)
key_path: counts.ci_duration_captured_weekly
events:
- name: ci_duration_captured
  sum: true
> UsageData.data[:counts][:ci_duration_captured_weekly]
=> 220

However, this would change API, hence we would need to add a new option to the metric definition which permits custom increase.

Use Instrumentation layer and create a new tracker class

It could be a reasonable solution to utilize instrumentation layer !167415 (merged) and add the new metric tracking class as an extra processing step

Event:

key_path: ci_duration_captured
extra_tracking_classes:
- TotalSumCounter

Metric:


key_path: totals.ci_duration_captured_weekly
time_frame: 7d
events:
- name: ci_duration_captured
  sum: true
class TotalSumCounter
  def track_event(_, _1, additional_properties)
    RedisCounter.increment_by(redis_key, additional_properties[:value]
  end
end

Documentation Update Needed

  • Yes
  • No

How to verify

Further actions needed

Edited by Niko Belokolodov