Commit c7f4d8c3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'ci-add-tags-instrumentation-to-pipeline-logging' into 'master'

Log pipeline tags size

See merge request gitlab-org/gitlab!77112
parents 4a29e7c1 28a93879
......@@ -466,6 +466,18 @@ module Ci
statuses.count(:id)
end
def tags_count
if tag_counts_enabled?
ActsAsTaggableOn::Tagging.where(taggable: builds).count
end
end
def distinct_tags_count
if tag_counts_enabled?
ActsAsTaggableOn::Tagging.where(taggable: builds).count('distinct(tag_id)')
end
end
def stages_names
statuses.order(:stage_idx).distinct
.pluck(:stage, :stage_idx).map(&:first)
......@@ -1340,6 +1352,12 @@ module Ci
::Gitlab::Ci::PipelineObjectHierarchy
.new(self.class.unscoped.where(id: id), options: options)
end
def tag_counts_enabled?
strong_memoize(:tag_counts_enabled) do
::Feature.enabled?(:ci_pipeline_logger_tags_count, project, default_enabled: :yaml)
end
end
end
end
......
---
name: ci_pipeline_logger_tags_count
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77112
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/348967
milestone: '14.7'
type: development
group: group::pipeline execution
default_enabled: false
......@@ -50,11 +50,21 @@ module Gitlab
class: self.class.name.to_s,
pipeline_creation_caller: caller,
project_id: project.id,
pipeline_id: pipeline.id,
pipeline_persisted: pipeline.persisted?,
pipeline_source: pipeline.source,
pipeline_creation_service_duration_s: age
}.stringify_keys.merge(observations_hash)
}
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
attributes.compact!
attributes.stringify_keys!
attributes.merge!(observations_hash)
destination.info(attributes)
end
......
......@@ -4677,4 +4677,32 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
let!(:model) { create(:ci_pipeline, user: create(:user)) }
let!(:parent) { model.user }
end
describe 'tags count' do
let_it_be_with_refind(:pipeline) do
create(:ci_empty_pipeline, project: project)
end
it { expect(pipeline.tags_count).to eq(0) }
it { expect(pipeline.distinct_tags_count).to eq(0) }
context 'with builds' do
before do
create(:ci_build, pipeline: pipeline, tag_list: %w[a b])
create(:ci_build, pipeline: pipeline, tag_list: %w[b c])
end
it { expect(pipeline.tags_count).to eq(4) }
it { expect(pipeline.distinct_tags_count).to eq(3) }
end
context 'with the FF disabled' do
before do
stub_feature_flags(ci_pipeline_logger_tags_count: false)
end
it { expect(pipeline.tags_count).to be_nil }
it { expect(pipeline.distinct_tags_count).to be_nil }
end
end
end
......@@ -35,7 +35,9 @@ RSpec.describe Ci::CreatePipelineService do
'pipeline_creation_service_duration_s' => a_kind_of(Numeric),
'pipeline_creation_duration_s' => counters,
'pipeline_size_count' => counters,
'pipeline_step_gitlab_ci_pipeline_chain_seed_duration_s' => counters
'pipeline_step_gitlab_ci_pipeline_chain_seed_duration_s' => counters,
'pipeline_builds_tags_count' => a_kind_of(Numeric),
'pipeline_builds_distinct_tags_count' => a_kind_of(Numeric)
}
end
......@@ -81,7 +83,6 @@ RSpec.describe Ci::CreatePipelineService do
{
'pipeline_creation_caller' => 'Ci::CreatePipelineService',
'pipeline_source' => 'push',
'pipeline_id' => nil,
'pipeline_persisted' => false,
'project_id' => project.id,
'pipeline_creation_service_duration_s' => 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