Add trailing newline to response.
Prometheus requires a trailing newline in its response. + cleanup
This commit is contained in:
parent
5bc099c2de
commit
6b9a091cee
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue