Commit 6c29eaaf authored by Aakriti Gupta's avatar Aakriti Gupta

Add deployment frequency to Group Summary

parent b87db076
---
title: Add deployment frequency to Group Value Stream Analytics summary
merge_request: 28776
author:
type: added
......@@ -239,11 +239,18 @@ describe 'Group Value Stream Analytics', :js do
end
it 'displays the number of deploys' do
deploys_count = page.all(card_metric_selector).last
deploys_count = page.all(card_metric_selector)[1]
expect(deploys_count).to have_content('Deploys')
expect(deploys_count).to have_content('-')
end
it 'displays the deployment frequency' do
deployment_frequency = page.all(card_metric_selector).last
expect(deployment_frequency).to have_content(_('Deployment Frequency'))
expect(deployment_frequency).to have_content('-')
end
end
context 'with a sub group selected' do
......
......@@ -2,15 +2,18 @@
"type": "array",
"items": {
"minItems": 2,
"maxItems": 2,
"maxItems": 3,
"type": "object",
"required": ["value", "title"],
"properties": {
"value": {
"type": "integer"
"type": "number"
},
"title": {
"type": "string"
},
"unit": {
"type": "string"
}
},
"additionalProperties": false
......
......@@ -51,6 +51,21 @@ exports[`RecentActivityCard matches the snapshot 1`] = `
Deploys
</p>
</div>
<div
class="js-metric-card-item flex-grow text-center"
>
<h3
class="my-2"
>
-
</h3>
<p
class="text-secondary gl-font-size-small mb-2"
>
Deployment Frequency
</p>
</div>
</div>
</div>
......
......@@ -12,14 +12,42 @@ module Gitlab
end
def data
[serialize(Summary::Group::Issue.new(group: group, current_user: current_user, options: options)),
serialize(Summary::Group::Deploy.new(group: group, options: options))]
[issue_stats,
deploy_stats,
deployment_frequency_stats]
end
private
def serialize(summary_object)
AnalyticsSummarySerializer.new.represent(summary_object)
def issue_stats
serialize(
Summary::Group::Issue.new(
group: group, current_user: current_user, options: options)
)
end
def deployments_summary
@deployments_summary ||=
Summary::Group::Deploy.new(group: group, options: options)
end
def deploy_stats
serialize deployments_summary
end
def deployment_frequency_stats
serialize(
Summary::Group::DeploymentFrequency.new(
deployments: deployments_summary.value,
group: group,
options: options),
with_unit: true
)
end
def serialize(summary_object, with_unit: false)
AnalyticsSummarySerializer.new.represent(
summary_object, with_unit: with_unit)
end
end
end
......
# frozen_string_literal: true
module Gitlab
module CycleAnalytics
module Summary
module Group
class DeploymentFrequency < Group::Base
include GroupProjectsProvider
include SummaryHelper
def initialize(deployments:, group:, options:)
@deployments = deployments
super(group: group, options: options)
end
def title
_('Deployment Frequency')
end
def value
@value ||=
frequency(@deployments, options[:from], options[:to] || Time.now)
end
def unit
_('per day')
end
end
end
end
end
end
# frozen_string_literal: true
module Gitlab
module CycleAnalytics
module SummaryHelper
def frequency(count, from, to)
(count / days(from, to)).round(1)
end
def days(from, to)
[(to.end_of_day - from.beginning_of_day) / (24 * 60 * 60), 1].max
end
end
end
end
......@@ -6957,6 +6957,9 @@ msgstr ""
msgid "Deploying to"
msgstr ""
msgid "Deployment Frequency"
msgstr ""
msgid "Deployment|API"
msgstr ""
......@@ -25117,6 +25120,9 @@ msgstr ""
msgid "pending removal"
msgstr ""
msgid "per day"
msgstr ""
msgid "pipeline"
msgstr ""
......
......@@ -127,4 +127,50 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
end
end
end
describe '#deployment_frequency' do
let(:from) { 6.days.ago }
let(:to) { nil }
subject do
described_class.new(group, options: {
from: from,
to: to,
current_user: user
}).data.third
end
it 'includes the unit: `per day`' do
expect(subject[:unit]).to eq(_('per day'))
end
before do
Timecop.freeze(5.days.ago) do
create(:deployment, :success, project: project)
end
end
context 'when `to` is nil' do
it 'includes range until now' do
# 1 deployment over 7 days
expect(subject[:value]).to eq(0.1)
end
end
context 'when `to` is given' do
let(:from) { 10.days.ago }
let(:to) { 10.days.from_now }
before do
Timecop.freeze(5.days.from_now) do
create(:deployment, :success, project: project)
end
end
it 'returns deployment frequency within `from` and `to` range' do
# 2 deployments over 20 days
expect(subject[:value]).to eq(0.1)
end
end
end
end
......@@ -38,7 +38,7 @@ describe CycleAnalytics::GroupLevel do
end
it 'returns medians for each stage for a specific group' do
expect(subject.summary.map { |summary| summary[:value] }).to contain_exactly(1, 1)
expect(subject.summary.map { |summary| summary[:value] }).to contain_exactly(0.1, 1, 1)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment