diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-09-04 22:14:54 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-02 18:10:57 +0100 |
commit | b6d75b29551e250f853b1a85919c677ecd85ac73 (patch) | |
tree | cbcbdb57b030b0c1b5c7bac40057c3cb9e4d749f | |
parent | f464adaaf6e463e148a1b74d8f1f8280a49594c3 (diff) | |
download | gitlab-ce-b6d75b29551e250f853b1a85919c677ecd85ac73.tar.gz |
remove common Base Sampler code
-rw-r--r-- | doc/user/project/integrations/prometheus.md | 2 | ||||
-rw-r--r-- | lib/gitlab/metrics/samplers/base_sampler.rb | 71 |
2 files changed, 18 insertions, 55 deletions
diff --git a/doc/user/project/integrations/prometheus.md b/doc/user/project/integrations/prometheus.md index e046b494724..5fefb3b69c4 100644 --- a/doc/user/project/integrations/prometheus.md +++ b/doc/user/project/integrations/prometheus.md @@ -14,8 +14,6 @@ the settings page with a default template. To configure the template, see the ## Requirements -[supported performance metrics](https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/metrics.html) - Integration with Prometheus requires the following: 1. GitLab 9.0 or higher diff --git a/lib/gitlab/metrics/samplers/base_sampler.rb b/lib/gitlab/metrics/samplers/base_sampler.rb index f911df3d170..778cf304e49 100644 --- a/lib/gitlab/metrics/samplers/base_sampler.rb +++ b/lib/gitlab/metrics/samplers/base_sampler.rb @@ -2,20 +2,7 @@ require 'logger' module Gitlab module Metrics module Samplers - class BaseSampler - def self.initialize_instance(*args) - raise "#{name} singleton instance already initialized" if @instance - @instance = new(*args) - at_exit(&@instance.method(:stop)) - @instance - end - - def self.instance - @instance - end - - attr_reader :running - + class BaseSampler < Daemon # interval - The sampling interval in seconds. def initialize(interval) interval_half = interval.to_f / 2 @@ -23,44 +10,7 @@ module Gitlab @interval = interval @interval_steps = (-interval_half..interval_half).step(0.1).to_a - @mutex = Mutex.new - end - - def enabled? - true - end - - def start - return unless enabled? - - @mutex.synchronize do - return if running - @running = true - - @thread = Thread.new do - sleep(sleep_interval) - - while running - safe_sample - - sleep(sleep_interval) - end - end - end - end - - def stop - @mutex.synchronize do - return unless running - - @running = false - - if @thread - @thread.wakeup if @thread.alive? - @thread.join - @thread = nil - end - end + super() end def safe_sample @@ -90,7 +40,22 @@ module Gitlab end end end + + private + + def start_working + @running = true + sleep(sleep_interval) + while running + safe_sample + end + end + + def stop_working + @running = false + end end end end -end
\ No newline at end of file +end + |