Commit 1ea39334 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'backstage/gb/pipeline-processing-metrics' into 'master'

Add pipeline processing events counter metric

See merge request gitlab-org/gitlab!36694
parents 5666044a dd47878e
...@@ -9,6 +9,8 @@ module Ci ...@@ -9,6 +9,8 @@ module Ci
end end
def execute(trigger_build_ids = nil, initial_process: false) def execute(trigger_build_ids = nil, initial_process: false)
increment_processing_counter
update_retried update_retried
if ::Gitlab::Ci::Features.atomic_processing?(pipeline.project) if ::Gitlab::Ci::Features.atomic_processing?(pipeline.project)
...@@ -22,6 +24,10 @@ module Ci ...@@ -22,6 +24,10 @@ module Ci
end end
end end
def metrics
@metrics ||= ::Gitlab::Ci::Pipeline::Metrics.new
end
private private
# This method is for compatibility and data consistency and should be removed with 9.3 version of GitLab # This method is for compatibility and data consistency and should be removed with 9.3 version of GitLab
...@@ -43,5 +49,9 @@ module Ci ...@@ -43,5 +49,9 @@ module Ci
.update_all(retried: true) if latest_statuses.any? .update_all(retried: true) if latest_statuses.any?
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def increment_processing_counter
metrics.pipeline_processing_events_counter.increment
end
end end
end end
...@@ -78,7 +78,7 @@ module Gitlab ...@@ -78,7 +78,7 @@ module Gitlab
end end
def metrics def metrics
@metrics ||= Chain::Metrics.new @metrics ||= ::Gitlab::Ci::Pipeline::Metrics.new
end end
def observe_creation_duration(duration) def observe_creation_duration(duration)
......
# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Chain
class Metrics
include Gitlab::Utils::StrongMemoize
def pipeline_creation_duration_histogram
strong_memoize(:pipeline_creation_duration_histogram) do
name = :gitlab_ci_pipeline_creation_duration_seconds
comment = 'Pipeline creation duration'
labels = {}
buckets = [0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0, 20.0, 50.0, 240.0]
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
def pipeline_size_histogram
strong_memoize(:pipeline_size_histogram) do
name = :gitlab_ci_pipeline_size_builds
comment = 'Pipeline size'
labels = { source: nil }
buckets = [0, 1, 5, 10, 20, 50, 100, 200, 500, 1000]
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
end
end
end
end
end
# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
class Metrics
include Gitlab::Utils::StrongMemoize
def pipeline_creation_duration_histogram
strong_memoize(:pipeline_creation_duration_histogram) do
name = :gitlab_ci_pipeline_creation_duration_seconds
comment = 'Pipeline creation duration'
labels = {}
buckets = [0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0, 20.0, 50.0, 240.0]
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
def pipeline_size_histogram
strong_memoize(:pipeline_size_histogram) do
name = :gitlab_ci_pipeline_size_builds
comment = 'Pipeline size'
labels = { source: nil }
buckets = [0, 1, 5, 10, 20, 50, 100, 200, 500, 1000]
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
def pipeline_processing_events_counter
strong_memoize(:pipeline_processing_events_counter) do
name = :gitlab_ci_pipeline_processing_events_total
comment = 'Total amount of pipeline processing events'
Gitlab::Metrics.counter(name, comment)
end
end
end
end
end
end
...@@ -80,7 +80,7 @@ RSpec.describe Ci::CreatePipelineService do ...@@ -80,7 +80,7 @@ RSpec.describe Ci::CreatePipelineService do
it 'records pipeline size in a prometheus histogram' do it 'records pipeline size in a prometheus histogram' do
histogram = spy('pipeline size histogram') histogram = spy('pipeline size histogram')
allow(Gitlab::Ci::Pipeline::Chain::Metrics) allow(Gitlab::Ci::Pipeline::Metrics)
.to receive(:new).and_return(histogram) .to receive(:new).and_return(histogram)
execute_service execute_service
......
...@@ -10,38 +10,52 @@ RSpec.describe Ci::ProcessPipelineService do ...@@ -10,38 +10,52 @@ RSpec.describe Ci::ProcessPipelineService do
create(:ci_empty_pipeline, ref: 'master', project: project) create(:ci_empty_pipeline, ref: 'master', project: project)
end end
subject { described_class.new(pipeline) }
before do before do
stub_ci_pipeline_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
stub_not_protect_default_branch stub_not_protect_default_branch
project.add_developer(user) project.add_developer(user)
end end
context 'updates a list of retried builds' do describe 'processing events counter' do
subject { described_class.retried.order(:id) } let(:metrics) { double('pipeline metrics') }
let(:counter) { double('events counter') }
before do
allow(subject)
.to receive(:metrics).and_return(metrics)
allow(metrics)
.to receive(:pipeline_processing_events_counter)
.and_return(counter)
end
it 'increments processing events counter' do
expect(counter).to receive(:increment)
subject.execute
end
end
describe 'updating a list of retried builds' do
let!(:build_retried) { create_build('build') } let!(:build_retried) { create_build('build') }
let!(:build) { create_build('build') } let!(:build) { create_build('build') }
let!(:test) { create_build('test') } let!(:test) { create_build('test') }
it 'returns unique statuses' do it 'returns unique statuses' do
process_pipeline subject.execute
expect(all_builds.latest).to contain_exactly(build, test) expect(all_builds.latest).to contain_exactly(build, test)
expect(all_builds.retried).to contain_exactly(build_retried) expect(all_builds.retried).to contain_exactly(build_retried)
end end
end
def process_pipeline
described_class.new(pipeline).execute
end
def create_build(name, **opts) def create_build(name, **opts)
create(:ci_build, :created, pipeline: pipeline, name: name, **opts) create(:ci_build, :created, pipeline: pipeline, name: name, **opts)
end end
def all_builds def all_builds
pipeline.builds.order(:stage_idx, :id) pipeline.builds.order(:stage_idx, :id)
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