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: ...@@ -36,6 +36,7 @@ The following metrics are available:
| `gitlab_cache_misses_total` | Counter | 10.2 | Cache read miss | controller, action | | `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_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_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_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 | | `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 | | | `gitlab_database_transaction_seconds` | Histogram | 12.1 | Time spent in database transactions, in seconds | |
......
...@@ -76,6 +76,21 @@ module Gitlab ...@@ -76,6 +76,21 @@ module Gitlab
def parent_pipeline def parent_pipeline
bridge&.parent_pipeline bridge&.parent_pipeline
end 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 end
end end
......
...@@ -10,6 +10,7 @@ module Gitlab ...@@ -10,6 +10,7 @@ module Gitlab
@command = command @command = command
@sequence = sequence @sequence = sequence
@completed = [] @completed = []
@start = Time.now
end end
def build! def build!
...@@ -24,6 +25,8 @@ module Gitlab ...@@ -24,6 +25,8 @@ module Gitlab
@pipeline.tap do @pipeline.tap do
yield @pipeline, self if block_given? yield @pipeline, self if block_given?
@command.observe_creation_duration(Time.now - @start)
end end
end end
......
...@@ -5,11 +5,13 @@ require 'spec_helper' ...@@ -5,11 +5,13 @@ require 'spec_helper'
describe Gitlab::Ci::Pipeline::Chain::Sequence do describe Gitlab::Ci::Pipeline::Chain::Sequence do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:pipeline) { build_stubbed(:ci_pipeline) } let(:pipeline) { build_stubbed(:ci_pipeline) }
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new } let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new }
let(:first_step) { spy('first step') } let(:first_step) { spy('first step') }
let(:second_step) { spy('second step') } let(:second_step) { spy('second step') }
let(:sequence) { [first_step, second_step] } let(:sequence) { [first_step, second_step] }
let(:histogram) { spy('prometheus metric') }
subject do subject do
described_class.new(pipeline, command, sequence) described_class.new(pipeline, command, sequence)
...@@ -52,5 +54,13 @@ describe Gitlab::Ci::Pipeline::Chain::Sequence do ...@@ -52,5 +54,13 @@ describe Gitlab::Ci::Pipeline::Chain::Sequence do
it 'returns a pipeline object' do it 'returns a pipeline object' do
expect(subject.build!).to eq pipeline expect(subject.build!).to eq pipeline
end 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
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