diff options
Diffstat (limited to 'lib/gitlab/metrics')
-rw-r--r-- | lib/gitlab/metrics/background_transaction.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/metrics/sidekiq_middleware.rb | 35 | ||||
-rw-r--r-- | lib/gitlab/metrics/subscribers/active_record.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/metrics/transaction.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/metrics/web_transaction.rb | 7 |
5 files changed, 8 insertions, 68 deletions
diff --git a/lib/gitlab/metrics/background_transaction.rb b/lib/gitlab/metrics/background_transaction.rb deleted file mode 100644 index 7b05ae29b02..00000000000 --- a/lib/gitlab/metrics/background_transaction.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Metrics - class BackgroundTransaction < Transaction - def initialize(worker_class) - super() - @worker_class = worker_class - end - - def labels - { controller: @worker_class.name, action: 'perform', feature_category: @worker_class.try(:get_feature_category).to_s } - end - end - end -end diff --git a/lib/gitlab/metrics/sidekiq_middleware.rb b/lib/gitlab/metrics/sidekiq_middleware.rb deleted file mode 100644 index 8c4e5a8d70c..00000000000 --- a/lib/gitlab/metrics/sidekiq_middleware.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Metrics - # Sidekiq middleware for tracking jobs. - # - # This middleware is intended to be used as a server-side middleware. - class SidekiqMiddleware - def call(worker, payload, queue) - trans = BackgroundTransaction.new(worker.class) - - begin - # Old gitlad-shell messages don't provide enqueued_at/created_at attributes - enqueued_at = payload['enqueued_at'] || payload['created_at'] || 0 - trans.set(:gitlab_transaction_sidekiq_queue_duration_total, Time.current.to_f - enqueued_at) do - multiprocess_mode :livesum - end - trans.run { yield } - rescue Exception => error # rubocop: disable Lint/RescueException - trans.add_event(:sidekiq_exception) - - raise error - ensure - add_info_to_payload(payload, trans) - end - end - - private - - def add_info_to_payload(payload, trans) - payload.merge!(::Gitlab::Metrics::Subscribers::ActiveRecord.db_counter_payload) - end - end - end -end diff --git a/lib/gitlab/metrics/subscribers/active_record.rb b/lib/gitlab/metrics/subscribers/active_record.rb index f9ba0a69b0e..d725d8d7b29 100644 --- a/lib/gitlab/metrics/subscribers/active_record.rb +++ b/lib/gitlab/metrics/subscribers/active_record.rb @@ -16,16 +16,14 @@ module Gitlab # using a connection. Thread.current[:uses_db_connection] = true - return unless current_transaction - payload = event.payload return if payload[:name] == 'SCHEMA' || IGNORABLE_SQL.include?(payload[:sql]) - current_transaction.observe(:gitlab_sql_duration_seconds, event.duration / 1000.0) do + increment_db_counters(payload) + + current_transaction&.observe(:gitlab_sql_duration_seconds, event.duration / 1000.0) do buckets [0.05, 0.1, 0.25] end - - increment_db_counters(payload) end def self.db_counter_payload @@ -53,7 +51,7 @@ module Gitlab end def increment(counter) - current_transaction.increment("gitlab_transaction_#{counter}_total".to_sym, 1) + current_transaction&.increment("gitlab_transaction_#{counter}_total".to_sym, 1) if Gitlab::SafeRequestStore.active? Gitlab::SafeRequestStore[counter] = Gitlab::SafeRequestStore[counter].to_i + 1 diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb index 95bc90f9dad..3ebafb5c5e4 100644 --- a/lib/gitlab/metrics/transaction.rb +++ b/lib/gitlab/metrics/transaction.rb @@ -48,23 +48,15 @@ module Gitlab @finished_at ? (@finished_at - @started_at) : 0.0 end - def thread_cpu_duration - System.thread_cpu_duration(@thread_cputime_start) - end - def run Thread.current[THREAD_KEY] = self @started_at = System.monotonic_time - @thread_cputime_start = System.thread_cpu_time yield ensure @finished_at = System.monotonic_time - observe(:gitlab_transaction_cputime_seconds, thread_cpu_duration) do - buckets SMALL_BUCKETS - end observe(:gitlab_transaction_duration_seconds, duration) do buckets SMALL_BUCKETS end diff --git a/lib/gitlab/metrics/web_transaction.rb b/lib/gitlab/metrics/web_transaction.rb index 2064f9290d3..1811389a744 100644 --- a/lib/gitlab/metrics/web_transaction.rb +++ b/lib/gitlab/metrics/web_transaction.rb @@ -66,9 +66,10 @@ module Gitlab if route path = endpoint_paths_cache[route.request_method][route.path] - # Feature categories will be added for grape endpoints in - # https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/462 - { controller: 'Grape', action: "#{route.request_method} #{path}", feature_category: '' } + grape_class = endpoint.options[:for] + feature_category = grape_class.try(:feature_category_for_app, endpoint).to_s + + { controller: 'Grape', action: "#{route.request_method} #{path}", feature_category: feature_category } end end |