diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-03 21:07:29 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-03 21:07:29 +0000 |
commit | 1da3754b25657f49afdcb0b942506d365b1ee89d (patch) | |
tree | 9f4bfa94fdd1762ef99e6a61bf180ac8cd7b5616 /lib/gitlab/health_checks | |
parent | 25521def84a6987fe9d4265b560e930bfb32c195 (diff) | |
download | gitlab-ce-1da3754b25657f49afdcb0b942506d365b1ee89d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/health_checks')
-rw-r--r-- | lib/gitlab/health_checks/checks.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/health_checks/gitaly_check.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/health_checks/metric.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/health_checks/prometheus_text_format.rb | 42 | ||||
-rw-r--r-- | lib/gitlab/health_checks/result.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/health_checks/simple_abstract_check.rb | 8 |
6 files changed, 41 insertions, 51 deletions
diff --git a/lib/gitlab/health_checks/checks.rb b/lib/gitlab/health_checks/checks.rb new file mode 100644 index 00000000000..c4016c5fffd --- /dev/null +++ b/lib/gitlab/health_checks/checks.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Gitlab + module HealthChecks + CHECKS = [ + Gitlab::HealthChecks::DbCheck, + Gitlab::HealthChecks::Redis::RedisCheck, + Gitlab::HealthChecks::Redis::CacheCheck, + Gitlab::HealthChecks::Redis::QueuesCheck, + Gitlab::HealthChecks::Redis::SharedStateCheck, + Gitlab::HealthChecks::GitalyCheck + ].freeze + end +end diff --git a/lib/gitlab/health_checks/gitaly_check.rb b/lib/gitlab/health_checks/gitaly_check.rb index e560f87bf98..f5f142c251f 100644 --- a/lib/gitlab/health_checks/gitaly_check.rb +++ b/lib/gitlab/health_checks/gitaly_check.rb @@ -29,7 +29,13 @@ module Gitlab def check(storage_name) serv = Gitlab::GitalyClient::HealthCheckService.new(storage_name) result = serv.check - HealthChecks::Result.new(result[:success], result[:message], shard: storage_name) + + HealthChecks::Result.new( + name, + result[:success], + result[:message], + shard: storage_name + ) end private diff --git a/lib/gitlab/health_checks/metric.rb b/lib/gitlab/health_checks/metric.rb index 184083de2bc..b697cb0d027 100644 --- a/lib/gitlab/health_checks/metric.rb +++ b/lib/gitlab/health_checks/metric.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true -module Gitlab::HealthChecks - Metric = Struct.new(:name, :value, :labels) +module Gitlab + module HealthChecks + Metric = Struct.new(:name, :value, :labels) + end end diff --git a/lib/gitlab/health_checks/prometheus_text_format.rb b/lib/gitlab/health_checks/prometheus_text_format.rb deleted file mode 100644 index 2a8f9d31cd5..00000000000 --- a/lib/gitlab/health_checks/prometheus_text_format.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module HealthChecks - class PrometheusTextFormat - def marshal(metrics) - "#{metrics_with_type_declarations(metrics).join("\n")}\n" - end - - private - - def metrics_with_type_declarations(metrics) - type_declaration_added = {} - - metrics.flat_map do |metric| - metric_lines = [] - - unless type_declaration_added.key?(metric.name) - type_declaration_added[metric.name] = true - metric_lines << metric_type_declaration(metric) - end - - metric_lines << metric_text(metric) - end - end - - def metric_type_declaration(metric) - "# TYPE #{metric.name} gauge" - end - - 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}" - end - end - end - end -end diff --git a/lib/gitlab/health_checks/result.rb b/lib/gitlab/health_checks/result.rb index 4586b1d94a7..38a36100ec7 100644 --- a/lib/gitlab/health_checks/result.rb +++ b/lib/gitlab/health_checks/result.rb @@ -1,5 +1,15 @@ # frozen_string_literal: true -module Gitlab::HealthChecks - Result = Struct.new(:success, :message, :labels) +module Gitlab + module HealthChecks + Result = Struct.new(:name, :success, :message, :labels) do + def payload + { + status: success ? 'ok' : 'failed', + message: message, + labels: labels + }.compact + end + end + end end diff --git a/lib/gitlab/health_checks/simple_abstract_check.rb b/lib/gitlab/health_checks/simple_abstract_check.rb index bc02f0da98d..959f28791c3 100644 --- a/lib/gitlab/health_checks/simple_abstract_check.rb +++ b/lib/gitlab/health_checks/simple_abstract_check.rb @@ -8,14 +8,14 @@ module Gitlab def readiness check_result = check if successful?(check_result) - HealthChecks::Result.new(true) + HealthChecks::Result.new(name, true) elsif check_result.is_a?(Timeout::Error) - HealthChecks::Result.new(false, "#{human_name} check timed out") + HealthChecks::Result.new(name, false, "#{human_name} check timed out") else - HealthChecks::Result.new(false, "unexpected #{human_name} check result: #{check_result}") + HealthChecks::Result.new(name, false, "unexpected #{human_name} check result: #{check_result}") end rescue => e - HealthChecks::Result.new(false, "unexpected #{human_name} check result: #{e}") + HealthChecks::Result.new(name, false, "unexpected #{human_name} check result: #{e}") end def metrics |