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 ...@@ -88,10 +88,8 @@ module Gitlab
end end
def observe_step_duration(step_class, duration) def observe_step_duration(step_class, duration)
step = step_class.name.underscore.tr('/', '_') metrics.pipeline_creation_step_duration_histogram
.observe({ step: step_class.name }, duration.seconds)
metrics.pipeline_creation_step_duration_histogram(step)
.observe({}, duration.seconds)
end end
def observe_creation_duration(duration) def observe_creation_duration(duration)
......
...@@ -4,6 +4,8 @@ module Gitlab ...@@ -4,6 +4,8 @@ module Gitlab
module Ci module Ci
module Pipeline module Pipeline
class Metrics class Metrics
extend Gitlab::Utils::StrongMemoize
def self.pipeline_creation_duration_histogram def self.pipeline_creation_duration_histogram
name = :gitlab_ci_pipeline_creation_duration_seconds name = :gitlab_ci_pipeline_creation_duration_seconds
comment = 'Pipeline creation duration' comment = 'Pipeline creation duration'
...@@ -13,14 +15,16 @@ module Gitlab ...@@ -13,14 +15,16 @@ module Gitlab
::Gitlab::Metrics.histogram(name, comment, labels, buckets) ::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end end
def self.pipeline_creation_step_duration_histogram(step) def self.pipeline_creation_step_duration_histogram
strong_memoize(:pipeline_creation_step_histogram) do
name = :gitlab_ci_pipeline_creation_step_duration_seconds name = :gitlab_ci_pipeline_creation_step_duration_seconds
comment = 'Duration of each pipeline creation step' comment = 'Duration of each pipeline creation step'
labels = { step: step.remove('gitlab_ci_') } 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] 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
end
def self.pipeline_security_orchestration_policy_processing_duration_histogram def self.pipeline_security_orchestration_policy_processing_duration_histogram
name = :gitlab_ci_pipeline_security_orchestration_policy_processing_duration_seconds name = :gitlab_ci_pipeline_security_orchestration_policy_processing_duration_seconds
......
...@@ -347,10 +347,10 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do ...@@ -347,10 +347,10 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do
histogram = double(:histogram) histogram = double(:histogram)
duration = 1.hour duration = 1.hour
expect(histogram).to receive(:observe).with({}, duration.seconds)
expect(::Gitlab::Ci::Pipeline::Metrics).to receive(:pipeline_creation_step_duration_histogram) expect(::Gitlab::Ci::Pipeline::Metrics).to receive(:pipeline_creation_step_duration_histogram)
.with('gitlab_ci_pipeline_chain_build')
.and_return(histogram) .and_return(histogram)
expect(histogram).to receive(:observe)
.with({ step: 'Gitlab::Ci::Pipeline::Chain::Build' }, duration.seconds)
described_class.new.observe_step_duration( described_class.new.observe_step_duration(
Gitlab::Ci::Pipeline::Chain::Build, Gitlab::Ci::Pipeline::Chain::Build,
......
...@@ -64,18 +64,12 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Sequence do ...@@ -64,18 +64,12 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Sequence do
it 'adds step sequence duration to duration histogram' do it 'adds step sequence duration to duration histogram' do
expect(command.metrics) expect(command.metrics)
.to receive(:pipeline_creation_step_duration_histogram) .to receive(:pipeline_creation_step_duration_histogram)
.with('first_step') .twice
.ordered
.and_return(histogram)
expect(command.metrics)
.to receive(:pipeline_creation_step_duration_histogram)
.with('second_step')
.ordered
.and_return(histogram) .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! subject.build!
expect(histogram).to have_received(:observe).twice
end end
it 'records pipeline size by pipeline source in a histogram' do it 'records pipeline size by pipeline source in a histogram' do
......
...@@ -5,17 +5,17 @@ require 'spec_helper' ...@@ -5,17 +5,17 @@ require 'spec_helper'
RSpec.describe ::Gitlab::Ci::Pipeline::Metrics do RSpec.describe ::Gitlab::Ci::Pipeline::Metrics do
describe '.pipeline_creation_step_duration_histogram' do describe '.pipeline_creation_step_duration_histogram' do
it 'adds the step to the 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) expect(::Gitlab::Metrics).to receive(:histogram)
.with( .with(
:gitlab_ci_pipeline_creation_step_duration_seconds, :gitlab_ci_pipeline_creation_step_duration_seconds,
'Duration of each pipeline creation step', '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] [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 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