diff options
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 6 | ||||
-rw-r--r-- | changelogs/unreleased/zj-prom-pipeline-count.yml | 4 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index bffec216819..769749c9925 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -57,6 +57,8 @@ module Ci cancel_pending_pipelines if project.auto_cancel_pending_pipelines? + pipeline_created_counter.increment(source: source) + pipeline.tap(&:process!) end @@ -131,5 +133,9 @@ module Ci pipeline.drop if save pipeline end + + def pipeline_created_counter + @pipeline_created_counter ||= Gitlab::Metrics.counter(:pipelines_created_count, "Pipelines created count") + end end end diff --git a/changelogs/unreleased/zj-prom-pipeline-count.yml b/changelogs/unreleased/zj-prom-pipeline-count.yml new file mode 100644 index 00000000000..191e4f2f949 --- /dev/null +++ b/changelogs/unreleased/zj-prom-pipeline-count.yml @@ -0,0 +1,4 @@ +--- +title: Add prometheus metrics on pipeline creation +merge_request: +author: diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index e9c2b865b47..77c07b71c68 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -38,6 +38,14 @@ describe Ci::CreatePipelineService, :services do expect(pipeline.builds.first).to be_kind_of(Ci::Build) end + it 'increments the prometheus counter' do + expect(Gitlab::Metrics).to receive(:counter) + .with(:pipelines_created_count, "Pipelines created count") + .and_call_original + + pipeline + end + context 'when merge requests already exist for this source branch' do it 'updates head pipeline of each merge request' do merge_request_1 = create(:merge_request, source_branch: 'master', target_branch: "branch_1", source_project: project) |