diff options
author | Kevin Lyda <lyda@gitlab.com> | 2017-05-16 17:32:07 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-02 20:45:57 +0300 |
commit | 6b9a091ceeb1c760be14f749956807bc429af46d (patch) | |
tree | 9aea662dbee6284d186dc1f29c3022d9eb25d229 /app/controllers/health_controller.rb | |
parent | 5bc099c2de1e05fa4dbe45b59caeced209834178 (diff) |
Add trailing newline to response.
Prometheus requires a trailing newline in its response.
+ cleanup
Diffstat (limited to 'app/controllers/health_controller.rb')
-rw-r--r-- | app/controllers/health_controller.rb | 18 |
1 files changed, 15 insertions, 3 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? |