Commit 2304a32e authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'ali/refactor-usage-data-finished-at' into 'master'

Refactor how finished_at is merged into usage data

Closes #219472

See merge request gitlab-org/gitlab!34331
parents 9a2eb9a4 e26299bc
...@@ -43,16 +43,11 @@ module EE ...@@ -43,16 +43,11 @@ module EE
override :uncached_data override :uncached_data
def uncached_data def uncached_data
with_finished_at(:recording_ee_finished_at) do
super super
.merge(usage_activity_by_stage) .merge(usage_activity_by_stage)
.merge(usage_activity_by_stage(:usage_activity_by_stage_monthly, default_time_period)) .merge(usage_activity_by_stage(:usage_activity_by_stage_monthly, default_time_period))
.merge(recording_ee_finish_data)
end end
def recording_ee_finish_data
{
recording_ee_finished_at: Time.now
}
end end
override :features_usage_data override :features_usage_data
......
...@@ -157,6 +157,10 @@ RSpec.describe Gitlab::UsageData do ...@@ -157,6 +157,10 @@ RSpec.describe Gitlab::UsageData do
expect(subject[:counts][:user_preferences_group_overview_details]).to eq(User.active.count - 2) # we have exactly 2 active users with security dashboard set expect(subject[:counts][:user_preferences_group_overview_details]).to eq(User.active.count - 2) # we have exactly 2 active users with security dashboard set
expect(subject[:counts][:user_preferences_group_overview_security_dashboard]).to eq 2 expect(subject[:counts][:user_preferences_group_overview_security_dashboard]).to eq 2
end end
it 'includes a recording_ee_finished_at timestamp' do
expect(subject[:recording_ee_finished_at]).to be_a(Time)
end
end end
describe '.features_usage_data_ee' do describe '.features_usage_data_ee' do
...@@ -721,14 +725,6 @@ RSpec.describe Gitlab::UsageData do ...@@ -721,14 +725,6 @@ RSpec.describe Gitlab::UsageData do
end end
end end
describe '.recording_ee_finished_at' do
subject { described_class.recording_ee_finish_data }
it 'gathers time ee recording finishes at' do
expect(subject[:recording_ee_finished_at]).to be_a(Time)
end
end
def for_defined_days_back(days: [29, 2]) def for_defined_days_back(days: [29, 2])
days.each do |n| days.each do |n|
Timecop.travel(n.days.ago) do Timecop.travel(n.days.ago) do
......
...@@ -29,6 +29,7 @@ module Gitlab ...@@ -29,6 +29,7 @@ module Gitlab
def uncached_data def uncached_data
clear_memoized_limits clear_memoized_limits
with_finished_at(:recording_ce_finished_at) do
license_usage_data license_usage_data
.merge(system_usage_data) .merge(system_usage_data)
.merge(features_usage_data) .merge(features_usage_data)
...@@ -36,7 +37,7 @@ module Gitlab ...@@ -36,7 +37,7 @@ module Gitlab
.merge(cycle_analytics_usage_data) .merge(cycle_analytics_usage_data)
.merge(object_store_usage_data) .merge(object_store_usage_data)
.merge(topology_usage_data) .merge(topology_usage_data)
.merge(recording_ce_finish_data) end
end end
def to_json(force_refresh: false) def to_json(force_refresh: false)
...@@ -59,12 +60,6 @@ module Gitlab ...@@ -59,12 +60,6 @@ module Gitlab
Time.now Time.now
end end
def recording_ce_finish_data
{
recording_ce_finished_at: Time.now
}
end
# rubocop: disable Metrics/AbcSize # rubocop: disable Metrics/AbcSize
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def system_usage_data def system_usage_data
......
...@@ -92,6 +92,10 @@ module Gitlab ...@@ -92,6 +92,10 @@ module Gitlab
[result, duration] [result, duration]
end end
def with_finished_at(key, &block)
yield.merge(key => Time.now)
end
private private
def redis_usage_counter def redis_usage_counter
......
...@@ -169,6 +169,10 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -169,6 +169,10 @@ describe Gitlab::UsageData, :aggregate_failures do
expect { subject }.not_to raise_error expect { subject }.not_to raise_error
end end
it 'includes a recording_ce_finished_at timestamp' do
expect(subject[:recording_ce_finished_at]).to be_a(Time)
end
it 'jira usage works when queries time out' do it 'jira usage works when queries time out' do
allow_any_instance_of(ActiveRecord::Relation) allow_any_instance_of(ActiveRecord::Relation)
.to receive(:find_in_batches).and_raise(ActiveRecord::StatementInvalid.new('')) .to receive(:find_in_batches).and_raise(ActiveRecord::StatementInvalid.new(''))
...@@ -216,14 +220,6 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -216,14 +220,6 @@ describe Gitlab::UsageData, :aggregate_failures do
end end
end end
describe '.recording_ce_finished_at' do
subject { described_class.recording_ce_finish_data }
it 'gathers time ce recording finishes at' do
expect(subject[:recording_ce_finished_at]).to be_a(Time)
end
end
context 'when not relying on database records' do context 'when not relying on database records' do
describe '#features_usage_data_ce' do describe '#features_usage_data_ce' do
subject { described_class.features_usage_data_ce } subject { described_class.features_usage_data_ce }
......
...@@ -108,4 +108,14 @@ describe Gitlab::Utils::UsageData do ...@@ -108,4 +108,14 @@ describe Gitlab::Utils::UsageData do
expect(duration).to eq(2) expect(duration).to eq(2)
end end
end end
describe '#with_finished_at' do
it 'adds a timestamp to the hash yielded by the block' do
freeze_time do
result = described_class.with_finished_at(:current_time) { { a: 1 } }
expect(result).to eq(a: 1, current_time: Time.now)
end
end
end
end end
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