Class: RailsHealthChecks::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_health_checks/configuration.rb

Constant Summary collapse

BUILT_IN_NAMES =
%i[database cache sidekiq solid_queue good_job resque disk memory http].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails_health_checks/configuration.rb', line 16

def initialize
  @checks = [:database]
  @timeout = 5
  @cache_duration = nil
  @allowed_ips = nil
  @token = nil
  @authenticate_block = nil
  @sidekiq_queue_size = nil
  @solid_queue_job_count = nil
  @good_job_latency = nil
  @resque_queue_size = nil
  @disk_warn_threshold = nil
  @disk_critical_threshold = nil
  @disk_path = "/"
  @memory_threshold = nil
  @http_url = nil
  @http_expected_status = 200
  @http_headers = {}
  @custom_checks = {}
  @groups = {}
  @disabled_checks = {}
end

Instance Attribute Details

#allowed_ipsObject

Returns the value of attribute allowed_ips.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def allowed_ips
  @allowed_ips
end

#authenticate_blockObject (readonly)

Returns the value of attribute authenticate_block.



14
15
16
# File 'lib/rails_health_checks/configuration.rb', line 14

def authenticate_block
  @authenticate_block
end

#cache_durationObject

Returns the value of attribute cache_duration.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def cache_duration
  @cache_duration
end

#checksObject



39
40
41
42
# File 'lib/rails_health_checks/configuration.rb', line 39

def checks
  disabled = @disabled_checks.filter_map { |name, envs| name if envs.include?(Rails.env.to_s) }
  @checks - disabled
end

#custom_checksObject (readonly)

Returns the value of attribute custom_checks.



14
15
16
# File 'lib/rails_health_checks/configuration.rb', line 14

def custom_checks
  @custom_checks
end

#disk_critical_thresholdObject

Returns the value of attribute disk_critical_threshold.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def disk_critical_threshold
  @disk_critical_threshold
end

#disk_pathObject

Returns the value of attribute disk_path.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def disk_path
  @disk_path
end

#disk_warn_thresholdObject

Returns the value of attribute disk_warn_threshold.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def disk_warn_threshold
  @disk_warn_threshold
end

#good_job_latencyObject

Returns the value of attribute good_job_latency.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def good_job_latency
  @good_job_latency
end

#groupsObject (readonly)

Returns the value of attribute groups.



14
15
16
# File 'lib/rails_health_checks/configuration.rb', line 14

def groups
  @groups
end

#http_expected_statusObject

Returns the value of attribute http_expected_status.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def http_expected_status
  @http_expected_status
end

#http_headersObject

Returns the value of attribute http_headers.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def http_headers
  @http_headers
end

#http_urlObject

Returns the value of attribute http_url.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def http_url
  @http_url
end

#memory_thresholdObject

Returns the value of attribute memory_threshold.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def memory_threshold
  @memory_threshold
end

#resque_queue_sizeObject

Returns the value of attribute resque_queue_size.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def resque_queue_size
  @resque_queue_size
end

#sidekiq_queue_sizeObject

Returns the value of attribute sidekiq_queue_size.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def sidekiq_queue_size
  @sidekiq_queue_size
end

#solid_queue_job_countObject

Returns the value of attribute solid_queue_job_count.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def solid_queue_job_count
  @solid_queue_job_count
end

#timeoutObject

Returns the value of attribute timeout.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def timeout
  @timeout
end

#tokenObject

Returns the value of attribute token.



10
11
12
# File 'lib/rails_health_checks/configuration.rb', line 10

def token
  @token
end

Instance Method Details

#authenticate(&block) ⇒ Object



44
45
46
# File 'lib/rails_health_checks/configuration.rb', line 44

def authenticate(&block)
  @authenticate_block = block
end

#disable(name, **opts) ⇒ Object



48
49
50
51
52
# File 'lib/rails_health_checks/configuration.rb', line 48

def disable(name, **opts)
  envs = Array(opts.fetch(:in)).map(&:to_s)
  @disabled_checks[name] ||= []
  @disabled_checks[name].concat(envs)
end

#group(name, check_names) ⇒ Object



54
55
56
# File 'lib/rails_health_checks/configuration.rb', line 54

def group(name, check_names)
  @groups[name] = check_names
end

#register(name, check, timeout: nil) ⇒ Object



58
59
60
61
62
# File 'lib/rails_health_checks/configuration.rb', line 58

def register(name, check, timeout: nil)
  check.timeout = timeout
  @custom_checks[name] = check
  @checks << name unless @checks.include?(name)
end

#validate!Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rails_health_checks/configuration.rb', line 64

def validate!
  all_checks = @checks + @groups.values.flatten
  all_checks.uniq.each do |name|
    next if BUILT_IN_NAMES.include?(name) || @custom_checks.key?(name)

    raise ConfigurationError, "Unknown check :#{name}. Built-ins: #{BUILT_IN_NAMES.join(', ')}"
  end

  if @checks.include?(:http) && @http_url.nil?
    raise ConfigurationError, "config.checks includes :http but config.http_url is not set"
  end
end