[VSA] Expose the persisted stage duration via the API
Release note
Introduce a new way of calculating durations from 2 event timestamps where optionally the events can be array of timestamps. The array-based calculation should work for label based stages.
Overview
The VSA backend calculates durations in query time by subtracting the start event timestamp from the end event timestamp.
Change the aggregated VSA duration calculation by simply returning the duration_in_milliseconds
column from the DB tables (select(:duration_in_milliseconds)
). This can be done only for the aggregated backend, where the in_progress?
is false. (the in-progress view is a leftover feature that is currently not used, we can ignore that branch of the if
statement).
Relevant code: https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/analytics/cycle_analytics/aggregated/stage_query_helpers.rb
The change should be behind a feature flag. For enabled groups, we can verify the cumulative durations the following way (note, cumulative duration will only show up if #432568 (closed) is implemented):
- Create a stage with label added - label removed events
- Create an issue
- Add the label and wait 5 minutes
- Remove the label
- Wait a few minutes and add the label again
- Wait 5 minutes and remove the label
The view should show 10 minute duration for the issue.