Commit d6aace3f authored by Marius Bobin's avatar Marius Bobin

Instrument job inclusion in the pipeline logger

With this instrumentation we can observe how many builds a pipeline
could have and how long it takes to compute if they should be persisted.
parent 40080f73
......@@ -53,13 +53,18 @@ module Gitlab
end
def context
Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: root_variables)
Gitlab::Ci::Pipeline::Seed::Context.new(
pipeline,
root_variables: root_variables,
logger: logger
)
end
def root_variables
logger.instrument(:pipeline_seed_merge_variables) do
::Gitlab::Ci::Variables::Helpers.merge_variables(
@command.yaml_processor_result.root_variables, @command.workflow_rules_result.variables
@command.yaml_processor_result.root_variables,
@command.workflow_rules_result.variables
)
end
end
......
......@@ -58,7 +58,6 @@ module Gitlab
if pipeline.persisted?
attributes[:pipeline_builds_tags_count] = pipeline.tags_count
attributes[:pipeline_builds_distinct_tags_count] = pipeline.distinct_tags_count
attributes[:pipeline_id] = pipeline.id
end
......
......@@ -41,12 +41,14 @@ module Gitlab
def included?
strong_memoize(:inclusion) do
if @using_rules
rules_result.pass?
elsif @using_only || @using_except
all_of_only? && none_of_except?
else
true
logger.instrument(:pipeline_seed_build_inclusion) do
if @using_rules
rules_result.pass?
elsif @using_only || @using_except
all_of_only? && none_of_except?
else
true
end
end
end
end
......@@ -122,6 +124,8 @@ module Gitlab
private
delegate :logger, to: :@context
def all_of_only?
@only.all? { |spec| spec.satisfied_by?(@pipeline, evaluate_context) }
end
......
......@@ -5,11 +5,18 @@ module Gitlab
module Pipeline
module Seed
class Context
attr_reader :pipeline, :root_variables
attr_reader :pipeline, :root_variables, :logger
def initialize(pipeline, root_variables: [])
def initialize(pipeline, root_variables: [], logger: nil)
@pipeline = pipeline
@root_variables = root_variables
@logger = logger || build_logger
end
private
def build_logger
::Gitlab::Ci::Pipeline::Logger.new(project: pipeline.project)
end
end
end
......
......@@ -8,7 +8,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
let(:pipeline) { build(:ci_empty_pipeline, project: project, sha: head_sha) }
let(:root_variables) { [] }
let(:seed_context) { double(pipeline: pipeline, root_variables: root_variables) }
let(:seed_context) { Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: root_variables) }
let(:attributes) { { name: 'rspec', ref: 'master', scheduling_type: :stage, when: 'on_success' } }
let(:previous_stages) { [] }
let(:current_stage) { double(seeds_names: [attributes[:name]]) }
......
......@@ -6,7 +6,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Pipeline do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let(:seed_context) { double(pipeline: pipeline, root_variables: []) }
let(:seed_context) { Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: []) }
let(:stages_attributes) do
[
......
......@@ -6,7 +6,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Stage do
let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:previous_stages) { [] }
let(:seed_context) { double(pipeline: pipeline, root_variables: []) }
let(:seed_context) { Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: []) }
let(:attributes) do
{ name: 'test',
......
......@@ -36,6 +36,7 @@ RSpec.describe Ci::CreatePipelineService do
'pipeline_creation_duration_s' => counters,
'pipeline_size_count' => counters,
'pipeline_step_gitlab_ci_pipeline_chain_seed_duration_s' => counters,
'pipeline_seed_build_inclusion_duration_s' => counters,
'pipeline_builds_tags_count' => a_kind_of(Numeric),
'pipeline_builds_distinct_tags_count' => a_kind_of(Numeric)
}
......
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