Skip to content

Persist Label Based Stages in Cycle Analytics

Adam Hegyi requested to merge 12196-label-based-ca-events into master

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 for GroupStage and ProjectStage
  • 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 a Group (GroupStage), often referred as parent.
  • Stage is used to calculate metrics:
    • Find all the Issue or MergeRequest records matching with a date range query (start_event and end_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)

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 and end_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

ca-custom-stages__add--filled-out

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

Availability and Testing

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

Merge request reports