diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-23 18:11:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-23 18:11:20 +0300 |
commit | 273ee970db58a0488d7b1de5ad7c62bfd21572e4 (patch) | |
tree | d8865c447cd60713575a022d6ef2760dc1bf1795 /lib/gitlab/ci/pipeline | |
parent | 026ed016d068a58b2e09422135b5b78bd11f2a2b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/ci/pipeline')
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/create.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/logger.rb | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/create.rb b/lib/gitlab/ci/pipeline/chain/create.rb index 15b0ff3c04d..a2fac144d45 100644 --- a/lib/gitlab/ci/pipeline/chain/create.rb +++ b/lib/gitlab/ci/pipeline/chain/create.rb @@ -9,7 +9,7 @@ module Gitlab include Gitlab::Utils::StrongMemoize def perform! - logger.instrument(:pipeline_save) do + logger.instrument_with_sql(:pipeline_save) do BulkInsertableAssociations.with_bulk_insert do tags = extract_tag_list_by_status diff --git a/lib/gitlab/ci/pipeline/logger.rb b/lib/gitlab/ci/pipeline/logger.rb index 892538f29af..50c8ec6b96a 100644 --- a/lib/gitlab/ci/pipeline/logger.rb +++ b/lib/gitlab/ci/pipeline/logger.rb @@ -37,6 +37,18 @@ module Gitlab result end + def instrument_with_sql(operation, &block) + return instrument(operation, &block) unless sql_logging_enabled? + + op_start_db_counters = current_db_counter_payload + + result = instrument(operation, &block) + + observe_sql_counters(operation, op_start_db_counters, current_db_counter_payload) + + result + end + def observe(operation, value) return unless enabled? @@ -106,6 +118,25 @@ module Gitlab def observations @observations ||= Hash.new { |hash, key| hash[key] = [] } end + + def observe_sql_counters(operation, start_db_counters, end_db_counters) + end_db_counters.each do |key, value| + result = value - start_db_counters.fetch(key, 0) + next if result == 0 + + observe("#{operation}_#{key}", result) + end + end + + def current_db_counter_payload + ::Gitlab::Metrics::Subscribers::ActiveRecord.db_counter_payload + end + + def sql_logging_enabled? + strong_memoize(:sql_logging_enabled) do + ::Feature.enabled?(:ci_pipeline_logger_sql_count, project, default_enabled: :yaml) + end + end end end end |