Commit 4d442da5 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '221184-rolling-28-day-time-period-for-all-usage-ping-counters' into 'master'

Rolling 28 day time period counters for snippets

See merge request gitlab-org/gitlab!34363
parents 94cbd2d0 27d75b30
---
title: Rolling 28 day time period counters for snippets
merge_request: 34363
author:
type: added
...@@ -678,12 +678,4 @@ RSpec.describe Gitlab::UsageData do ...@@ -678,12 +678,4 @@ RSpec.describe Gitlab::UsageData do
end end
end 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 end
...@@ -32,6 +32,7 @@ module Gitlab ...@@ -32,6 +32,7 @@ module Gitlab
with_finished_at(:recording_ce_finished_at) do with_finished_at(:recording_ce_finished_at) do
license_usage_data license_usage_data
.merge(system_usage_data) .merge(system_usage_data)
.merge(system_usage_data_monthly)
.merge(features_usage_data) .merge(features_usage_data)
.merge(components_usage_data) .merge(components_usage_data)
.merge(cycle_analytics_usage_data) .merge(cycle_analytics_usage_data)
...@@ -164,9 +165,17 @@ module Gitlab ...@@ -164,9 +165,17 @@ module Gitlab
) )
} }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable Metrics/AbcSize # 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 def cycle_analytics_usage_data
Gitlab::CycleAnalytics::UsageData.new.to_json Gitlab::CycleAnalytics::UsageData.new.to_json
rescue ActiveRecord::StatementInvalid rescue ActiveRecord::StatementInvalid
......
...@@ -89,6 +89,11 @@ FactoryBot.define do ...@@ -89,6 +89,11 @@ FactoryBot.define do
create(:grafana_integration, project: projects[2], enabled: false) create(:grafana_integration, project: projects[2], enabled: false)
ProjectFeature.first.update_attribute('repository_access_level', 0) 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 end
end end
...@@ -110,6 +110,10 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -110,6 +110,10 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(UsageDataHelpers::COUNTS_KEYS - count_data.keys).to be_empty expect(UsageDataHelpers::COUNTS_KEYS - count_data.keys).to be_empty
end end
it 'gathers usage counts monthly hash' do
expect(subject[:counts_monthly]).to be_an(Hash)
end
it 'gathers projects data correctly' do it 'gathers projects data correctly' do
count_data = subject[:counts] count_data = subject[:counts]
...@@ -169,6 +173,8 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -169,6 +173,8 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:grafana_integrated_projects]).to eq(2) expect(count_data[:grafana_integrated_projects]).to eq(2)
expect(count_data[:clusters_applications_jupyter]).to eq(1) expect(count_data[:clusters_applications_jupyter]).to eq(1)
expect(count_data[:clusters_management_project]).to eq(1) expect(count_data[:clusters_management_project]).to eq(1)
expect(count_data[:snippets]).to eq(2)
end end
it 'gathers object store usage correctly' do it 'gathers object store usage correctly' do
...@@ -247,6 +253,18 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -247,6 +253,18 @@ describe Gitlab::UsageData, :aggregate_failures do
end end
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 describe '#usage_data_counters' do
subject { described_class.usage_data_counters } subject { described_class.usage_data_counters }
......
...@@ -233,4 +233,12 @@ module UsageDataHelpers ...@@ -233,4 +233,12 @@ module UsageDataHelpers
allow(client).to receive(:aggregate).and_return({}) allow(client).to receive(:aggregate).and_return({})
end 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 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