diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:07:55 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:07:55 +0000 |
commit | 603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc (patch) | |
tree | 907f5b8ee1b6f5aad396e95e3327a08400b9e8ea /lib | |
parent | 120f4aaedc8fe830a3f572491d240d8ee6addefb (diff) | |
download | gitlab-ce-603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/entry/reports.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/grape_logging/loggers/perf_logger.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/instrumentation/redis.rb | 70 | ||||
-rw-r--r-- | lib/gitlab/instrumentation_helper.rb | 9 | ||||
-rw-r--r-- | lib/peek/views/detailed_view.rb | 2 | ||||
-rw-r--r-- | lib/peek/views/redis_detailed.rb | 38 |
6 files changed, 85 insertions, 64 deletions
diff --git a/lib/gitlab/ci/config/entry/reports.rb b/lib/gitlab/ci/config/entry/reports.rb index 40d37f3601a..8ccee3b5b2b 100644 --- a/lib/gitlab/ci/config/entry/reports.rb +++ b/lib/gitlab/ci/config/entry/reports.rb @@ -14,7 +14,7 @@ module Gitlab ALLOWED_KEYS = %i[junit codequality sast dependency_scanning container_scanning dast performance license_management license_scanning metrics lsif - dotenv cobertura].freeze + dotenv cobertura terraform].freeze attributes ALLOWED_KEYS @@ -36,6 +36,7 @@ module Gitlab validates :lsif, array_of_strings_or_string: true validates :dotenv, array_of_strings_or_string: true validates :cobertura, array_of_strings_or_string: true + validates :terraform, array_of_strings_or_string: true end end diff --git a/lib/gitlab/grape_logging/loggers/perf_logger.rb b/lib/gitlab/grape_logging/loggers/perf_logger.rb index 7e86b35a215..ca4a702cb94 100644 --- a/lib/gitlab/grape_logging/loggers/perf_logger.rb +++ b/lib/gitlab/grape_logging/loggers/perf_logger.rb @@ -5,30 +5,11 @@ module Gitlab module GrapeLogging module Loggers class PerfLogger < ::GrapeLogging::Loggers::Base - def parameters(_, _) - gitaly_data.merge(rugged_data) - end - - def gitaly_data - gitaly_calls = Gitlab::GitalyClient.get_request_count + include ::Gitlab::InstrumentationHelper - return {} if gitaly_calls.zero? - - { - gitaly_calls: Gitlab::GitalyClient.get_request_count, - gitaly_duration: Gitlab::GitalyClient.query_time_ms - } - end - - def rugged_data - rugged_calls = Gitlab::RuggedInstrumentation.query_count - - return {} if rugged_calls.zero? - - { - rugged_calls: rugged_calls, - rugged_duration_ms: Gitlab::RuggedInstrumentation.query_time_ms - } + def parameters(_, _) + payload = {} + payload.tap { add_instrumentation_data(payload) } end end end diff --git a/lib/gitlab/instrumentation/redis.rb b/lib/gitlab/instrumentation/redis.rb new file mode 100644 index 00000000000..f9a6fdc05aa --- /dev/null +++ b/lib/gitlab/instrumentation/redis.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'redis' + +module Gitlab + module Instrumentation + module RedisInterceptor + def call(*args, &block) + start = Time.now + super(*args, &block) + ensure + duration = (Time.now - start) + + if ::RequestStore.active? + ::Gitlab::Instrumentation::Redis.increment_request_count + ::Gitlab::Instrumentation::Redis.add_duration(duration) + ::Gitlab::Instrumentation::Redis.add_call_details(duration, args) + end + end + end + + class Redis + REDIS_REQUEST_COUNT = :redis_request_count + REDIS_CALL_DURATION = :redis_call_duration + REDIS_CALL_DETAILS = :redis_call_details + + def self.get_request_count + ::RequestStore[REDIS_REQUEST_COUNT] || 0 + end + + def self.increment_request_count + ::RequestStore[REDIS_REQUEST_COUNT] ||= 0 + ::RequestStore[REDIS_REQUEST_COUNT] += 1 + end + + def self.detail_store + ::RequestStore[REDIS_CALL_DETAILS] ||= [] + end + + def self.query_time_ms + (self.query_time * 1000).round(2) + end + + def self.query_time + ::RequestStore[REDIS_CALL_DURATION] || 0 + end + + def self.add_duration(duration) + total_time = query_time + duration + ::RequestStore[REDIS_CALL_DURATION] = total_time + end + + def self.add_call_details(duration, args) + return unless Gitlab::PerformanceBar.enabled_for_request? + # redis-rb passes an array (e.g. [:get, key]) + return unless args.length == 1 + + detail_store << { + cmd: args.first, + duration: duration, + backtrace: ::Gitlab::BacktraceCleaner.clean_backtrace(caller) + } + end + end + end +end + +class ::Redis::Client + prepend ::Gitlab::Instrumentation::RedisInterceptor +end diff --git a/lib/gitlab/instrumentation_helper.rb b/lib/gitlab/instrumentation_helper.rb index edaa9c645b4..5d4e6a7bdef 100644 --- a/lib/gitlab/instrumentation_helper.rb +++ b/lib/gitlab/instrumentation_helper.rb @@ -4,7 +4,7 @@ module Gitlab module InstrumentationHelper extend self - KEYS = %i(gitaly_calls gitaly_duration rugged_calls rugged_duration_ms).freeze + KEYS = %i(gitaly_calls gitaly_duration rugged_calls rugged_duration_ms redis_calls redis_duration_ms).freeze def add_instrumentation_data(payload) gitaly_calls = Gitlab::GitalyClient.get_request_count @@ -20,6 +20,13 @@ module Gitlab payload[:rugged_calls] = rugged_calls payload[:rugged_duration_ms] = Gitlab::RuggedInstrumentation.query_time_ms end + + redis_calls = Gitlab::Instrumentation::Redis.get_request_count + + if redis_calls > 0 + payload[:redis_calls] = redis_calls + payload[:redis_duration_ms] = Gitlab::Instrumentation::Redis.query_time_ms + end end # Returns the queuing duration for a Sidekiq job in seconds, as a float, if the diff --git a/lib/peek/views/detailed_view.rb b/lib/peek/views/detailed_view.rb index 4f3eddaf11b..389f5301079 100644 --- a/lib/peek/views/detailed_view.rb +++ b/lib/peek/views/detailed_view.rb @@ -17,7 +17,7 @@ module Peek end def detail_store - ::Gitlab::SafeRequestStore["#{key}_call_details"] ||= [] + ::Gitlab::SafeRequestStore["#{key}_call_details".to_sym] ||= [] end private diff --git a/lib/peek/views/redis_detailed.rb b/lib/peek/views/redis_detailed.rb index 14cabd62025..79845044d75 100644 --- a/lib/peek/views/redis_detailed.rb +++ b/lib/peek/views/redis_detailed.rb @@ -1,39 +1,5 @@ # frozen_string_literal: true -require 'redis' - -module Gitlab - module Peek - module RedisInstrumented - def call(*args, &block) - start = Time.now - super(*args, &block) - ensure - duration = (Time.now - start) - add_call_details(duration, args) - end - - private - - def add_call_details(duration, args) - return unless Gitlab::PerformanceBar.enabled_for_request? - # redis-rb passes an array (e.g. [:get, key]) - return unless args.length == 1 - - detail_store << { - cmd: args.first, - duration: duration, - backtrace: ::Gitlab::BacktraceCleaner.clean_backtrace(caller) - } - end - - def detail_store - ::Gitlab::SafeRequestStore['redis_call_details'] ||= [] - end - end - end -end - module Peek module Views class RedisDetailed < DetailedView @@ -63,7 +29,3 @@ module Peek end end end - -class Redis::Client - prepend Gitlab::Peek::RedisInstrumented -end |