diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-19 18:08:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-19 18:08:39 +0300 |
commit | e1f8f12bbed19bea753d81d7586b30ea403733d5 (patch) | |
tree | 379d8f092fa416eb1830c2a8208380e438441b72 /spec/lib/gitlab | |
parent | 235dc61f473cb7f02a9453a59fb26d293e05b092 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/bitbucket_import/importer_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/bitbucket_server_import/importer_spec.rb | 49 | ||||
-rw-r--r-- | spec/lib/gitlab/import/metrics_spec.rb | 68 |
3 files changed, 87 insertions, 54 deletions
diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index 137d0fd4f9e..69dc10d1f55 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -226,8 +226,8 @@ describe Gitlab::BitbucketImport::Importer do it 'counts imported pull requests' do expect(Gitlab::Metrics).to receive(:counter).with( - :bitbucket_importer_imported_pull_requests, - 'The number of imported Bitbucket pull requests' + :bitbucket_importer_imported_merge_requests_total, + 'The number of imported merge (pull) requests' ) expect(counter).to receive(:increment) @@ -369,8 +369,8 @@ describe Gitlab::BitbucketImport::Importer do it 'counts imported issues' do expect(Gitlab::Metrics).to receive(:counter).with( - :bitbucket_importer_imported_issues, - 'The number of imported Bitbucket issues' + :bitbucket_importer_imported_issues_total, + 'The number of imported issues' ) expect(counter).to receive(:increment) @@ -389,23 +389,27 @@ describe Gitlab::BitbucketImport::Importer do allow(subject).to receive(:import_issues) allow(subject).to receive(:import_pull_requests) - allow(Gitlab::Metrics).to receive(:counter) { counter } - allow(Gitlab::Metrics).to receive(:histogram) { histogram } + allow(Gitlab::Metrics).to receive(:counter).and_return(counter) + allow(Gitlab::Metrics).to receive(:histogram).and_return(histogram) + allow(histogram).to receive(:observe) + allow(counter).to receive(:increment) end it 'counts and measures duration of imported projects' do expect(Gitlab::Metrics).to receive(:counter).with( - :bitbucket_importer_imported_projects, - 'The number of imported Bitbucket projects' + :bitbucket_importer_imported_projects_total, + 'The number of imported projects' ) expect(Gitlab::Metrics).to receive(:histogram).with( :bitbucket_importer_total_duration_seconds, - 'Total time spent importing Bitbucket projects, in seconds' + 'Total time spent importing projects, in seconds', + {}, + Gitlab::Import::Metrics::IMPORT_DURATION_BUCKETS ) expect(counter).to receive(:increment) - expect(histogram).to receive(:observe).with({ importer: described_class::IMPORTER }, anything) + expect(histogram).to receive(:observe).with({ importer: :bitbucket_importer }, anything) subject.execute end diff --git a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb index cf39d2cb753..570ad916fb2 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb @@ -5,7 +5,10 @@ require 'spec_helper' describe Gitlab::BitbucketServerImport::Importer do include ImportSpecHelper - let(:project) { create(:project, :repository, import_url: 'http://my-bitbucket') } + let(:import_url) { 'http://my-bitbucket' } + let(:user) { 'bitbucket' } + let(:password) { 'test' } + let(:project) { create(:project, :repository, import_url: import_url) } let(:now) { Time.now.utc.change(usec: 0) } let(:project_key) { 'TEST' } let(:repo_slug) { 'rouge' } @@ -16,7 +19,7 @@ describe Gitlab::BitbucketServerImport::Importer do before do data = project.create_or_update_import_data( data: { project_key: project_key, repo_slug: repo_slug }, - credentials: { base_uri: 'http://my-bitbucket', user: 'bitbucket', password: 'test' } + credentials: { base_uri: import_url, user: user, password: password } ) data.save project.save @@ -125,6 +128,48 @@ describe Gitlab::BitbucketServerImport::Importer do expect(note.updated_at).to eq(@pr_note.created_at) end + context 'metrics' do + let(:histogram) { double(:histogram) } + let(:counter) { double('counter', increment: true) } + + before do + allow(Gitlab::Metrics).to receive(:counter) { counter } + allow(Gitlab::Metrics).to receive(:histogram) { histogram } + allow(subject.client).to receive(:activities).and_return([@merge_event]) + end + + it 'counts and measures duration of imported projects' do + expect(Gitlab::Metrics).to receive(:counter).with( + :bitbucket_server_importer_imported_projects_total, + 'The number of imported projects' + ) + + expect(Gitlab::Metrics).to receive(:histogram).with( + :bitbucket_server_importer_total_duration_seconds, + 'Total time spent importing projects, in seconds', + {}, + Gitlab::Import::Metrics::IMPORT_DURATION_BUCKETS + ) + + expect(counter).to receive(:increment) + expect(histogram).to receive(:observe).with({ importer: :bitbucket_server_importer }, anything) + + subject.execute + end + + it 'counts imported pull requests' do + expect(Gitlab::Metrics).to receive(:counter).with( + :bitbucket_server_importer_imported_merge_requests_total, + 'The number of imported merge (pull) requests' + ) + + expect(counter).to receive(:increment) + allow(histogram).to receive(:observe).with({ importer: :bitbucket_server_importer }, anything) + + subject.execute + end + end + it 'imports threaded discussions' do reply = instance_double( BitbucketServer::Representation::PullRequestComment, diff --git a/spec/lib/gitlab/import/metrics_spec.rb b/spec/lib/gitlab/import/metrics_spec.rb index 0799d19fcef..89ea4db5c6e 100644 --- a/spec/lib/gitlab/import/metrics_spec.rb +++ b/spec/lib/gitlab/import/metrics_spec.rb @@ -3,54 +3,38 @@ require 'spec_helper' describe Gitlab::Import::Metrics do - let(:importer_stub) do - Class.new do - prepend Gitlab::Import::Metrics - - Gitlab::Import::Metrics.measure :execute, metrics: { - importer_counter: { - type: :counter, - description: 'description' - }, - importer_histogram: { - type: :histogram, - labels: { importer: 'importer' }, - description: 'description' - } - } - - def execute - true - end + let(:importer) { :test_importer } + let(:project) { create(:project) } + let(:histogram) { double(:histogram) } + let(:counter) { double(:counter) } + + subject { described_class.new(importer, project) } + + describe '#report_import_time' do + before do + allow(Gitlab::Metrics).to receive(:counter) { counter } + allow(Gitlab::Metrics).to receive(:histogram) { histogram } + allow(counter).to receive(:increment) + allow(counter).to receive(:observe) end - end - - subject { importer_stub.new.execute } - describe '#execute' do - let(:counter) { double(:counter) } - let(:histogram) { double(:histogram) } + it 'emits importer metrics' do + expect(Gitlab::Metrics).to receive(:counter).with( + :test_importer_imported_projects_total, + 'The number of imported projects' + ) - it 'increments counter metric' do - expect(Gitlab::Metrics) - .to receive(:counter) - .with(:importer_counter, 'description') - .and_return(counter) + 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(histogram).to receive(:observe).with({ importer: :test_importer }, anything) - subject - end - - it 'measures method duration and reports histogram metric' do - expect(Gitlab::Metrics) - .to receive(:histogram) - .with(:importer_histogram, 'description') - .and_return(histogram) - - expect(histogram).to receive(:observe).with({ importer: 'importer' }, anything) - - subject + subject.track_finished_import end end end |