Commit dd3927e3 authored by Alper Akgun's avatar Alper Akgun

Calculate recorded_at before other usage data

Ensures recorded_at is set before any other usage data calculation
parent 4af72bc5
...@@ -39,11 +39,9 @@ module EE ...@@ -39,11 +39,9 @@ module EE
override :uncached_data override :uncached_data
def uncached_data def uncached_data
usage_activity_by_stage_monthly = usage_activity_by_stage(:usage_activity_by_stage_monthly, default_time_period)
super super
.merge(usage_activity_by_stage) .merge(usage_activity_by_stage)
.merge(usage_activity_by_stage_monthly) .merge(usage_activity_by_stage(:usage_activity_by_stage_monthly, default_time_period))
.merge(recording_ee_finish_data) .merge(recording_ee_finish_data)
end end
......
...@@ -45,7 +45,7 @@ module Gitlab ...@@ -45,7 +45,7 @@ module Gitlab
def license_usage_data def license_usage_data
{ {
recorded_at: Time.now, # should be calculated very first recorded_at: recorded_at,
uuid: alt_usage_data { Gitlab::CurrentSettings.uuid }, uuid: alt_usage_data { Gitlab::CurrentSettings.uuid },
hostname: alt_usage_data { Gitlab.config.gitlab.host }, hostname: alt_usage_data { Gitlab.config.gitlab.host },
version: alt_usage_data { Gitlab::VERSION }, version: alt_usage_data { Gitlab::VERSION },
...@@ -55,6 +55,10 @@ module Gitlab ...@@ -55,6 +55,10 @@ module Gitlab
} }
end end
def recorded_at
Time.now
end
def recording_ce_finish_data def recording_ce_finish_data
{ {
recording_ce_finished_at: Time.now recording_ce_finished_at: Time.now
......
...@@ -10,6 +10,17 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -10,6 +10,17 @@ describe Gitlab::UsageData, :aggregate_failures do
stub_object_store_settings stub_object_store_settings
end end
describe '#uncached_data' do
it 'ensures recorded_at is set before any other usage data calculation' do
%i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class).not_to receive(method)
end
expect(described_class).to receive(:recorded_at).and_raise(Exception.new('Stopped calculating recorded_at'))
expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at')
end
end
describe '#data' do describe '#data' do
let!(:ud) { build(:usage_data) } let!(:ud) { build(:usage_data) }
......
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