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 ...@@ -239,11 +239,18 @@ describe 'Group Value Stream Analytics', :js do
end end
it 'displays the number of deploys' do 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('Deploys')
expect(deploys_count).to have_content('-') expect(deploys_count).to have_content('-')
end 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 end
context 'with a sub group selected' do context 'with a sub group selected' do
......
...@@ -2,15 +2,18 @@ ...@@ -2,15 +2,18 @@
"type": "array", "type": "array",
"items": { "items": {
"minItems": 2, "minItems": 2,
"maxItems": 2, "maxItems": 3,
"type": "object", "type": "object",
"required": ["value", "title"], "required": ["value", "title"],
"properties": { "properties": {
"value": { "value": {
"type": "integer" "type": "number"
}, },
"title": { "title": {
"type": "string" "type": "string"
},
"unit": {
"type": "string"
} }
}, },
"additionalProperties": false "additionalProperties": false
......
...@@ -51,6 +51,21 @@ exports[`RecentActivityCard matches the snapshot 1`] = ` ...@@ -51,6 +51,21 @@ exports[`RecentActivityCard matches the snapshot 1`] = `
Deploys Deploys
</p> </p>
</div> </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>
</div> </div>
......
...@@ -12,14 +12,42 @@ module Gitlab ...@@ -12,14 +12,42 @@ module Gitlab
end end
def data def data
[serialize(Summary::Group::Issue.new(group: group, current_user: current_user, options: options)), [issue_stats,
serialize(Summary::Group::Deploy.new(group: group, options: options))] deploy_stats,
deployment_frequency_stats]
end end
private private
def serialize(summary_object) def issue_stats
AnalyticsSummarySerializer.new.represent(summary_object) 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 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 "" ...@@ -6957,6 +6957,9 @@ msgstr ""
msgid "Deploying to" msgid "Deploying to"
msgstr "" msgstr ""
msgid "Deployment Frequency"
msgstr ""
msgid "Deployment|API" msgid "Deployment|API"
msgstr "" msgstr ""
...@@ -25117,6 +25120,9 @@ msgstr "" ...@@ -25117,6 +25120,9 @@ msgstr ""
msgid "pending removal" msgid "pending removal"
msgstr "" msgstr ""
msgid "per day"
msgstr ""
msgid "pipeline" msgid "pipeline"
msgstr "" msgstr ""
......
...@@ -127,4 +127,50 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do ...@@ -127,4 +127,50 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
end end
end 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 end
...@@ -38,7 +38,7 @@ describe CycleAnalytics::GroupLevel do ...@@ -38,7 +38,7 @@ describe CycleAnalytics::GroupLevel do
end end
it 'returns medians for each stage for a specific group' do 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 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