diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-29 14:19:43 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-02 19:45:58 +0200 |
commit | c134a72cdb7e6de8b70dc60de99cf4edc68a9227 (patch) | |
tree | 0082ba4d422cc53eea223583bca9c98cbc823c96 /app | |
parent | 770f07cd5c68075bb261f4b6139c92b2ac9309c0 (diff) | |
download | gitlab-ce-c134a72cdb7e6de8b70dc60de99cf4edc68a9227.tar.gz |
Move Prometheus presentation logic to PrometheusText
+ Use NullMetrics to mock metrics when unused
+ Use method_missing in NullMetrics mocking
+ Update prometheus gem to version that correctly uses transitive dependencies
+ Ensure correct folders are used in Multiprocess prometheus client tests.
+ rename Sessions controller's metric
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/metrics_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/sessions_controller.rb | 2 | ||||
-rw-r--r-- | app/services/metrics_service.rb | 15 |
3 files changed, 13 insertions, 10 deletions
diff --git a/app/controllers/metrics_controller.rb b/app/controllers/metrics_controller.rb index 9bcd6f96b34..0e9a19c0b6f 100644 --- a/app/controllers/metrics_controller.rb +++ b/app/controllers/metrics_controller.rb @@ -5,10 +5,8 @@ class MetricsController < ActionController::Base before_action :validate_prometheus_metrics - def metrics - response = "#{metrics_service.health_metrics_text}\n#{metrics_service.prometheus_metrics_text}" - - render text: response, content_type: 'text/plain; version=0.0.4' + def index + render text: metrics_service.metrics_text, content_type: 'text/plain; verssion=0.0.4' end private diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index fc9de30f256..ab52b676e01 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -48,7 +48,7 @@ class SessionsController < Devise::SessionsController private def login_counter - @login_counter ||= Gitlab::Metrics.counter(:user_session_logins, 'User logins count') + @login_counter ||= Gitlab::Metrics.counter(:user_session_logins, 'User sign in count') end # Handle an "initial setup" state, where there's only one user, it's an admin, diff --git a/app/services/metrics_service.rb b/app/services/metrics_service.rb index 350c3639e92..0faa86a228b 100644 --- a/app/services/metrics_service.rb +++ b/app/services/metrics_service.rb @@ -12,18 +12,23 @@ class MetricsService end def health_metrics_text - results = CHECKS.flat_map(&:metrics) + metrics = CHECKS.flat_map(&:metrics) - types = results.map(&:name).uniq.map { |metric_name| "# TYPE #{metric_name} gauge" } - metrics = results.map(&method(:metric_to_prom_line)) + formatter.marshal(metrics) + end - types.concat(metrics).join("\n") + def metrics_text + "#{health_metrics_text}\n#{prometheus_metrics_text}" end private + def formatter + @formatter ||= PrometheusText.new + end + def multiprocess_metrics_path - Rails.root.join(ENV['prometheus_multiproc_dir']) + @multiprocess_metrics_path ||= Rails.root.join(ENV['prometheus_multiproc_dir']) end def metric_to_prom_line(metric) |