Commit b51407c1 authored by Piotr Skorupa's avatar Piotr Skorupa

Add saving usage_data_id from Usage Ping response

This modifies SubmitUsagePingService to save `usage_data_id` from
version-gitlab-com app to help correlate records from RawUsageData with
those stored in the versions app, as previously this was only possible
by relying on `recorded_at`.
parent d02c44ee
......@@ -35,7 +35,10 @@ class SubmitUsagePingService
raise SubmissionError.new("Unsuccessful response code: #{response.code}") unless response.success?
raw_usage_data.update_sent_at! if raw_usage_data
if raw_usage_data
raw_usage_data.update_sent_at!
raw_usage_data.update!(version_usage_data_id: response.dig('conv_index', 'usage_data_id'))
end
store_metrics(response)
end
......
......@@ -46,7 +46,7 @@ RSpec.describe SubmitUsagePingService do
end
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].merge(usage_data_id: 31643) } }
let(:without_dev_ops_score_params) { { dev_ops_score: {} } }
shared_examples 'does not run' do
......@@ -124,6 +124,19 @@ RSpec.describe SubmitUsagePingService do
end
it_behaves_like 'saves DevOps report data from the response'
it 'saves usage_data_id to version_usage_data_id' 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).to eq(31643)
end
end
context 'when DevOps report data is passed' do
......
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