Class: NurseAndrea::Configuration

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

Constant Summary collapse

SUPPORTED_ENVIRONMENTS =
EnvironmentDetector::SUPPORTED
MIGRATION_MESSAGE =
"%<field>s is no longer supported in NurseAndrea SDK 1.0. " \
"Migrate to org_token + workspace_slug + environment. " \
"See https://docs.nurseandrea.io/sdk/migration"
LOG_LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3, fatal: 4 }.freeze
DEFAULT_HOST =
"https://nurseandrea.io"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nurse_andrea/configuration.rb', line 23

def initialize
  @host           = DEFAULT_HOST
  @environment    = EnvironmentDetector.detect
  @timeout        = 5
  @log_level      = :debug
  @batch_size     = 100
  @flush_interval = 10
  @backfill_hours = 24
  @log_file_path  = nil
  @enabled            = true
  @debug              = false
  @service_name       = default_service_name
  @sdk_version        = NurseAndrea::VERSION
  @sdk_language       = "ruby"
  @hooks_enabled      = true
  @hooks_database     = true
  @hooks_cache        = true
  @hooks_jobs         = true
  @hooks_mailer       = true
  @hook_interval_ms   = 10_000
  @platform_detection = true
  @service_discovery  = true
  @auto_connect       = false
  @disable_continuous_scan  = false
  @continuous_scan_interval = 5 * 60
end

Instance Attribute Details

#auto_connectObject

Returns the value of attribute auto_connect.



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

def auto_connect
  @auto_connect
end

#backfill_hoursObject

Returns the value of attribute backfill_hours.



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

def backfill_hours
  @backfill_hours
end

#batch_sizeObject

Returns the value of attribute batch_size.



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

def batch_size
  @batch_size
end

#continuous_scan_intervalObject

Returns the value of attribute continuous_scan_interval.



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

def continuous_scan_interval
  @continuous_scan_interval
end

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

#disable_continuous_scanObject

Returns the value of attribute disable_continuous_scan.



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

def disable_continuous_scan
  @disable_continuous_scan
end

#enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#environmentObject

Returns the value of attribute environment.



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

def environment
  @environment
end

#flush_intervalObject

Returns the value of attribute flush_interval.



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

def flush_interval
  @flush_interval
end

#hook_interval_msObject

Returns the value of attribute hook_interval_ms.



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

def hook_interval_ms
  @hook_interval_ms
end

#hooks_cacheObject

Returns the value of attribute hooks_cache.



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

def hooks_cache
  @hooks_cache
end

#hooks_databaseObject

Returns the value of attribute hooks_database.



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

def hooks_database
  @hooks_database
end

#hooks_enabledObject

Returns the value of attribute hooks_enabled.



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

def hooks_enabled
  @hooks_enabled
end

#hooks_jobsObject

Returns the value of attribute hooks_jobs.



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

def hooks_jobs
  @hooks_jobs
end

#hooks_mailerObject

Returns the value of attribute hooks_mailer.



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

def hooks_mailer
  @hooks_mailer
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#log_file_pathObject

Returns the value of attribute log_file_path.



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

def log_file_path
  @log_file_path
end

#log_levelObject

Returns the value of attribute log_level.



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

def log_level
  @log_level
end

#org_tokenObject

Returns the value of attribute org_token.



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

def org_token
  @org_token
end

#platform_detectionObject

Returns the value of attribute platform_detection.



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

def platform_detection
  @platform_detection
end

#sdk_languageObject

Returns the value of attribute sdk_language.



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

def sdk_language
  @sdk_language
end

#sdk_versionObject

Returns the value of attribute sdk_version.



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

def sdk_version
  @sdk_version
end

#service_discoveryObject

Returns the value of attribute service_discovery.



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

def service_discovery
  @service_discovery
end

#service_nameObject

Returns the value of attribute service_name.



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

def service_name
  @service_name
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#workspace_slugObject

Returns the value of attribute workspace_slug.



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

def workspace_slug
  @workspace_slug
end

Instance Method Details

#deploy_urlObject



64
# File 'lib/nurse_andrea/configuration.rb', line 64

def deploy_url    = "#{normalised_host}/api/v1/deploy"

#enabled?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/nurse_andrea/configuration.rb', line 66

def enabled?
  @enabled
end

#handshake_urlObject



63
# File 'lib/nurse_andrea/configuration.rb', line 63

def handshake_url = "#{normalised_host}/api/v1/handshake"

#ingest_urlObject



60
# File 'lib/nurse_andrea/configuration.rb', line 60

def ingest_url    = "#{normalised_host}/api/v1/ingest"

#metrics_urlObject



61
# File 'lib/nurse_andrea/configuration.rb', line 61

def metrics_url   = "#{normalised_host}/api/v1/metrics"

#min_log_level_intObject



70
71
72
# File 'lib/nurse_andrea/configuration.rb', line 70

def min_log_level_int
  LOG_LEVELS.fetch(log_level.to_sym, 0)
end

#traces_urlObject



62
# File 'lib/nurse_andrea/configuration.rb', line 62

def traces_url    = "#{normalised_host}/api/v1/traces"

#valid?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/nurse_andrea/configuration.rb', line 74

def valid?
  validation_diagnostic.nil?
end

#validate!Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/nurse_andrea/configuration.rb', line 98

def validate!
  raise_config_error("org_token is required")      if blank?(org_token)
  raise_config_error("workspace_slug is required") if blank?(workspace_slug)
  raise_config_error("environment is required")    if blank?(environment)

  unless SUPPORTED_ENVIRONMENTS.include?(environment)
    raise_config_error(
      "environment must be one of #{SUPPORTED_ENVIRONMENTS.join(', ')} " \
      "(got #{environment.inspect})"
    )
  end

  unless SlugValidator.valid?(workspace_slug)
    raise_config_error(
      "workspace_slug #{workspace_slug.inspect} is invalid. " \
      "#{SlugValidator::HUMAN_READABLE_RULES}"
    )
  end

  self
end

#validation_diagnosticObject

Sprint A D6 (GAP-10) — returns nil when configuration is valid, otherwise returns a symbol identifying the first failure mode. The Railtie maps these symbols to operator-actionable stderr messages so a missing-org_token miss tells the operator to set the env var rather than emitting the generic “Configuration incomplete at logger wrap time” line.

Order matters: most-likely-missing field first. Operators debugging from logs benefit from the first message being the most common cause.



88
89
90
91
92
93
94
95
96
# File 'lib/nurse_andrea/configuration.rb', line 88

def validation_diagnostic
  return :missing_org_token      if blank?(org_token)
  return :missing_workspace_slug if blank?(workspace_slug)
  return :missing_environment    if blank?(environment)
  return :invalid_environment    unless SUPPORTED_ENVIRONMENTS.include?(environment)
  return :invalid_workspace_slug unless SlugValidator.valid?(workspace_slug)
  return :missing_host           if host.nil?
  nil
end