Module: Gitlab::PerformanceBar::RedisAdapterWhenPeekEnabled

Defined in:
lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb

Instance Method Summary collapse

Instance Method Details

#enqueue_stats_job(request_id) ⇒ Object

schedules a job which parses peek profile data and adds them to a structured log rubocop:disable Gitlab/ModuleWithInstanceVariables rubocop:disable CodeReuse/ActiveRecord – needed because of ‘.exists?` method usage (which is actually not AR method)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb', line 21

def enqueue_stats_job(request_id)
  return unless Feature.enabled?(:performance_bar_stats, type: :ops)

  cache_existed = @client.exists?(GitlabPerformanceBarStatsWorker::STATS_KEY)
  @client.sadd?(GitlabPerformanceBarStatsWorker::STATS_KEY, request_id)

  return if cache_existed

  # stats key should be periodically processed and deleted by
  # GitlabPerformanceBarStatsWorker but if it doesn't happen for
  # some reason, we set expiration for the stats key to avoid
  # keeping millions of request ids which would be already expired
  # anyway
  @client.expire(
    GitlabPerformanceBarStatsWorker::STATS_KEY,
    GitlabPerformanceBarStatsWorker::STATS_KEY_EXPIRE
  )
end

#save(request_id) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb', line 7

def save(request_id)
  return unless ::Gitlab::PerformanceBar.enabled_for_request?
  return if request_id.blank?

  super

  enqueue_stats_job(request_id)
end