Commit e06fe59c authored by Piotr Skorupa's avatar Piotr Skorupa Committed by Mikolaj Wawrzyniak

Fix handling Service Ping response DevOps metrics

When only partial Service Ping is being reporeted
by instance, returned response does not contain
required metrics casuing DevOps metric record
creation to fail and raise and error.

Changelog: fixed
parent d7459cdd
......@@ -78,7 +78,7 @@ module ServicePing
def store_metrics(response)
metrics = response['conv_index'] || response['dev_ops_score'] # leaving dev_ops_score here, as the response data comes from the gitlab-version-com
return unless metrics.present?
return unless metrics.except('usage_data_id').present?
DevOpsReport::Metric.create!(
metrics.slice(*METRICS)
......
......@@ -50,6 +50,7 @@ RSpec.describe ServicePing::SubmitService do
let(:with_dev_ops_score_params) { { dev_ops_score: score_params[:score] } }
let(:with_conv_index_params) { { conv_index: score_params[:score] } }
let(:with_usage_data_id_params) { { conv_index: { usage_data_id: usage_data_id } } }
shared_examples 'does not run' do
it do
......@@ -173,6 +174,29 @@ RSpec.describe ServicePing::SubmitService do
end
end
context 'when only usage_data_id is passed in response' do
before do
stub_response(body: with_usage_data_id_params)
end
it 'does not save DevOps report data' do
expect { subject.execute }.not_to change { DevOpsReport::Metric.count }
end
it 'saves usage_data_id to version_usage_data_id_value' do
recorded_at = Time.current
usage_data = { uuid: 'uuid', recorded_at: recorded_at }
expect(Gitlab::UsageData).to receive(:data).with(force_refresh: true).and_return(usage_data)
subject.execute
raw_usage_data = RawUsageData.find_by(recorded_at: recorded_at)
expect(raw_usage_data.version_usage_data_id_value).to eq(31643)
end
end
context 'when version app usage_data_id is invalid' do
let(:usage_data_id) { -1000 }
......
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