debian-mirror-gitlab/lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb

49 lines
1.6 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
# Adapted from https://github.com/peek/peek/blob/master/lib/peek/adapters/redis.rb
module Gitlab
module PerformanceBar
module RedisAdapterWhenPeekEnabled
2019-12-04 20:38:33 +05:30
def save(request_id)
2021-02-22 17:27:13 +05:30
return unless ::Gitlab::PerformanceBar.enabled_for_request?
return if request_id.blank?
super
enqueue_stats_job(request_id)
end
# schedules a job which parses peek profile data and adds them
# to a structured log
2021-03-08 18:12:59 +05:30
# rubocop:disable Gitlab/ModuleWithInstanceVariables
2021-02-22 17:27:13 +05:30
def enqueue_stats_job(request_id)
2021-04-17 20:07:23 +05:30
return unless Feature.enabled?(:performance_bar_stats)
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
@client.sadd(GitlabPerformanceBarStatsWorker::STATS_KEY, request_id)
2021-02-22 17:27:13 +05:30
return unless uuid = Gitlab::ExclusiveLease.new(
GitlabPerformanceBarStatsWorker::LEASE_KEY,
timeout: GitlabPerformanceBarStatsWorker::LEASE_TIMEOUT
).try_obtain
2021-03-08 18:12:59 +05:30
# 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
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@client.expire(
GitlabPerformanceBarStatsWorker::STATS_KEY,
GitlabPerformanceBarStatsWorker::STATS_KEY_EXPIRE
)
GitlabPerformanceBarStatsWorker.perform_in(
GitlabPerformanceBarStatsWorker::WORKER_DELAY,
uuid
)
2021-02-22 17:27:13 +05:30
end
2021-03-08 18:12:59 +05:30
# rubocop:enable Gitlab/ModuleWithInstanceVariables
2019-09-30 21:07:59 +05:30
end
end
end