Commit 7ab46b1d authored by Avielle Wolfe's avatar Avielle Wolfe

Add an enabled FF for safety

An improperly configured histogram can create problems with Prometheus.
In order to make triage easier if there is a problem, this commit
introduces the `ci_pipeline_creation_step_duration_tracking` feature
flag.
parent 10616a22
---
name: ci_pipeline_creation_step_duration_tracking
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68485
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339486
milestone: '14.2'
type: development
group: group::pipeline execution
default_enabled: true
......@@ -88,8 +88,10 @@ module Gitlab
end
def observe_step_duration(step_class, duration)
metrics.pipeline_creation_step_duration_histogram
.observe({ step: step_class.name }, duration.seconds)
if Feature.enabled?(:ci_pipeline_creation_step_duration_tracking, default_enabled: :yaml)
metrics.pipeline_creation_step_duration_histogram
.observe({ step: step_class.name }, duration.seconds)
end
end
def observe_creation_duration(duration)
......
......@@ -343,19 +343,38 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do
end
describe '#observe_step_duration' do
it 'adds the duration to the step duration histogram' do
histogram = double(:histogram)
duration = 1.hour
expect(::Gitlab::Ci::Pipeline::Metrics).to receive(:pipeline_creation_step_duration_histogram)
.and_return(histogram)
expect(histogram).to receive(:observe)
.with({ step: 'Gitlab::Ci::Pipeline::Chain::Build' }, duration.seconds)
described_class.new.observe_step_duration(
Gitlab::Ci::Pipeline::Chain::Build,
duration
)
context 'when ci_pipeline_creation_step_duration_tracking is enabled' do
it 'adds the duration to the step duration histogram' do
histogram = double(:histogram)
duration = 1.hour
expect(::Gitlab::Ci::Pipeline::Metrics).to receive(:pipeline_creation_step_duration_histogram)
.and_return(histogram)
expect(histogram).to receive(:observe)
.with({ step: 'Gitlab::Ci::Pipeline::Chain::Build' }, duration.seconds)
described_class.new.observe_step_duration(
Gitlab::Ci::Pipeline::Chain::Build,
duration
)
end
end
context 'when ci_pipeline_creation_step_duration_tracking is disabled' do
before do
stub_feature_flags(ci_pipeline_creation_step_duration_tracking: false)
end
it 'does nothing' do
duration = 1.hour
expect(::Gitlab::Ci::Pipeline::Metrics).not_to receive(:pipeline_creation_step_duration_histogram)
described_class.new.observe_step_duration(
Gitlab::Ci::Pipeline::Chain::Build,
duration
)
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