diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
commit | 14bd84b61276ef29b97d23642d698de769bacfd2 (patch) | |
tree | f9eba90140c1bd874211dea17750a0d422c04080 /spec/lib/gitlab/import/metrics_spec.rb | |
parent | 891c388697b2db0d8ee0c8358a9bdbf6dc56d581 (diff) |
Add latest changes from gitlab-org/gitlab@15-10-stable-eev15.10.0-rc42
Diffstat (limited to 'spec/lib/gitlab/import/metrics_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import/metrics_spec.rb | 130 |
1 files changed, 111 insertions, 19 deletions
diff --git a/spec/lib/gitlab/import/metrics_spec.rb b/spec/lib/gitlab/import/metrics_spec.rb index 9b8b58d00f3..1a988af0dbd 100644 --- a/spec/lib/gitlab/import/metrics_spec.rb +++ b/spec/lib/gitlab/import/metrics_spec.rb @@ -11,7 +11,6 @@ RSpec.describe Gitlab::Import::Metrics, :aggregate_failures do subject { described_class.new(importer, project) } before do - allow(Gitlab::Metrics).to receive(:counter) { counter } allow(counter).to receive(:increment) allow(histogram).to receive(:observe) end @@ -42,6 +41,13 @@ RSpec.describe Gitlab::Import::Metrics, :aggregate_failures do context 'when project is not a github import' do it 'does not emit importer metrics' do expect(subject).not_to receive(:track_usage_event) + expect_no_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'failed' } + ) subject.track_failed_import end @@ -50,39 +56,81 @@ RSpec.describe Gitlab::Import::Metrics, :aggregate_failures do context 'when project is a github import' do before do project.import_type = 'github' + allow(project).to receive(:import_status).and_return('failed') end it 'emits importer metrics' do expect(subject).to receive(:track_usage_event).with(:github_import_project_failure, project.id) subject.track_failed_import + + expect_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'failed' } + ) end end end describe '#track_finished_import' do - before do - allow(Gitlab::Metrics).to receive(:histogram) { histogram } - end + context 'when project is a github import' do + before do + project.import_type = 'github' + allow(Gitlab::Metrics).to receive(:counter) { counter } + allow(Gitlab::Metrics).to receive(:histogram) { histogram } + allow(project).to receive(:beautified_import_status_name).and_return('completed') + end - it 'emits importer metrics' do - expect(Gitlab::Metrics).to receive(:counter).with( - :test_importer_imported_projects_total, - 'The number of imported projects' - ) + it 'emits importer metrics' do + expect(Gitlab::Metrics).to receive(:counter).with( + :test_importer_imported_projects_total, + 'The number of imported projects' + ) - expect(Gitlab::Metrics).to receive(:histogram).with( - :test_importer_total_duration_seconds, - 'Total time spent importing projects, in seconds', - {}, - described_class::IMPORT_DURATION_BUCKETS - ) + expect(Gitlab::Metrics).to receive(:histogram).with( + :test_importer_total_duration_seconds, + 'Total time spent importing projects, in seconds', + {}, + described_class::IMPORT_DURATION_BUCKETS + ) + + expect(counter).to receive(:increment) - expect(counter).to receive(:increment) + subject.track_finished_import - subject.track_finished_import + expect_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'completed' } + ) + + expect(subject.duration).not_to be_nil + end - expect(subject.duration).not_to be_nil + context 'when import is partially completed' do + before do + allow(project).to receive(:beautified_import_status_name).and_return('partially completed') + end + + it 'emits snowplow metrics' do + expect(subject).to receive(:track_usage_event).with(:github_import_project_partially_completed, project.id) + + subject.track_finished_import + + expect_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'partially completed' } + ) + end + end end context 'when project is not a github import' do @@ -91,7 +139,51 @@ RSpec.describe Gitlab::Import::Metrics, :aggregate_failures do subject.track_finished_import - expect(histogram).to have_received(:observe).with({ importer: :test_importer }, anything) + expect_no_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'completed' } + ) + end + end + end + + describe '#track_cancelled_import' do + context 'when project is not a github import' do + it 'does not emit importer metrics' do + expect(subject).not_to receive(:track_usage_event) + expect_no_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'canceled' } + ) + + subject.track_canceled_import + end + end + + context 'when project is a github import' do + before do + project.import_type = 'github' + allow(project).to receive(:import_status).and_return('canceled') + end + + it 'emits importer metrics' do + expect(subject).to receive(:track_usage_event).with(:github_import_project_cancelled, project.id) + + subject.track_canceled_import + + expect_snowplow_event( + category: :test_importer, + action: 'create', + label: 'github_import_project_state', + project: project, + extra: { import_type: 'github', state: 'canceled' } + ) end end end |