Class: NurseAndrea::Configuration
- Inherits:
-
Object
- Object
- NurseAndrea::Configuration
- 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
-
#auto_connect ⇒ Object
Returns the value of attribute auto_connect.
-
#backfill_hours ⇒ Object
Returns the value of attribute backfill_hours.
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#continuous_scan_interval ⇒ Object
Returns the value of attribute continuous_scan_interval.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#disable_continuous_scan ⇒ Object
Returns the value of attribute disable_continuous_scan.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
-
#hook_interval_ms ⇒ Object
Returns the value of attribute hook_interval_ms.
-
#hooks_cache ⇒ Object
Returns the value of attribute hooks_cache.
-
#hooks_database ⇒ Object
Returns the value of attribute hooks_database.
-
#hooks_enabled ⇒ Object
Returns the value of attribute hooks_enabled.
-
#hooks_jobs ⇒ Object
Returns the value of attribute hooks_jobs.
-
#hooks_mailer ⇒ Object
Returns the value of attribute hooks_mailer.
-
#host ⇒ Object
Returns the value of attribute host.
-
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#org_token ⇒ Object
Returns the value of attribute org_token.
-
#platform_detection ⇒ Object
Returns the value of attribute platform_detection.
-
#sdk_language ⇒ Object
Returns the value of attribute sdk_language.
-
#sdk_version ⇒ Object
Returns the value of attribute sdk_version.
-
#service_discovery ⇒ Object
Returns the value of attribute service_discovery.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#workspace_slug ⇒ Object
Returns the value of attribute workspace_slug.
Instance Method Summary collapse
- #deploy_url ⇒ Object
- #enabled? ⇒ Boolean
- #handshake_url ⇒ Object
- #ingest_url ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #metrics_url ⇒ Object
- #min_log_level_int ⇒ Object
- #traces_url ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
-
#validation_diagnostic ⇒ Object
Sprint A D6 (GAP-10) — returns nil when configuration is valid, otherwise returns a symbol identifying the first failure mode.
Constructor Details
#initialize ⇒ Configuration
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_connect ⇒ Object
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_hours ⇒ Object
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_size ⇒ Object
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_interval ⇒ Object
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 |
#debug ⇒ Object
Returns the value of attribute debug.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def debug @debug end |
#disable_continuous_scan ⇒ Object
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 |
#enabled ⇒ Object
Returns the value of attribute enabled.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def enabled @enabled end |
#environment ⇒ Object
Returns the value of attribute environment.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def environment @environment end |
#flush_interval ⇒ Object
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_ms ⇒ Object
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_cache ⇒ Object
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_database ⇒ Object
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_enabled ⇒ Object
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_jobs ⇒ Object
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_mailer ⇒ Object
Returns the value of attribute hooks_mailer.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def hooks_mailer @hooks_mailer end |
#host ⇒ Object
Returns the value of attribute host.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def host @host end |
#log_file_path ⇒ Object
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_level ⇒ Object
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_token ⇒ Object
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_detection ⇒ Object
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_language ⇒ Object
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_version ⇒ Object
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_discovery ⇒ Object
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_name ⇒ Object
Returns the value of attribute service_name.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def service_name @service_name end |
#timeout ⇒ Object
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/nurse_andrea/configuration.rb', line 10 def timeout @timeout end |
#workspace_slug ⇒ Object
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_url ⇒ Object
64 |
# File 'lib/nurse_andrea/configuration.rb', line 64 def deploy_url = "#{normalised_host}/api/v1/deploy" |
#enabled? ⇒ Boolean
66 67 68 |
# File 'lib/nurse_andrea/configuration.rb', line 66 def enabled? @enabled end |
#handshake_url ⇒ Object
63 |
# File 'lib/nurse_andrea/configuration.rb', line 63 def handshake_url = "#{normalised_host}/api/v1/handshake" |
#ingest_url ⇒ Object
60 |
# File 'lib/nurse_andrea/configuration.rb', line 60 def ingest_url = "#{normalised_host}/api/v1/ingest" |
#metrics_url ⇒ Object
61 |
# File 'lib/nurse_andrea/configuration.rb', line 61 def metrics_url = "#{normalised_host}/api/v1/metrics" |
#min_log_level_int ⇒ Object
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_url ⇒ Object
62 |
# File 'lib/nurse_andrea/configuration.rb', line 62 def traces_url = "#{normalised_host}/api/v1/traces" |
#valid? ⇒ 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_diagnostic ⇒ Object
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 |