diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-23 15:06:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-23 15:06:18 +0300 |
commit | 09ffaae1328da918056512ddc674913f0bb7b134 (patch) | |
tree | 5d53f44823cbc132d9f61c60f9781ca9dc9f2e44 /lib | |
parent | b3e4ec8e8adf4fe96c982124e91b6a05021a9cda (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/sidekiq_middleware/metrics.rb | 32 | ||||
-rw-r--r-- | lib/gitlab/sql/union.rb | 2 |
2 files changed, 20 insertions, 14 deletions
diff --git a/lib/gitlab/sidekiq_middleware/metrics.rb b/lib/gitlab/sidekiq_middleware/metrics.rb index 86762a2d02b..d45045ca414 100644 --- a/lib/gitlab/sidekiq_middleware/metrics.rb +++ b/lib/gitlab/sidekiq_middleware/metrics.rb @@ -21,29 +21,35 @@ module Gitlab @metrics[:sidekiq_jobs_retried_total].increment(labels, 1) end + job_succeeded = false + monotonic_time_start = Gitlab::Metrics::System.monotonic_time job_thread_cputime_start = get_thread_cputime - - realtime = Benchmark.realtime do + begin yield - end + job_succeeded = true + ensure + monotonic_time_end = Gitlab::Metrics::System.monotonic_time + job_thread_cputime_end = get_thread_cputime - job_thread_cputime_end = get_thread_cputime - job_thread_cputime = job_thread_cputime_end - job_thread_cputime_start - @metrics[:sidekiq_jobs_cpu_seconds].observe(labels, job_thread_cputime) + monotonic_time = monotonic_time_end - monotonic_time_start + job_thread_cputime = job_thread_cputime_end - job_thread_cputime_start - @metrics[:sidekiq_jobs_completion_seconds].observe(labels, realtime) - rescue Exception # rubocop: disable Lint/RescueException - @metrics[:sidekiq_jobs_failed_total].increment(labels, 1) - raise - ensure - @metrics[:sidekiq_running_jobs].increment(labels, -1) + # sidekiq_running_jobs, sidekiq_jobs_failed_total should not include the job_status label + @metrics[:sidekiq_running_jobs].increment(labels, -1) + @metrics[:sidekiq_jobs_failed_total].increment(labels, 1) unless job_succeeded + + # job_status: done, fail match the job_status attribute in structured logging + labels[:job_status] = job_succeeded ? :done : :fail + @metrics[:sidekiq_jobs_cpu_seconds].observe(labels, job_thread_cputime) + @metrics[:sidekiq_jobs_completion_seconds].observe(labels, monotonic_time) + end end private def init_metrics { - sidekiq_jobs_cpu_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_cpu_seconds, 'Seconds of cpu time to run sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS), + sidekiq_jobs_cpu_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_cpu_seconds, 'Seconds of cpu time to run sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS), sidekiq_jobs_completion_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_completion_seconds, 'Seconds to complete sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS), sidekiq_jobs_failed_total: ::Gitlab::Metrics.counter(:sidekiq_jobs_failed_total, 'Sidekiq jobs failed'), sidekiq_jobs_retried_total: ::Gitlab::Metrics.counter(:sidekiq_jobs_retried_total, 'Sidekiq jobs retried'), diff --git a/lib/gitlab/sql/union.rb b/lib/gitlab/sql/union.rb index f05592fc3a3..b15f2ca385a 100644 --- a/lib/gitlab/sql/union.rb +++ b/lib/gitlab/sql/union.rb @@ -29,7 +29,7 @@ module Gitlab end if fragments.any? - fragments.join("\n#{union_keyword}\n") + "(" + fragments.join(")\n#{union_keyword}\n(") + ")" else 'NULL' end |