Skip to content
Snippets Groups Projects
Verified Commit 27d75b30 authored by Alper Akgun's avatar Alper Akgun :two:
Browse files

Rolling 28 day time period counters for snippets

Also adds the "counts_monthly" section to the usage ping
parent 04f6bd8e
No related branches found
No related tags found
1 merge request!34363Rolling 28 day time period counters for snippets
---
title: Rolling 28 day time period counters for snippets
merge_request: 34363
author:
type: added
......@@ -724,12 +724,4 @@ def ldap_server_config
end
end
end
def for_defined_days_back(days: [29, 2])
days.each do |n|
Timecop.travel(n.days.ago) do
yield
end
end
end
end
......@@ -32,6 +32,7 @@ def uncached_data
with_finished_at(:recording_ce_finished_at) do
license_usage_data
.merge(system_usage_data)
.merge(system_usage_data_monthly)
.merge(features_usage_data)
.merge(components_usage_data)
.merge(cycle_analytics_usage_data)
......@@ -161,9 +162,17 @@ def system_usage_data
)
}
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable Metrics/AbcSize
def system_usage_data_monthly
{
counts_monthly: {
snippets: count(Snippet.where(default_time_period))
}
}
end
# rubocop: enable CodeReuse/ActiveRecord
def cycle_analytics_usage_data
Gitlab::CycleAnalytics::UsageData.new.to_json
rescue ActiveRecord::StatementInvalid
......
......@@ -89,6 +89,11 @@
create(:grafana_integration, project: projects[2], enabled: false)
ProjectFeature.first.update_attribute('repository_access_level', 0)
# Create fresh & a month (28-days SMAU) old data
[2, 29].each do |n|
create(:snippet, created_at: n.days.ago)
end
end
end
end
......@@ -44,6 +44,10 @@
expect(UsageDataHelpers::COUNTS_KEYS - count_data.keys).to be_empty
end
it 'gathers usage counts monthly hash' do
expect(subject[:counts_monthly]).to be_an(Hash)
end
it 'gathers projects data correctly' do
count_data = subject[:counts]
......@@ -103,6 +107,8 @@
expect(count_data[:grafana_integrated_projects]).to eq(2)
expect(count_data[:clusters_applications_jupyter]).to eq(1)
expect(count_data[:clusters_management_project]).to eq(1)
expect(count_data[:snippets]).to eq(2)
end
it 'gathers object store usage correctly' do
......@@ -181,6 +187,18 @@
end
end
describe '.system_usage_data_monthly' do
let!(:ud) { build(:usage_data) }
subject { described_class.system_usage_data_monthly }
it 'gathers projects data correctly' do
counts_monthly = subject[:counts_monthly]
expect(counts_monthly[:snippets]).to eq(1)
end
end
describe '#usage_data_counters' do
subject { described_class.usage_data_counters }
......
......@@ -233,4 +233,12 @@ def allow_prometheus_queries
allow(client).to receive(:aggregate).and_return({})
end
end
def for_defined_days_back(days: [29, 2])
days.each do |n|
Timecop.travel(n.days.ago) do
yield
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment