Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/lib/gitlab/usage_data_counters
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
-rw-r--r--spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb24
-rw-r--r--spec/lib/gitlab/usage_data_counters/code_review_events_spec.rb23
-rw-r--r--spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb12
-rw-r--r--spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb52
-rw-r--r--spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb102
-rw-r--r--spec/lib/gitlab/usage_data_counters/package_event_counter_spec.rb2
-rw-r--r--spec/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter_spec.rb20
7 files changed, 206 insertions, 29 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb b/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb
index 58f974fbe12..9aba86cdaf2 100644
--- a/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb
@@ -23,6 +23,22 @@ RSpec.describe 'aggregated metrics' do
end
end
+ RSpec::Matchers.define :have_known_time_frame do
+ allowed_time_frames = [
+ Gitlab::Utils::UsageData::ALL_TIME_TIME_FRAME_NAME,
+ Gitlab::Utils::UsageData::TWENTY_EIGHT_DAYS_TIME_FRAME_NAME,
+ Gitlab::Utils::UsageData::SEVEN_DAYS_TIME_FRAME_NAME
+ ]
+
+ match do |aggregate|
+ (aggregate[:time_frame] - allowed_time_frames).empty?
+ end
+
+ failure_message do |aggregate|
+ "Aggregate with name: `#{aggregate[:name]}` uses not allowed time_frame`#{aggregate[:time_frame] - allowed_time_frames}`"
+ end
+ end
+
let_it_be(:known_events) do
Gitlab::UsageDataCounters::HLLRedisCounter.known_events
end
@@ -38,10 +54,18 @@ RSpec.describe 'aggregated metrics' do
expect(aggregated_metrics).to all has_known_source
end
+ it 'all aggregated metrics has known source' do
+ expect(aggregated_metrics).to all have_known_time_frame
+ end
+
aggregated_metrics&.select { |agg| agg[:source] == Gitlab::Usage::Metrics::Aggregates::REDIS_SOURCE }&.each do |aggregate|
context "for #{aggregate[:name]} aggregate of #{aggregate[:events].join(' ')}" do
let_it_be(:events_records) { known_events.select { |event| aggregate[:events].include?(event[:name]) } }
+ it "does not include 'all' time frame for Redis sourced aggregate" do
+ expect(aggregate[:time_frame]).not_to include(Gitlab::Utils::UsageData::ALL_TIME_TIME_FRAME_NAME)
+ end
+
it "only refers to known events" do
expect(aggregate[:events]).to all be_known_event
end
diff --git a/spec/lib/gitlab/usage_data_counters/code_review_events_spec.rb b/spec/lib/gitlab/usage_data_counters/code_review_events_spec.rb
new file mode 100644
index 00000000000..664e7938a7e
--- /dev/null
+++ b/spec/lib/gitlab/usage_data_counters/code_review_events_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+# If this spec fails, we need to add the new code review event to the correct aggregated metric
+RSpec.describe 'Code review events' do
+ it 'the aggregated metrics contain all the code review metrics' do
+ path = Rails.root.join('lib/gitlab/usage_data_counters/aggregated_metrics/code_review.yml')
+ aggregated_events = YAML.safe_load(File.read(path), aliases: true)&.map(&:with_indifferent_access)
+
+ code_review_aggregated_events = aggregated_events
+ .map { |event| event['events'] }
+ .flatten
+ .uniq
+
+ code_review_events = Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category("code_review")
+
+ exceptions = %w[i_code_review_mr_diffs i_code_review_mr_single_file_diffs]
+ code_review_aggregated_events += exceptions
+
+ expect(code_review_events - code_review_aggregated_events).to be_empty
+ end
+end
diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
index b4894ec049f..d12dcdae955 100644
--- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
@@ -42,7 +42,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
'terraform',
'ci_templates',
'quickactions',
- 'pipeline_authoring'
+ 'pipeline_authoring',
+ 'epics_usage'
)
end
end
@@ -150,10 +151,17 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
expect { described_class.track_event(different_aggregation, values: entity1, time: Date.current) }.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownAggregation)
end
- it 'raise error if metrics of unknown aggregation' do
+ it 'raise error if metrics of unknown event' do
expect { described_class.track_event('unknown', values: entity1, time: Date.current) }.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent)
end
+ it 'reports an error if Feature.enabled raise an error' do
+ expect(Feature).to receive(:enabled?).and_raise(StandardError.new)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
+
+ described_class.track_event(:g_analytics_contribution, values: entity1, time: Date.current)
+ end
+
context 'for weekly events' do
it 'sets the keys in Redis to expire automatically after the given expiry time' do
described_class.track_event("g_analytics_contribution", values: entity1)
diff --git a/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb
index bf43f7552e6..f8f6494b92e 100644
--- a/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
let(:time) { Time.zone.now }
context 'for Issue title edit actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_TITLE_CHANGED }
def track_action(params)
@@ -19,7 +19,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue description edit actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_DESCRIPTION_CHANGED }
def track_action(params)
@@ -29,7 +29,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue assignee edit actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_ASSIGNEE_CHANGED }
def track_action(params)
@@ -39,7 +39,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue make confidential actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_MADE_CONFIDENTIAL }
def track_action(params)
@@ -49,7 +49,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue make visible actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_MADE_VISIBLE }
def track_action(params)
@@ -59,7 +59,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue created actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_CREATED }
def track_action(params)
@@ -69,7 +69,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue closed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_CLOSED }
def track_action(params)
@@ -79,7 +79,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue reopened actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_REOPENED }
def track_action(params)
@@ -89,7 +89,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue label changed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_LABEL_CHANGED }
def track_action(params)
@@ -99,7 +99,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue cross-referenced actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_CROSS_REFERENCED }
def track_action(params)
@@ -109,7 +109,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue moved actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_MOVED }
def track_action(params)
@@ -119,7 +119,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue cloned actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_CLONED }
def track_action(params)
@@ -129,7 +129,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue relate actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_RELATED }
def track_action(params)
@@ -139,7 +139,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue unrelate actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_UNRELATED }
def track_action(params)
@@ -149,7 +149,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue marked as duplicate actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_MARKED_AS_DUPLICATE }
def track_action(params)
@@ -159,7 +159,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue locked actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_LOCKED }
def track_action(params)
@@ -169,7 +169,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue unlocked actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_UNLOCKED }
def track_action(params)
@@ -179,7 +179,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue designs added actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_DESIGNS_ADDED }
def track_action(params)
@@ -189,7 +189,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue designs modified actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_DESIGNS_MODIFIED }
def track_action(params)
@@ -199,7 +199,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue designs removed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_DESIGNS_REMOVED }
def track_action(params)
@@ -209,7 +209,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue due date changed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_DUE_DATE_CHANGED }
def track_action(params)
@@ -219,7 +219,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue time estimate changed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_TIME_ESTIMATE_CHANGED }
def track_action(params)
@@ -229,7 +229,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue time spent changed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_TIME_SPENT_CHANGED }
def track_action(params)
@@ -239,7 +239,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue comment added actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_COMMENT_ADDED }
def track_action(params)
@@ -249,7 +249,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue comment edited actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_COMMENT_EDITED }
def track_action(params)
@@ -259,7 +259,7 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
context 'for Issue comment removed actions' do
- it_behaves_like 'a tracked issue edit event' do
+ it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_COMMENT_REMOVED }
def track_action(params)
diff --git a/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb
index a604de4a61f..6486a5a22ba 100644
--- a/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb
@@ -21,6 +21,14 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
end
end
+ shared_examples_for 'not tracked merge request unique event' do
+ specify do
+ expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
+
+ subject
+ end
+ end
+
describe '.track_mr_diffs_action' do
subject { described_class.track_mr_diffs_action(merge_request: merge_request) }
@@ -284,4 +292,98 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_CREATE_FROM_ISSUE_ACTION }
end
end
+
+ describe '.track_discussion_locked_action' do
+ subject { described_class.track_discussion_locked_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_DISCUSSION_LOCKED_ACTION }
+ end
+ end
+
+ describe '.track_discussion_unlocked_action' do
+ subject { described_class.track_discussion_unlocked_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_DISCUSSION_UNLOCKED_ACTION }
+ end
+ end
+
+ describe '.track_time_estimate_changed_action' do
+ subject { described_class.track_time_estimate_changed_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_TIME_ESTIMATE_CHANGED_ACTION }
+ end
+ end
+
+ describe '.track_time_spent_changed_action' do
+ subject { described_class.track_time_spent_changed_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_TIME_SPENT_CHANGED_ACTION }
+ end
+ end
+
+ describe '.track_assignees_changed_action' do
+ subject { described_class.track_assignees_changed_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_ASSIGNEES_CHANGED_ACTION }
+ end
+ end
+
+ describe '.track_reviewers_changed_action' do
+ subject { described_class.track_reviewers_changed_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_REVIEWERS_CHANGED_ACTION }
+ end
+ end
+
+ describe '.track_mr_including_ci_config' do
+ subject { described_class.track_mr_including_ci_config(user: user, merge_request: merge_request) }
+
+ context 'when merge request includes a ci config change' do
+ before do
+ allow(merge_request).to receive(:diff_stats).and_return([double(path: 'abc.txt'), double(path: '.gitlab-ci.yml')])
+ end
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_INCLUDING_CI_CONFIG_ACTION }
+ end
+
+ context 'when FF usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile is disabled' do
+ before do
+ stub_feature_flags(usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile: false)
+ end
+
+ it_behaves_like 'not tracked merge request unique event'
+ end
+ end
+
+ context 'when merge request does not include any ci config change' do
+ before do
+ allow(merge_request).to receive(:diff_stats).and_return([double(path: 'abc.txt'), double(path: 'abc.xyz')])
+ end
+
+ it_behaves_like 'not tracked merge request unique event'
+ end
+ end
+
+ describe '.track_milestone_changed_action' do
+ subject { described_class.track_milestone_changed_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_MILESTONE_CHANGED_ACTION }
+ end
+ end
+
+ describe '.track_labels_changed_action' do
+ subject { described_class.track_labels_changed_action(user: user) }
+
+ it_behaves_like 'a tracked merge request unique event' do
+ let(:action) { described_class::MR_LABELS_CHANGED_ACTION }
+ end
+ end
end
diff --git a/spec/lib/gitlab/usage_data_counters/package_event_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/package_event_counter_spec.rb
index 7b5efb11034..1be2a83f98f 100644
--- a/spec/lib/gitlab/usage_data_counters/package_event_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/package_event_counter_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Gitlab::UsageDataCounters::PackageEventCounter, :clean_gitlab_red
end
it 'includes the right events' do
- expect(described_class::KNOWN_EVENTS.size).to eq 45
+ expect(described_class::KNOWN_EVENTS.size).to eq 48
end
described_class::KNOWN_EVENTS.each do |event|
diff --git a/spec/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter_spec.rb
index d4c423f57fe..2df0f331f73 100644
--- a/spec/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter_spec.rb
@@ -160,4 +160,24 @@ RSpec.describe Gitlab::UsageDataCounters::QuickActionActivityUniqueCounter, :cle
end
end
end
+
+ context 'tracking invite_email' do
+ let(:quickaction_name) { 'invite_email' }
+
+ context 'single email' do
+ let(:args) { 'someone@gitlab.com' }
+
+ it_behaves_like 'a tracked quick action unique event' do
+ let(:action) { 'i_quickactions_invite_email_single' }
+ end
+ end
+
+ context 'multiple emails' do
+ let(:args) { 'someone@gitlab.com another@gitlab.com' }
+
+ it_behaves_like 'a tracked quick action unique event' do
+ let(:action) { 'i_quickactions_invite_email_multiple' }
+ end
+ end
+ end
end