Commit 466beeb3 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Use interpolation instead of concatenation

parent 62fe37e3
...@@ -14,7 +14,7 @@ class MetricsController < ActionController::Base ...@@ -14,7 +14,7 @@ class MetricsController < ActionController::Base
def metrics def metrics
metrics_text = Prometheus::Client::Formats::Text.marshal_multiprocess(multiprocess_metrics_path) metrics_text = Prometheus::Client::Formats::Text.marshal_multiprocess(multiprocess_metrics_path)
response = health_metrics_text + "\n" + metrics_text response = "#{health_metrics_text}\n#{metrics_text}"
render text: response, content_type: 'text/plain; version=0.0.4' render text: response, content_type: 'text/plain; version=0.0.4'
end end
...@@ -32,15 +32,15 @@ class MetricsController < ActionController::Base ...@@ -32,15 +32,15 @@ class MetricsController < ActionController::Base
def health_metrics_text def health_metrics_text
results = CHECKS.flat_map(&:metrics) results = CHECKS.flat_map(&:metrics)
types = results.map(&:name) types = results.map(&:name).uniq.map { |metric_name| "# TYPE #{metric_name} gauge" }
.uniq
.map { |metric_name| "# TYPE #{metric_name} gauge" }
metrics = results.map(&method(:metric_to_prom_line)) metrics = results.map(&method(:metric_to_prom_line))
types.concat(metrics).join("\n") types.concat(metrics).join("\n")
end end
def metric_to_prom_line(metric) def metric_to_prom_line(metric)
labels = metric.labels&.map { |key, value| "#{key}=\"#{value}\"" }&.join(',') || '' labels = metric.labels&.map { |key, value| "#{key}=\"#{value}\"" }&.join(',') || ''
if labels.empty? if labels.empty?
"#{metric.name} #{metric.value}" "#{metric.name} #{metric.value}"
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment