diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-30 00:18:46 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-02 19:45:58 +0200 |
commit | b668aaf4268d552315152057729f73f5c5d72147 (patch) | |
tree | b73c130db449e1f43ff8b1d1f9625bd6fa93a011 /lib/gitlab/health_checks | |
parent | ae8f7666e597493ab404f8524c1216a924338291 (diff) | |
download | gitlab-ce-b668aaf4268d552315152057729f73f5c5d72147.tar.gz |
Split the metrics implementation to separate modules for Influx and Prometheus
Diffstat (limited to 'lib/gitlab/health_checks')
-rw-r--r-- | lib/gitlab/health_checks/prometheus_text_format.rb | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/lib/gitlab/health_checks/prometheus_text_format.rb b/lib/gitlab/health_checks/prometheus_text_format.rb index 5fc6f19c37c..e7ec1c516a2 100644 --- a/lib/gitlab/health_checks/prometheus_text_format.rb +++ b/lib/gitlab/health_checks/prometheus_text_format.rb @@ -1,38 +1,40 @@ -module Gitlab::HealthChecks - class PrometheusTextFormat - def marshal(metrics) - metrics_with_type_declarations(metrics).join("\n") - end +module Gitlab + module HealthChecks + class PrometheusTextFormat + def marshal(metrics) + metrics_with_type_declarations(metrics).join("\n") + end - private + private - def metrics_with_type_declarations(metrics) - type_declaration_added = {} + def metrics_with_type_declarations(metrics) + type_declaration_added = {} - metrics.flat_map do |metric| - metric_lines = [] + metrics.flat_map do |metric| + metric_lines = [] - unless type_declaration_added.has_key?(metric.name) - type_declaration_added[metric.name] = true - metric_lines << metric_type_declaration(metric) - end + unless type_declaration_added.has_key?(metric.name) + type_declaration_added[metric.name] = true + metric_lines << metric_type_declaration(metric) + end - metric_lines << metric_text(metric) + metric_lines << metric_text(metric) + end end - end - def metric_type_declaration(metric) - "# TYPE #{metric.name} gauge" - end + def metric_type_declaration(metric) + "# TYPE #{metric.name} gauge" + end - def metric_text(metric) - labels = metric.labels&.map { |key, value| "#{key}=\"#{value}\"" }&.join(',') || '' + def metric_text(metric) + labels = metric.labels&.map { |key, value| "#{key}=\"#{value}\"" }&.join(',') || '' - if labels.empty? - "#{metric.name} #{metric.value}" - else - "#{metric.name}{#{labels}} #{metric.value}" + if labels.empty? + "#{metric.name} #{metric.value}" + else + "#{metric.name}{#{labels}} #{metric.value}" + end end end end -end +end
\ No newline at end of file |