diff options
| author | Kevin Lyda <lyda@gitlab.com> | 2017-05-16 15:32:07 +0100 |
|---|---|---|
| committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-02 19:45:57 +0200 |
| commit | 6b9a091ceeb1c760be14f749956807bc429af46d (patch) | |
| tree | 9aea662dbee6284d186dc1f29c3022d9eb25d229 | |
| parent | 5bc099c2de1e05fa4dbe45b59caeced209834178 (diff) | |
| download | gitlab-ce-6b9a091ceeb1c760be14f749956807bc429af46d.tar.gz | |
Add trailing newline to response.
Prometheus requires a trailing newline in its response.
+ cleanup
| -rw-r--r-- | app/controllers/health_controller.rb | 18 | ||||
| -rw-r--r-- | app/controllers/sessions_controller.rb | 6 | ||||
| -rw-r--r-- | app/services/prom_service.rb | 15 |
3 files changed, 20 insertions, 19 deletions
diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb index 03cc896fce9..6f8038f6ec3 100644 --- a/app/controllers/health_controller.rb +++ b/app/controllers/health_controller.rb @@ -23,15 +23,27 @@ class HealthController < ActionController::Base end def metrics - results = CHECKS.flat_map(&:metrics) + response = health_metrics_text + "\n" + + if Gitlab::Metrics.prometheus_metrics_enabled? + response += Prometheus::Client::Formats::Text.marshal_multiprocess(ENV['prometheus_multiproc_dir']) + end - response = results.map(&method(:metric_to_prom_line)).join("\n") - response = ::Prometheus::Client::Formats::Text.marshal_multiprocess render text: response, content_type: 'text/plain; version=0.0.4' end private + def health_metrics_text + results = CHECKS.flat_map(&:metrics) + + types = results.map(&:name) + .uniq + .map { |metric_name| "# TYPE #{metric_name} gauge" } + metrics = results.map(&method(:metric_to_prom_line)) + types.concat(metrics).join("\n") + end + def metric_to_prom_line(metric) labels = metric.labels&.map { |key, value| "#{key}=\"#{value}\"" }&.join(',') || '' if labels.empty? diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 9870d4286a6..eaed878283e 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -34,7 +34,6 @@ class SessionsController < Devise::SessionsController end # hide the signed-in notification flash[:notice] = nil - PromService.instance.login.increment log_audit_event(current_user, with: authentication_method) log_user_activity(current_user) end @@ -48,6 +47,10 @@ class SessionsController < Devise::SessionsController private + def self.login_counter + @login_counter ||= Gitlab::Metrics.counter(:user_session_logins, 'User logins count') + end + # Handle an "initial setup" state, where there's only one user, it's an admin, # and they require a password change. def check_initial_setup @@ -126,6 +129,7 @@ class SessionsController < Devise::SessionsController end def log_user_activity(user) + SessionsController.login_counter.increment Users::ActivityService.new(user, 'login').execute end diff --git a/app/services/prom_service.rb b/app/services/prom_service.rb deleted file mode 100644 index 93d52fd2c79..00000000000 --- a/app/services/prom_service.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'prometheus/client' -require 'singleton' - -class PromService - include Singleton - - attr_reader :login - - def initialize - @prometheus = Prometheus::Client.registry - - @login = Prometheus::Client::Counter.new(:login, 'Login counter') - @prometheus.register(@login) - end -end |
