Commit 27d75b30 authored by Alper Akgun's avatar Alper Akgun

Rolling 28 day time period counters for snippets

Also adds the "counts_monthly" section to the usage ping
parent 04f6bd8e
---
title: Rolling 28 day time period counters for snippets
merge_request: 34363
author:
type: added
......@@ -724,12 +724,4 @@ RSpec.describe Gitlab::UsageData do
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 @@ module Gitlab
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 @@ module Gitlab
)
}
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 @@ FactoryBot.define do
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 @@ describe Gitlab::UsageData, :aggregate_failures do
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 @@ describe Gitlab::UsageData, :aggregate_failures do
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 @@ describe Gitlab::UsageData, :aggregate_failures do
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 @@ module UsageDataHelpers
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
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