Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-07 18:05:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-07 18:05:59 +0300
commit31040b5bfe48f8d73830f473513164427522b3a6 (patch)
tree6301b395ad45d7a0f84aa0f9c31373889208d09b /lib/gitlab/health_checks
parent185f428fa5e6123ffa0f29e307523da138e7b028 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/health_checks')
-rw-r--r--lib/gitlab/health_checks/probes/liveness.rb13
-rw-r--r--lib/gitlab/health_checks/probes/readiness.rb53
-rw-r--r--lib/gitlab/health_checks/probes/status.rb14
3 files changed, 80 insertions, 0 deletions
diff --git a/lib/gitlab/health_checks/probes/liveness.rb b/lib/gitlab/health_checks/probes/liveness.rb
new file mode 100644
index 00000000000..b4d346e945e
--- /dev/null
+++ b/lib/gitlab/health_checks/probes/liveness.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ module Probes
+ class Liveness
+ def execute
+ Probes::Status.new(200, status: 'ok')
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/health_checks/probes/readiness.rb b/lib/gitlab/health_checks/probes/readiness.rb
new file mode 100644
index 00000000000..b789cbe1ae6
--- /dev/null
+++ b/lib/gitlab/health_checks/probes/readiness.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ module Probes
+ class Readiness
+ attr_reader :checks
+
+ # This accepts an array of Proc
+ # that returns `::Gitlab::HealthChecks::Result`
+ def initialize(*additional_checks)
+ @checks = ::Gitlab::HealthChecks::CHECKS.map { |check| check.method(:readiness) }
+ @checks += additional_checks
+ end
+
+ def execute
+ readiness = probe_readiness
+ success = all_succeeded?(readiness)
+
+ Probes::Status.new(
+ success ? 200 : 503,
+ status(success).merge(payload(readiness))
+ )
+ end
+
+ private
+
+ def all_succeeded?(readiness)
+ readiness.all? do |name, probes|
+ probes.any?(&:success)
+ end
+ end
+
+ def status(success)
+ { status: success ? 'ok' : 'failed' }
+ end
+
+ def payload(readiness)
+ readiness.transform_values do |probes|
+ probes.map(&:payload)
+ end
+ end
+
+ def probe_readiness
+ checks
+ .flat_map(&:call)
+ .compact
+ .group_by(&:name)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/health_checks/probes/status.rb b/lib/gitlab/health_checks/probes/status.rb
new file mode 100644
index 00000000000..192e9366001
--- /dev/null
+++ b/lib/gitlab/health_checks/probes/status.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ module Probes
+ Status = Struct.new(:http_status, :json) do
+ # We accept 2xx
+ def success?
+ http_status / 100 == 2
+ end
+ end
+ end
+ end
+end