Commit ba527d74 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch '337497-fix-handling-service-ping-response' into 'master'

Fix handling Service Ping response with only usage_data_id

See merge request gitlab-org/gitlab!72344
parents c799e7be e06fe59c
...@@ -78,7 +78,7 @@ module ServicePing ...@@ -78,7 +78,7 @@ module ServicePing
def store_metrics(response) 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 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!( DevOpsReport::Metric.create!(
metrics.slice(*METRICS) metrics.slice(*METRICS)
......
...@@ -50,6 +50,7 @@ RSpec.describe ServicePing::SubmitService do ...@@ -50,6 +50,7 @@ RSpec.describe ServicePing::SubmitService do
let(:with_dev_ops_score_params) { { dev_ops_score: score_params[:score] } } let(:with_dev_ops_score_params) { { dev_ops_score: score_params[:score] } }
let(:with_conv_index_params) { { conv_index: 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 shared_examples 'does not run' do
it do it do
...@@ -173,6 +174,29 @@ RSpec.describe ServicePing::SubmitService do ...@@ -173,6 +174,29 @@ RSpec.describe ServicePing::SubmitService do
end end
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 context 'when version app usage_data_id is invalid' do
let(:usage_data_id) { -1000 } 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