Persist Label Based Stages in Cycle Analytics
What does this MR do?
This MR implements persistence for label based events within customizable cycle analytics feature.
This MR contains:
- Validation of
GroupLabel
associations forGroupStage
andProjectStage
- Event definitions (configuration)
- Event pairing rule definitions (configuration)
Note: This change is not visible to the end user. There will be a follow up MR that exposes label based events to the end users (API) and implements the necessary query logic.
What is Cycle Analytics
- Related issue: https://gitlab.com/gitlab-org/gitlab-ee/issues/12196
- Stages can be defined for a
Project
(ProjectStage
) or aGroup
(GroupStage
), often referred asparent
. -
Stage
is used to calculate metrics:- Find all the
Issue
orMergeRequest
records matching with a date range query (start_event
andend_event
) =Stage
. - Calculate the duration (
end_event_time
-start_event_time
) (already implemented and merged) - Extract the median duration. (already implemented and merged)
- Extract the list of records relevant to the date range. (already implemented and merged)
- Find all the
Storage
Cycle Analytics stages are stored in the database. To persist the label based stage events, we need to store the selected labels (FK).
- Only
GroupLabel
is allowed. -
GroupLabel
must be associated with the root group. (custom validator) - Since
start_event
andend_event
can be label based, we need two columns to store labels. (see Schema ) - If the selected event is label based, user must select a label:
start_event_label_id
,end_event_label_id
columns.
Test the Feature Locally
Requirements:
- Enable FF:
Feature.enable(:cycle_analytics)
- Create a group with one project
- Define a group label
- Create issues or merge requests and add/remove labels
In Rails console (FE is not ready):
Create a Stage
group = Group.find($YOUR_GROUP)
Analytics::CycleAnalytics::Stages::CreateService.new(parent: group, params: {
name: 'my stage',
start_event_identifier: 'issue_label_added',
start_event_label_id: $YOUR_LABEL_ID,
end_event_identifier: 'issue_label_removed',
end_event_label_id: $YOUR_LABEL_ID
}, current_user: $YOUR_USER).execute
Screenshots
On the Screenshot (see the form on the right side):
- Start Event:
MergeReqestLabelAdded
- Start Event Label:
wip::in-review
(GroupLabel)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Adam Hegyi