diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-10 12:06:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-10 12:06:08 +0300 |
commit | c157f963db87a40a3ba7b94b339530ee83194bc8 (patch) | |
tree | 9f8f9468daf727cce39bc7487af8bd9a53b8c59d /lib/gitlab | |
parent | bd1e1afde56a9bd97e03ca24298e260dc071999e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/sidekiq_middleware/metrics.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/utils.rb | 8 |
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/gitlab/sidekiq_middleware/metrics.rb b/lib/gitlab/sidekiq_middleware/metrics.rb index 368f37a5d8c..8af353d8674 100644 --- a/lib/gitlab/sidekiq_middleware/metrics.rb +++ b/lib/gitlab/sidekiq_middleware/metrics.rb @@ -19,10 +19,16 @@ module Gitlab @metrics[:sidekiq_jobs_retried_total].increment(labels, 1) end + job_thread_cputime_start = get_thread_cputime + realtime = Benchmark.realtime do yield end + 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) + @metrics[:sidekiq_jobs_completion_seconds].observe(labels, realtime) rescue Exception # rubocop: disable Lint/RescueException @metrics[:sidekiq_jobs_failed_total].increment(labels, 1) @@ -35,6 +41,7 @@ module Gitlab 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_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'), @@ -47,6 +54,10 @@ module Gitlab queue: queue } end + + def get_thread_cputime + defined?(Process::CLOCK_THREAD_CPUTIME_ID) ? Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID) : 0 + end end end end diff --git a/lib/gitlab/utils.rb b/lib/gitlab/utils.rb index c66ce0434a4..7fbfc4c45c4 100644 --- a/lib/gitlab/utils.rb +++ b/lib/gitlab/utils.rb @@ -13,14 +13,6 @@ module Gitlab path end - # Run system command without outputting to stdout. - # - # @param cmd [Array<String>] - # @return [Boolean] - def system_silent(cmd) - Popen.popen(cmd).last.zero? - end - def force_utf8(str) str.dup.force_encoding(Encoding::UTF_8) end |