Commit a7e49cba authored by Sean McGivern's avatar Sean McGivern

Merge branch 'feature/gb/pipeline-creation-duration-histogram' into 'master'

Add pipeline creation duration histogram metric

Closes #214784

See merge request gitlab-org/gitlab!30025
parents e6963bb4 1dbdf24a
......@@ -36,6 +36,7 @@ The following metrics are available:
| `gitlab_cache_misses_total` | Counter | 10.2 | Cache read miss | controller, action |
| `gitlab_cache_operation_duration_seconds` | Histogram | 10.2 | Cache access time | |
| `gitlab_cache_operations_total` | Counter | 12.2 | Cache operations by controller/action | controller, action, operation |
| `gitlab_ci_pipeline_creation_duration_seconds` | Histogram | 13.0 | Time in seconds it takes to create a CI/CD pipeline | |
| `job_waiter_started_total` | Counter | 12.9 | Number of batches of jobs started where a web request is waiting for the jobs to complete | worker |
| `job_waiter_timeouts_total` | Counter | 12.9 | Number of batches of jobs that timed out where a web request is waiting for the jobs to complete | worker |
| `gitlab_database_transaction_seconds` | Histogram | 12.1 | Time spent in database transactions, in seconds | |
......
......@@ -76,6 +76,21 @@ module Gitlab
def parent_pipeline
bridge&.parent_pipeline
end
def duration_histogram
strong_memoize(: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 observe_creation_duration(duration)
duration_histogram.observe({}, duration.seconds)
end
end
end
end
......
......@@ -10,6 +10,7 @@ module Gitlab
@command = command
@sequence = sequence
@completed = []
@start = Time.now
end
def build!
......@@ -24,6 +25,8 @@ module Gitlab
@pipeline.tap do
yield @pipeline, self if block_given?
@command.observe_creation_duration(Time.now - @start)
end
end
......
......@@ -5,11 +5,13 @@ require 'spec_helper'
describe Gitlab::Ci::Pipeline::Chain::Sequence do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:pipeline) { build_stubbed(:ci_pipeline) }
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new }
let(:first_step) { spy('first step') }
let(:second_step) { spy('second step') }
let(:sequence) { [first_step, second_step] }
let(:histogram) { spy('prometheus metric') }
subject do
described_class.new(pipeline, command, sequence)
......@@ -52,5 +54,13 @@ describe Gitlab::Ci::Pipeline::Chain::Sequence do
it 'returns a pipeline object' do
expect(subject.build!).to eq pipeline
end
it 'adds sequence duration to duration histogram' do
allow(command).to receive(:duration_histogram).and_return(histogram)
subject.build!
expect(histogram).to have_received(:observe)
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