Commit 49d44e93 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'ag-rename-convdev-usage-pings' into 'master'

[Usage Pings] Rename ConvDev Index to DevOps Score

See merge request gitlab-org/gitlab!21132
parents eac3ad67 f4a4398e
......@@ -36,10 +36,12 @@ class SubmitUsagePingService
private
def store_metrics(response)
return unless response['conv_index'].present?
metrics = response['conv_index'] || response['dev_ops_score']
return unless metrics.present?
DevOpsScore::Metric.create!(
response['conv_index'].slice(*METRICS)
metrics.slice(*METRICS)
)
end
end
......@@ -5,6 +5,49 @@ require 'spec_helper'
describe SubmitUsagePingService do
include StubRequests
let(:score_params) do
{
score: {
leader_issues: 10.2,
instance_issues: 3.2,
percentage_issues: 31.37,
leader_notes: 25.3,
instance_notes: 23.2,
leader_milestones: 16.2,
instance_milestones: 5.5,
leader_boards: 5.2,
instance_boards: 3.2,
leader_merge_requests: 5.2,
instance_merge_requests: 3.2,
leader_ci_pipelines: 25.1,
instance_ci_pipelines: 21.3,
leader_environments: 3.3,
instance_environments: 2.2,
leader_deployments: 41.3,
instance_deployments: 15.2,
leader_projects_prometheus_active: 0.31,
instance_projects_prometheus_active: 0.30,
leader_service_desk_issues: 15.8,
instance_service_desk_issues: 15.1,
non_existing_column: 'value'
}
}
end
let(:with_dev_ops_score_params) { { dev_ops_score: score_params[:score] } }
let(:with_conv_index_params) { { conv_index: score_params[:score] } }
let(:without_dev_ops_score_params) { { dev_ops_score: {} } }
context 'when usage ping is disabled' do
before do
stub_application_setting(usage_ping_enabled: false)
......@@ -19,13 +62,25 @@ describe SubmitUsagePingService do
end
end
shared_examples 'saves DevOps score data from the response' do
it do
expect { subject.execute }
.to change { DevOpsScore::Metric.count }
.by(1)
expect(DevOpsScore::Metric.last.leader_issues).to eq 10.2
expect(DevOpsScore::Metric.last.instance_issues).to eq 3.2
expect(DevOpsScore::Metric.last.percentage_issues).to eq 31.37
end
end
context 'when usage ping is enabled' do
before do
stub_application_setting(usage_ping_enabled: true)
end
it 'sends a POST request' do
response = stub_response(without_conv_index_params)
response = stub_response(without_dev_ops_score_params)
subject.execute
......@@ -33,7 +88,7 @@ describe SubmitUsagePingService do
end
it 'refreshes usage data statistics before submitting' do
stub_response(without_conv_index_params)
stub_response(without_dev_ops_score_params)
expect(Gitlab::UsageData).to receive(:to_json)
.with(force_refresh: true)
......@@ -42,62 +97,21 @@ describe SubmitUsagePingService do
subject.execute
end
it 'saves DevOps Score data from the response' do
stub_response(with_conv_index_params)
context 'when conv_index data is passed' do
before do
stub_response(with_conv_index_params)
end
expect { subject.execute }
.to change { DevOpsScore::Metric.count }
.by(1)
expect(DevOpsScore::Metric.last.leader_issues).to eq 10.2
expect(DevOpsScore::Metric.last.instance_issues).to eq 3.2
expect(DevOpsScore::Metric.last.percentage_issues).to eq 31.37
it_behaves_like 'saves DevOps score data from the response'
end
end
def without_conv_index_params
{
conv_index: {}
}
end
def with_conv_index_params
{
conv_index: {
leader_issues: 10.2,
instance_issues: 3.2,
percentage_issues: 31.37,
leader_notes: 25.3,
instance_notes: 23.2,
leader_milestones: 16.2,
instance_milestones: 5.5,
context 'when DevOps score data is passed' do
before do
stub_response(with_dev_ops_score_params)
end
leader_boards: 5.2,
instance_boards: 3.2,
leader_merge_requests: 5.2,
instance_merge_requests: 3.2,
leader_ci_pipelines: 25.1,
instance_ci_pipelines: 21.3,
leader_environments: 3.3,
instance_environments: 2.2,
leader_deployments: 41.3,
instance_deployments: 15.2,
leader_projects_prometheus_active: 0.31,
instance_projects_prometheus_active: 0.30,
leader_service_desk_issues: 15.8,
instance_service_desk_issues: 15.1,
non_existing_column: 'value'
}
}
it_behaves_like 'saves DevOps score data from the response'
end
end
def stub_response(body)
......
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