Commit 10616a22 authored by Avielle Wolfe's avatar Avielle Wolfe

Fix step histogram label usage

The labels need to be passed to `#observe`
parent 34810d37
......@@ -88,10 +88,8 @@ module Gitlab
end
def observe_step_duration(step_class, duration)
step = step_class.name.underscore.tr('/', '_')
metrics.pipeline_creation_step_duration_histogram(step)
.observe({}, duration.seconds)
metrics.pipeline_creation_step_duration_histogram
.observe({ step: step_class.name }, duration.seconds)
end
def observe_creation_duration(duration)
......
......@@ -4,6 +4,8 @@ module Gitlab
module Ci
module Pipeline
class Metrics
extend Gitlab::Utils::StrongMemoize
def self.pipeline_creation_duration_histogram
name = :gitlab_ci_pipeline_creation_duration_seconds
comment = 'Pipeline creation duration'
......@@ -13,13 +15,15 @@ module Gitlab
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
def self.pipeline_creation_step_duration_histogram(step)
name = :gitlab_ci_pipeline_creation_step_duration_seconds
comment = 'Duration of each pipeline creation step'
labels = { step: step.remove('gitlab_ci_') }
buckets = [0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 15.0, 20.0, 50.0, 240.0]
def self.pipeline_creation_step_duration_histogram
strong_memoize(:pipeline_creation_step_histogram) do
name = :gitlab_ci_pipeline_creation_step_duration_seconds
comment = 'Duration of each pipeline creation step'
labels = { step: nil }
buckets = [0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 15.0, 20.0, 50.0, 240.0]
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
end
def self.pipeline_security_orchestration_policy_processing_duration_histogram
......
......@@ -347,10 +347,10 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do
histogram = double(:histogram)
duration = 1.hour
expect(histogram).to receive(:observe).with({}, duration.seconds)
expect(::Gitlab::Ci::Pipeline::Metrics).to receive(:pipeline_creation_step_duration_histogram)
.with('gitlab_ci_pipeline_chain_build')
.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,
......
......@@ -64,18 +64,12 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Sequence do
it 'adds step sequence duration to duration histogram' do
expect(command.metrics)
.to receive(:pipeline_creation_step_duration_histogram)
.with('first_step')
.ordered
.and_return(histogram)
expect(command.metrics)
.to receive(:pipeline_creation_step_duration_histogram)
.with('second_step')
.ordered
.twice
.and_return(histogram)
expect(histogram).to receive(:observe).with({ step: 'FirstStep' }, any_args).ordered
expect(histogram).to receive(:observe).with({ step: 'SecondStep' }, any_args).ordered
subject.build!
expect(histogram).to have_received(:observe).twice
end
it 'records pipeline size by pipeline source in a histogram' do
......
......@@ -5,17 +5,17 @@ require 'spec_helper'
RSpec.describe ::Gitlab::Ci::Pipeline::Metrics do
describe '.pipeline_creation_step_duration_histogram' do
it 'adds the step to the step duration histogram' do
step = 'gitlab_ci_pipeline_chain_build'
described_class.clear_memoization(:pipeline_creation_step_histogram)
expect(::Gitlab::Metrics).to receive(:histogram)
.with(
:gitlab_ci_pipeline_creation_step_duration_seconds,
'Duration of each pipeline creation step',
{ step: 'pipeline_chain_build' },
{ step: nil },
[0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 15.0, 20.0, 50.0, 240.0]
)
described_class.pipeline_creation_step_duration_histogram(step)
described_class.pipeline_creation_step_duration_histogram
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