skylight 5.1.0.beta → 5.1.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +390 -371
  3. data/CLA.md +1 -1
  4. data/LICENSE.md +7 -17
  5. data/README.md +1 -1
  6. data/ext/extconf.rb +42 -54
  7. data/lib/skylight.rb +20 -30
  8. data/lib/skylight/api.rb +22 -18
  9. data/lib/skylight/cli.rb +47 -46
  10. data/lib/skylight/cli/doctor.rb +50 -50
  11. data/lib/skylight/cli/helpers.rb +19 -19
  12. data/lib/skylight/cli/merger.rb +141 -139
  13. data/lib/skylight/config.rb +265 -302
  14. data/lib/skylight/deprecation.rb +4 -4
  15. data/lib/skylight/errors.rb +3 -4
  16. data/lib/skylight/extensions.rb +17 -29
  17. data/lib/skylight/extensions/source_location.rb +128 -128
  18. data/lib/skylight/formatters/http.rb +1 -3
  19. data/lib/skylight/gc.rb +30 -40
  20. data/lib/skylight/helpers.rb +43 -41
  21. data/lib/skylight/instrumenter.rb +25 -18
  22. data/lib/skylight/middleware.rb +31 -35
  23. data/lib/skylight/native.rb +8 -10
  24. data/lib/skylight/native_ext_fetcher.rb +10 -12
  25. data/lib/skylight/normalizers.rb +43 -39
  26. data/lib/skylight/normalizers/action_controller/process_action.rb +24 -25
  27. data/lib/skylight/normalizers/action_controller/send_file.rb +7 -6
  28. data/lib/skylight/normalizers/action_dispatch/route_set.rb +7 -7
  29. data/lib/skylight/normalizers/active_job/perform.rb +48 -44
  30. data/lib/skylight/normalizers/active_model_serializers/render.rb +7 -3
  31. data/lib/skylight/normalizers/active_storage.rb +11 -13
  32. data/lib/skylight/normalizers/active_support/cache.rb +1 -12
  33. data/lib/skylight/normalizers/coach/handler_finish.rb +1 -3
  34. data/lib/skylight/normalizers/default.rb +1 -9
  35. data/lib/skylight/normalizers/faraday/request.rb +1 -3
  36. data/lib/skylight/normalizers/grape/endpoint.rb +13 -19
  37. data/lib/skylight/normalizers/grape/endpoint_run.rb +16 -18
  38. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +1 -3
  39. data/lib/skylight/normalizers/graphql/base.rb +23 -28
  40. data/lib/skylight/normalizers/render.rb +19 -21
  41. data/lib/skylight/normalizers/shrine.rb +15 -17
  42. data/lib/skylight/normalizers/sql.rb +4 -4
  43. data/lib/skylight/probes.rb +38 -46
  44. data/lib/skylight/probes/action_controller.rb +32 -28
  45. data/lib/skylight/probes/action_dispatch/request_id.rb +9 -5
  46. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +7 -5
  47. data/lib/skylight/probes/action_view.rb +9 -10
  48. data/lib/skylight/probes/active_job_enqueue.rb +3 -9
  49. data/lib/skylight/probes/active_model_serializers.rb +8 -8
  50. data/lib/skylight/probes/delayed_job.rb +37 -42
  51. data/lib/skylight/probes/elasticsearch.rb +3 -5
  52. data/lib/skylight/probes/excon.rb +1 -1
  53. data/lib/skylight/probes/excon/middleware.rb +22 -23
  54. data/lib/skylight/probes/graphql.rb +2 -7
  55. data/lib/skylight/probes/middleware.rb +14 -5
  56. data/lib/skylight/probes/mongo.rb +83 -91
  57. data/lib/skylight/probes/net_http.rb +1 -1
  58. data/lib/skylight/probes/redis.rb +5 -17
  59. data/lib/skylight/probes/sequel.rb +7 -11
  60. data/lib/skylight/probes/sinatra.rb +8 -5
  61. data/lib/skylight/probes/tilt.rb +2 -4
  62. data/lib/skylight/railtie.rb +121 -135
  63. data/lib/skylight/sidekiq.rb +4 -5
  64. data/lib/skylight/subscriber.rb +31 -33
  65. data/lib/skylight/test.rb +89 -84
  66. data/lib/skylight/trace.rb +121 -115
  67. data/lib/skylight/user_config.rb +14 -17
  68. data/lib/skylight/util/clock.rb +1 -0
  69. data/lib/skylight/util/component.rb +18 -21
  70. data/lib/skylight/util/deploy.rb +11 -13
  71. data/lib/skylight/util/http.rb +104 -105
  72. data/lib/skylight/util/logging.rb +4 -6
  73. data/lib/skylight/util/lru_cache.rb +2 -6
  74. data/lib/skylight/util/platform.rb +2 -6
  75. data/lib/skylight/util/ssl.rb +1 -3
  76. data/lib/skylight/version.rb +1 -1
  77. data/lib/skylight/vm/gc.rb +1 -9
  78. metadata +4 -4
@@ -22,113 +22,96 @@ module Skylight
22
22
  # Map environment variable keys with Skylight configuration keys
23
23
  ENV_TO_KEY = {
24
24
  # == Authentication ==
25
- -"AUTHENTICATION" => :authentication,
26
-
25
+ -"AUTHENTICATION" => :authentication,
27
26
  # == App settings ==
28
- -"ROOT" => :root,
29
- -"HOSTNAME" => :hostname,
30
- -"SESSION_TOKEN" => :session_token,
31
-
27
+ -"ROOT" => :root,
28
+ -"HOSTNAME" => :hostname,
29
+ -"SESSION_TOKEN" => :session_token,
32
30
  # == Component settings ==
33
- -"ENV" => :env,
34
- -"COMPONENT" => :component,
35
- -"REPORT_RAILS_ENV" => :report_rails_env,
36
-
31
+ -"ENV" => :env,
32
+ -"COMPONENT" => :component,
33
+ -"REPORT_RAILS_ENV" => :report_rails_env,
37
34
  # == Deploy settings ==
38
- -"DEPLOY_ID" => :'deploy.id',
39
- -"DEPLOY_GIT_SHA" => :'deploy.git_sha',
40
- -"DEPLOY_DESCRIPTION" => :'deploy.description',
41
-
35
+ -"DEPLOY_ID" => :'deploy.id',
36
+ -"DEPLOY_GIT_SHA" => :'deploy.git_sha',
37
+ -"DEPLOY_DESCRIPTION" => :'deploy.description',
42
38
  # == Logging ==
43
- -"LOG_FILE" => :log_file,
44
- -"LOG_LEVEL" => :log_level,
45
- -"ALERT_LOG_FILE" => :alert_log_file,
46
- -"NATIVE_LOG_FILE" => :native_log_file,
47
- -"NATIVE_LOG_LEVEL" => :native_log_level,
48
- -"LOG_SQL_PARSE_ERRORS" => :log_sql_parse_errors,
49
-
39
+ -"LOG_FILE" => :log_file,
40
+ -"LOG_LEVEL" => :log_level,
41
+ -"ALERT_LOG_FILE" => :alert_log_file,
42
+ -"NATIVE_LOG_FILE" => :native_log_file,
43
+ -"NATIVE_LOG_LEVEL" => :native_log_level,
44
+ -"LOG_SQL_PARSE_ERRORS" => :log_sql_parse_errors,
50
45
  # == Proxy ==
51
- -"PROXY_URL" => :proxy_url,
52
-
46
+ -"PROXY_URL" => :proxy_url,
53
47
  # == Instrumenter ==
54
- -"ENABLE_SEGMENTS" => :enable_segments,
55
- -"ENABLE_SIDEKIQ" => :enable_sidekiq,
56
- -"IGNORED_ENDPOINT" => :ignored_endpoint,
57
- -"IGNORED_ENDPOINTS" => :ignored_endpoints,
58
- -"SINATRA_ROUTE_PREFIXES" => :sinatra_route_prefixes,
59
- -"ENABLE_SOURCE_LOCATIONS" => :enable_source_locations,
60
-
48
+ -"ENABLE_SEGMENTS" => :enable_segments,
49
+ -"ENABLE_SIDEKIQ" => :enable_sidekiq,
50
+ -"IGNORED_ENDPOINT" => :ignored_endpoint,
51
+ -"IGNORED_ENDPOINTS" => :ignored_endpoints,
52
+ -"SINATRA_ROUTE_PREFIXES" => :sinatra_route_prefixes,
53
+ -"ENABLE_SOURCE_LOCATIONS" => :enable_source_locations,
61
54
  # == Max Span Handling ==
62
- -"REPORT_MAX_SPANS_EXCEEDED" => :report_max_spans_exceeded,
63
- -"PRUNE_LARGE_TRACES" => :prune_large_traces,
64
-
55
+ -"REPORT_MAX_SPANS_EXCEEDED" => :report_max_spans_exceeded,
56
+ -"PRUNE_LARGE_TRACES" => :prune_large_traces,
65
57
  # == Skylight Remote ==
66
- -"AUTH_URL" => :auth_url,
67
- -"APP_CREATE_URL" => :app_create_url,
68
- -"MERGES_URL" => :merges_url,
69
- -"VALIDATION_URL" => :validation_url,
70
- -"AUTH_HTTP_DEFLATE" => :auth_http_deflate,
71
- -"AUTH_HTTP_CONNECT_TIMEOUT" => :auth_http_connect_timeout,
72
- -"AUTH_HTTP_READ_TIMEOUT" => :auth_http_read_timeout,
73
- -"REPORT_URL" => :report_url,
74
- -"REPORT_HTTP_DEFLATE" => :report_http_deflate,
75
- -"REPORT_HTTP_CONNECT_TIMEOUT" => :report_http_connect_timeout,
76
- -"REPORT_HTTP_READ_TIMEOUT" => :report_http_read_timeout,
77
- -"REPORT_HTTP_DISABLED" => :report_http_disabled,
78
-
58
+ -"AUTH_URL" => :auth_url,
59
+ -"APP_CREATE_URL" => :app_create_url,
60
+ -"MERGES_URL" => :merges_url,
61
+ -"VALIDATION_URL" => :validation_url,
62
+ -"AUTH_HTTP_DEFLATE" => :auth_http_deflate,
63
+ -"AUTH_HTTP_CONNECT_TIMEOUT" => :auth_http_connect_timeout,
64
+ -"AUTH_HTTP_READ_TIMEOUT" => :auth_http_read_timeout,
65
+ -"REPORT_URL" => :report_url,
66
+ -"REPORT_HTTP_DEFLATE" => :report_http_deflate,
67
+ -"REPORT_HTTP_CONNECT_TIMEOUT" => :report_http_connect_timeout,
68
+ -"REPORT_HTTP_READ_TIMEOUT" => :report_http_read_timeout,
69
+ -"REPORT_HTTP_DISABLED" => :report_http_disabled,
79
70
  # == Native agent settings ==
80
71
  #
81
- -"LAZY_START" => :'daemon.lazy_start',
82
- -"DAEMON_EXEC_PATH" => :'daemon.exec_path',
83
- -"DAEMON_LIB_PATH" => :'daemon.lib_path',
84
- -"PIDFILE_PATH" => :'daemon.pidfile_path',
85
- -"SOCKDIR_PATH" => :'daemon.sockdir_path',
86
- -"BATCH_QUEUE_DEPTH" => :'daemon.batch_queue_depth',
87
- -"BATCH_SAMPLE_SIZE" => :'daemon.batch_sample_size',
88
- -"BATCH_FLUSH_INTERVAL" => :'daemon.batch_flush_interval',
89
- -"DAEMON_TICK_INTERVAL" => :'daemon.tick_interval',
90
- -"DAEMON_LOCK_CHECK_INTERVAL" => :'daemon.lock_check_interval',
91
- -"DAEMON_INACTIVITY_TIMEOUT" => :'daemon.inactivity_timeout',
92
- -"CLIENT_MAX_TRIES" => :'daemon.max_connect_tries',
93
- -"CLIENT_CONN_TRY_WIN" => :'daemon.connect_try_window',
94
- -"MAX_PRESPAWN_JITTER" => :'daemon.max_prespawn_jitter',
95
- -"DAEMON_WAIT_TIMEOUT" => :'daemon.wait_timeout',
96
- -"CLIENT_CHECK_INTERVAL" => :'daemon.client_check_interval',
97
- -"CLIENT_QUEUE_DEPTH" => :'daemon.client_queue_depth',
98
- -"CLIENT_WRITE_TIMEOUT" => :'daemon.client_write_timeout',
99
- -"SSL_CERT_PATH" => :'daemon.ssl_cert_path',
100
- -"ENABLE_TCP" => :'daemon.enable_tcp',
101
- -"TCP_PORT" => :'daemon.tcp_port',
102
-
72
+ -"LAZY_START" => :'daemon.lazy_start',
73
+ -"DAEMON_EXEC_PATH" => :'daemon.exec_path',
74
+ -"DAEMON_LIB_PATH" => :'daemon.lib_path',
75
+ -"PIDFILE_PATH" => :'daemon.pidfile_path',
76
+ -"SOCKDIR_PATH" => :'daemon.sockdir_path',
77
+ -"BATCH_QUEUE_DEPTH" => :'daemon.batch_queue_depth',
78
+ -"BATCH_SAMPLE_SIZE" => :'daemon.batch_sample_size',
79
+ -"BATCH_FLUSH_INTERVAL" => :'daemon.batch_flush_interval',
80
+ -"DAEMON_TICK_INTERVAL" => :'daemon.tick_interval',
81
+ -"DAEMON_LOCK_CHECK_INTERVAL" => :'daemon.lock_check_interval',
82
+ -"DAEMON_INACTIVITY_TIMEOUT" => :'daemon.inactivity_timeout',
83
+ -"CLIENT_MAX_TRIES" => :'daemon.max_connect_tries',
84
+ -"CLIENT_CONN_TRY_WIN" => :'daemon.connect_try_window',
85
+ -"MAX_PRESPAWN_JITTER" => :'daemon.max_prespawn_jitter',
86
+ -"DAEMON_WAIT_TIMEOUT" => :'daemon.wait_timeout',
87
+ -"CLIENT_CHECK_INTERVAL" => :'daemon.client_check_interval',
88
+ -"CLIENT_QUEUE_DEPTH" => :'daemon.client_queue_depth',
89
+ -"CLIENT_WRITE_TIMEOUT" => :'daemon.client_write_timeout',
90
+ -"SSL_CERT_PATH" => :'daemon.ssl_cert_path',
91
+ -"ENABLE_TCP" => :'daemon.enable_tcp',
92
+ -"TCP_PORT" => :'daemon.tcp_port',
103
93
  # == Legacy env vars ==
104
94
  #
105
- -"AGENT_LOCKFILE" => :'agent.lockfile',
106
- -"AGENT_SOCKFILE_PATH" => :'agent.sockfile_path',
107
-
95
+ -"AGENT_LOCKFILE" => :'agent.lockfile',
96
+ -"AGENT_SOCKFILE_PATH" => :'agent.sockfile_path',
108
97
  # == User config settings ==
109
- -"USER_CONFIG_PATH" => :user_config_path,
110
-
98
+ -"USER_CONFIG_PATH" => :user_config_path,
111
99
  # == Heroku settings ==
112
- -"HEROKU_DYNO_INFO_PATH" => :'heroku.dyno_info_path',
113
-
100
+ -"HEROKU_DYNO_INFO_PATH" => :'heroku.dyno_info_path',
114
101
  # == Source Location ==
115
102
  -"SOURCE_LOCATION_IGNORED_GEMS" => :source_location_ignored_gems,
116
- -"SOURCE_LOCATION_CACHE_SIZE" => :source_location_cache_size
103
+ -"SOURCE_LOCATION_CACHE_SIZE" => :source_location_cache_size
117
104
  }.freeze
118
105
 
119
106
  KEY_TO_NATIVE_ENV = {
120
107
  # We use different log files for native and Ruby, but the native code doesn't know this
121
- native_log_file: "LOG_FILE",
108
+ native_log_file: "LOG_FILE",
122
109
  native_log_level: "LOG_LEVEL"
123
110
  }.freeze
124
111
 
125
112
  SERVER_VALIDATE = %i[].freeze
126
113
 
127
- DEFAULT_IGNORED_SOURCE_LOCATION_GEMS = [
128
- -"skylight",
129
- -"activesupport",
130
- -"activerecord"
131
- ].freeze
114
+ DEFAULT_IGNORED_SOURCE_LOCATION_GEMS = [-"skylight", -"activesupport", -"activerecord"].freeze
132
115
 
133
116
  # Default values for Skylight configuration keys
134
117
  def self.default_values
@@ -136,38 +119,32 @@ module Skylight
136
119
  begin
137
120
  ret = {
138
121
  # URLs
139
- auth_url: -"https://auth.skylight.io/agent",
140
- app_create_url: -"https://www.skylight.io/apps",
141
- merges_url: -"https://www.skylight.io/merges",
142
- validation_url: -"https://auth.skylight.io/agent/config",
143
-
122
+ auth_url: -"https://auth.skylight.io/agent",
123
+ app_create_url: -"https://www.skylight.io/apps",
124
+ merges_url: -"https://www.skylight.io/merges",
125
+ validation_url: -"https://auth.skylight.io/agent/config",
144
126
  # Logging
145
- log_file: -"-",
146
- log_level: -"INFO",
147
- alert_log_file: -"-",
148
- log_sql_parse_errors: true,
149
- native_log_level: -"warn",
150
-
127
+ log_file: -"-",
128
+ log_level: -"INFO",
129
+ alert_log_file: -"-",
130
+ log_sql_parse_errors: true,
131
+ native_log_level: -"warn",
151
132
  # Features
152
- enable_segments: true,
153
- enable_sidekiq: false,
154
- sinatra_route_prefixes: false,
155
- enable_source_locations: true,
156
-
133
+ enable_segments: true,
134
+ enable_sidekiq: false,
135
+ sinatra_route_prefixes: false,
136
+ enable_source_locations: true,
157
137
  # Deploys
158
- 'heroku.dyno_info_path': -"/etc/heroku/dyno",
159
- report_rails_env: true,
160
-
138
+ 'heroku.dyno_info_path': -"/etc/heroku/dyno",
139
+ report_rails_env: true,
161
140
  # Daemon
162
- 'daemon.lazy_start': true,
163
- hostname: Util::Hostname.default_hostname,
141
+ 'daemon.lazy_start': true,
142
+ hostname: Util::Hostname.default_hostname,
164
143
  report_max_spans_exceeded: false,
165
- prune_large_traces: true
144
+ prune_large_traces: true
166
145
  }
167
146
 
168
- unless Util::Platform::OS == -"darwin"
169
- ret[:'daemon.ssl_cert_path'] = Util::SSL.ca_cert_file_or_default
170
- end
147
+ ret[:'daemon.ssl_cert_path'] = Util::SSL.ca_cert_file_or_default unless Util::Platform::OS == -"darwin"
171
148
 
172
149
  if Skylight.native?
173
150
  native_path = Skylight.libskylight_path
@@ -182,67 +159,64 @@ module Skylight
182
159
 
183
160
  REQUIRED_KEYS = {
184
161
  authentication: "authentication token",
185
- hostname: "server hostname",
186
- auth_url: "authentication url",
162
+ hostname: "server hostname",
163
+ auth_url: "authentication url",
187
164
  validation_url: "config validation url"
188
165
  }.freeze
189
166
 
190
167
  def self.native_env_keys
191
- @native_env_keys ||= %i[
192
- native_log_level
193
- native_log_file
194
- log_sql_parse_errors
195
- version
196
- root
197
- proxy_url
198
- hostname
199
- session_token
200
- auth_url
201
- auth_http_deflate
202
- auth_http_connect_timeout
203
- auth_http_read_timeout
204
- report_url
205
- report_http_deflate
206
- report_http_connect_timeout
207
- report_http_read_timeout
208
- report_http_disabled
209
- daemon.lazy_start
210
- daemon.exec_path
211
- daemon.lib_path
212
- daemon.pidfile_path
213
- daemon.sockdir_path
214
- daemon.batch_queue_depth
215
- daemon.batch_sample_size
216
- daemon.batch_flush_interval
217
- daemon.tick_interval
218
- daemon.lock_check_interval
219
- daemon.inactivity_timeout
220
- daemon.max_connect_tries
221
- daemon.connect_try_window
222
- daemon.max_prespawn_jitter
223
- daemon.wait_timeout
224
- daemon.client_check_interval
225
- daemon.client_queue_depth
226
- daemon.client_write_timeout
227
- daemon.ssl_cert_path
228
- daemon.ssl_cert_dir
229
- daemon.enable_tcp
230
- daemon.tcp_port
231
- ]
168
+ @native_env_keys ||=
169
+ %i[
170
+ native_log_level
171
+ native_log_file
172
+ log_sql_parse_errors
173
+ version
174
+ root
175
+ proxy_url
176
+ hostname
177
+ session_token
178
+ auth_url
179
+ auth_http_deflate
180
+ auth_http_connect_timeout
181
+ auth_http_read_timeout
182
+ report_url
183
+ report_http_deflate
184
+ report_http_connect_timeout
185
+ report_http_read_timeout
186
+ report_http_disabled
187
+ daemon.lazy_start
188
+ daemon.exec_path
189
+ daemon.lib_path
190
+ daemon.pidfile_path
191
+ daemon.sockdir_path
192
+ daemon.batch_queue_depth
193
+ daemon.batch_sample_size
194
+ daemon.batch_flush_interval
195
+ daemon.tick_interval
196
+ daemon.lock_check_interval
197
+ daemon.inactivity_timeout
198
+ daemon.max_connect_tries
199
+ daemon.connect_try_window
200
+ daemon.max_prespawn_jitter
201
+ daemon.wait_timeout
202
+ daemon.client_check_interval
203
+ daemon.client_queue_depth
204
+ daemon.client_write_timeout
205
+ daemon.ssl_cert_path
206
+ daemon.ssl_cert_dir
207
+ daemon.enable_tcp
208
+ daemon.tcp_port
209
+ ]
232
210
  end
233
211
 
234
212
  # Maps legacy config keys to new config keys
235
213
  def self.legacy_keys
236
- @legacy_keys ||= {
237
- 'agent.sockfile_path': :'daemon.sockdir_path',
238
- 'agent.lockfile': :'daemon.pidfile_path'
239
- }
214
+ @legacy_keys ||= { 'agent.sockfile_path': :'daemon.sockdir_path', 'agent.lockfile': :'daemon.pidfile_path' }
240
215
  end
241
216
 
242
217
  def self.validators
243
- @validators ||= {
244
- 'agent.interval': [->(v, _c) { v.is_a?(Integer) && v > 0 }, "must be an integer greater than 0"]
245
- }
218
+ @validators ||=
219
+ { 'agent.interval': [->(v, _c) { v.is_a?(Integer) && v > 0 }, "must be an integer greater than 0"] }
246
220
  end
247
221
 
248
222
  # @api private
@@ -252,9 +226,7 @@ module Skylight
252
226
  def initialize(*args)
253
227
  attrs = {}
254
228
 
255
- if args.last.is_a?(Hash)
256
- attrs = args.pop.dup
257
- end
229
+ attrs = args.pop.dup if args.last.is_a?(Hash)
258
230
 
259
231
  @values = {}
260
232
  @priority = {}
@@ -268,13 +240,9 @@ module Skylight
268
240
  @priority_regexp = /^#{Regexp.escape(priority_key)}\.(.+)$/
269
241
  end
270
242
 
271
- attrs.each do |k, v|
272
- self[k] = v
273
- end
243
+ attrs.each { |k, v| self[k] = v }
274
244
 
275
- p&.each do |k, v|
276
- @priority[self.class.remap_key(k)] = v
277
- end
245
+ p&.each { |k, v| @priority[self.class.remap_key(k)] = v }
278
246
  end
279
247
 
280
248
  def self.load(opts = {}, env = ENV)
@@ -286,10 +254,8 @@ module Skylight
286
254
  if path
287
255
  error = nil
288
256
  begin
289
- attrs = YAML.safe_load(ERB.new(File.read(path)).result,
290
- permitted_classes: [],
291
- permitted_symbols: [],
292
- aliases: true)
257
+ attrs =
258
+ YAML.safe_load(ERB.new(File.read(path)).result, permitted_classes: [], permitted_symbols: [], aliases: true)
293
259
  error = "empty file" unless attrs
294
260
  error = "invalid format" if attrs && !attrs.is_a?(Hash)
295
261
  rescue Exception => e
@@ -302,15 +268,11 @@ module Skylight
302
268
  # The key-value pairs in this `priority` option are inserted into the
303
269
  # config's @priority hash *after* anything listed under priority_key;
304
270
  # i.e., ENV takes precendence over priority_key
305
- if env
306
- attrs[:priority] = remap_env(env)
307
- end
271
+ attrs[:priority] = remap_env(env) if env
308
272
 
309
273
  config = new(priority_key, attrs)
310
274
 
311
- opts.each do |k, v|
312
- config[k] = v
313
- end
275
+ opts.each { |k, v| config[k] = v }
314
276
 
315
277
  config
316
278
  end
@@ -337,12 +299,18 @@ module Skylight
337
299
 
338
300
  ret[key] =
339
301
  case val
340
- when /^false$/i then false
341
- when /^true$/i then true
342
- when /^(nil|null)$/i then nil
343
- when /^\d+$/ then val.to_i
344
- when /^\d+\.\d+$/ then val.to_f
345
- else val
302
+ when /^false$/i
303
+ false
304
+ when /^true$/i
305
+ true
306
+ when /^(nil|null)$/i
307
+ nil
308
+ when /^\d+$/
309
+ val.to_i
310
+ when /^\d+\.\d+$/
311
+ val.to_f
312
+ else
313
+ val
346
314
  end
347
315
  end
348
316
 
@@ -351,11 +319,7 @@ module Skylight
351
319
 
352
320
  # @api private
353
321
  def validate!
354
- REQUIRED_KEYS.each do |k, v|
355
- unless get(k)
356
- raise ConfigError, "#{v} required"
357
- end
358
- end
322
+ REQUIRED_KEYS.each { |k, v| raise ConfigError, "#{v} required" unless get(k) }
359
323
 
360
324
  log_file = self[:log_file]
361
325
  alert_log_file = self[:alert_log_file]
@@ -363,6 +327,7 @@ module Skylight
363
327
 
364
328
  check_logfile_permissions(log_file, "log_file")
365
329
  check_logfile_permissions(alert_log_file, "alert_log_file")
330
+
366
331
  # TODO: Support rotation interpolation in this check
367
332
  check_logfile_permissions(native_log_file, "native_log_file")
368
333
 
@@ -382,15 +347,20 @@ module Skylight
382
347
  file_root = File.dirname(file)
383
348
 
384
349
  # Try to make the directory, don't blow up if we can't. Our writable? check will fail later.
385
- FileUtils.mkdir_p file_root rescue nil
350
+ begin
351
+ FileUtils.mkdir_p file_root
352
+ rescue StandardError
353
+ nil
354
+ end
386
355
 
387
356
  if File.exist?(file) && !FileTest.writable?(file)
388
357
  raise ConfigError, "File `#{file}` is not writable. Please set #{key} in your config to a writable path"
389
358
  end
390
359
 
391
360
  unless FileTest.writable?(file_root)
392
- raise ConfigError, "Directory `#{file_root}` is not writable. Please set #{key} in your config to a " \
393
- "writable path"
361
+ raise ConfigError,
362
+ "Directory `#{file_root}` is not writable. Please set #{key} in your config to a " \
363
+ "writable path"
394
364
  end
395
365
  end
396
366
 
@@ -410,7 +380,7 @@ module Skylight
410
380
  key = self.class.remap_key(key)
411
381
 
412
382
  return @priority[key] if @priority.key?(key)
413
- return @values[key] if @values.key?(key)
383
+ return @values[key] if @values.key?(key)
414
384
  return self.class.default_values[key] if self.class.default_values.key?(key)
415
385
 
416
386
  if default
@@ -425,14 +395,10 @@ module Skylight
425
395
  alias [] get
426
396
 
427
397
  def set(key, val, scope = nil)
428
- if scope
429
- key = [scope, key].join(".")
430
- end
398
+ key = [scope, key].join(".") if scope
431
399
 
432
400
  if val.is_a?(Hash)
433
- val.each do |k, v|
434
- set(k, v, key)
435
- end
401
+ val.each { |k, v| set(k, v, key) }
436
402
  else
437
403
  k = self.class.remap_key(key)
438
404
 
@@ -446,9 +412,7 @@ module Skylight
446
412
  end
447
413
  end
448
414
 
449
- if @priority_regexp && k =~ @priority_regexp
450
- @priority[$1.to_sym] = val
451
- end
415
+ @priority[$1.to_sym] = val if @priority_regexp && k =~ @priority_regexp
452
416
 
453
417
  @values[k] = val
454
418
  end
@@ -470,7 +434,8 @@ module Skylight
470
434
  v / 1_000
471
435
  when "nanos"
472
436
  v / 1_000_000
473
- else # "s", "sec", nil
437
+ else
438
+ # "s", "sec", nil
474
439
  v * 1000
475
440
  end
476
441
  else
@@ -481,13 +446,16 @@ module Skylight
481
446
  def to_native_env
482
447
  ret = []
483
448
 
484
- self.class.native_env_keys.each do |key|
485
- value = send_or_get(key)
486
- unless value.nil?
487
- env_key = KEY_TO_NATIVE_ENV[key] || ENV_TO_KEY.key(key) || key.upcase
488
- ret << "SKYLIGHT_#{env_key}" << cast_for_env(value)
449
+ self
450
+ .class
451
+ .native_env_keys
452
+ .each do |key|
453
+ value = send_or_get(key)
454
+ unless value.nil?
455
+ env_key = KEY_TO_NATIVE_ENV[key] || ENV_TO_KEY.key(key) || key.upcase
456
+ ret << "SKYLIGHT_#{env_key}" << cast_for_env(value)
457
+ end
489
458
  end
490
- end
491
459
 
492
460
  ret << "SKYLIGHT_AUTHENTICATION" << authentication_with_meta
493
461
  ret << "SKYLIGHT_VALIDATE_AUTHENTICATION" << "false"
@@ -518,9 +486,7 @@ module Skylight
518
486
 
519
487
  # If, for some odd reason you have a comma in your endpoint name, use the
520
488
  # YML config instead.
521
- if ignored_endpoints.is_a?(String)
522
- ignored_endpoints = ignored_endpoints.split(/\s*,\s*/)
523
- end
489
+ ignored_endpoints = ignored_endpoints.split(/\s*,\s*/) if ignored_endpoints.is_a?(String)
524
490
 
525
491
  val = Array(get(:ignored_endpoint))
526
492
  val.concat(Array(ignored_endpoints))
@@ -533,9 +499,7 @@ module Skylight
533
499
  @source_location_ignored_gems ||=
534
500
  begin
535
501
  ignored_gems = get(:source_location_ignored_gems)
536
- if ignored_gems.is_a?(String)
537
- ignored_gems = ignored_gems.split(/\s*,\s*/)
538
- end
502
+ ignored_gems = ignored_gems.split(/\s*,\s*/) if ignored_gems.is_a?(String)
539
503
 
540
504
  Array(ignored_gems) | DEFAULT_IGNORED_SOURCE_LOCATION_GEMS
541
505
  end
@@ -551,12 +515,18 @@ module Skylight
551
515
  Logger::DEBUG
552
516
  else
553
517
  case get(:log_level)
554
- when /^debug$/i then Logger::DEBUG
555
- when /^info$/i then Logger::INFO
556
- when /^warn$/i then Logger::WARN
557
- when /^error$/i then Logger::ERROR
558
- when /^fatal$/i then Logger::FATAL
559
- else Logger::ERROR # rubocop:disable Lint/DuplicateBranch
518
+ when /^debug$/i
519
+ Logger::DEBUG
520
+ when /^info$/i
521
+ Logger::INFO
522
+ when /^warn$/i
523
+ Logger::WARN
524
+ when /^error$/i
525
+ Logger::ERROR
526
+ when /^fatal$/i
527
+ Logger::FATAL
528
+ else
529
+ Logger::ERROR
560
530
  end
561
531
  end
562
532
  end
@@ -566,36 +536,35 @@ module Skylight
566
536
  end
567
537
 
568
538
  def logger
569
- @logger ||=
570
- MUTEX.synchronize do
571
- load_logger
572
- end
539
+ @logger ||= MUTEX.synchronize { load_logger }
573
540
  end
574
541
 
575
542
  def native_log_file
576
- @native_log_file ||= get("native_log_file") do
577
- log_file = self["log_file"]
578
- return "-" if log_file == "-"
579
-
580
- parts = log_file.to_s.split(".")
581
- parts.insert(-2, "native")
582
- parts.join(".")
583
- end
543
+ @native_log_file ||=
544
+ get("native_log_file") do
545
+ log_file = self["log_file"]
546
+ return "-" if log_file == "-"
547
+
548
+ parts = log_file.to_s.split(".")
549
+ parts.insert(-2, "native")
550
+ parts.join(".")
551
+ end
584
552
  end
585
553
 
586
554
  attr_writer :logger, :alert_logger
587
555
 
588
556
  def alert_logger
589
- @alert_logger ||= MUTEX.synchronize do
590
- unless (l = @alert_logger)
591
- out = get(:alert_log_file)
592
- out = Util::AlertLogger.new(load_logger) if out == "-"
557
+ @alert_logger ||=
558
+ MUTEX.synchronize do
559
+ unless (l = @alert_logger)
560
+ out = get(:alert_log_file)
561
+ out = Util::AlertLogger.new(load_logger) if out == "-"
593
562
 
594
- l = create_logger(out, level: Logger::DEBUG)
595
- end
563
+ l = create_logger(out, level: Logger::DEBUG)
564
+ end
596
565
 
597
- l
598
- end
566
+ l
567
+ end
599
568
  end
600
569
 
601
570
  def enable_segments?
@@ -624,36 +593,41 @@ module Skylight
624
593
 
625
594
  private
626
595
 
627
- def create_logger(out, level: :info)
628
- if out.is_a?(String)
629
- out = File.expand_path(out, root)
630
- # May be redundant since we also do this in the permissions check
631
- FileUtils.mkdir_p(File.dirname(out))
632
- end
596
+ def create_logger(out, level: :info)
597
+ if out.is_a?(String)
598
+ out = File.expand_path(out, root)
633
599
 
634
- Logger.new(out, progname: "Skylight", level: level)
635
- rescue
636
- Logger.new($stdout, progname: "Skylight", level: level)
600
+ # May be redundant since we also do this in the permissions check
601
+ FileUtils.mkdir_p(File.dirname(out))
637
602
  end
638
603
 
639
- def load_logger
640
- unless (l = @logger)
641
- out = get(:log_file)
642
- out = $stdout if out == "-"
643
- l = create_logger(out, level: log_level)
644
- end
604
+ Logger.new(out, progname: "Skylight", level: level)
605
+ rescue StandardError
606
+ Logger.new($stdout, progname: "Skylight", level: level)
607
+ end
645
608
 
646
- l
609
+ def load_logger
610
+ unless (l = @logger)
611
+ out = get(:log_file)
612
+ out = $stdout if out == "-"
613
+ l = create_logger(out, level: log_level)
647
614
  end
648
615
 
649
- def cast_for_env(val)
650
- case val
651
- when true then "true"
652
- when false then "false"
653
- when nil then "nil"
654
- else val.to_s
655
- end
616
+ l
617
+ end
618
+
619
+ def cast_for_env(val)
620
+ case val
621
+ when true
622
+ "true"
623
+ when false
624
+ "false"
625
+ when nil
626
+ "nil"
627
+ else
628
+ val.to_s
656
629
  end
630
+ end
657
631
 
658
632
  public
659
633
 
@@ -670,15 +644,11 @@ module Skylight
670
644
  return false
671
645
  end
672
646
 
673
- if res.error_response?
674
- warn("Unable to reach server for config validation")
675
- end
647
+ warn("Unable to reach server for config validation") if res.error_response?
676
648
 
677
649
  unless res.config_valid?
678
650
  warn("Invalid configuration") unless res.error_response?
679
- res.validation_errors.each do |k, v|
680
- warn(" #{k}: #{v}")
681
- end
651
+ res.validation_errors.each { |k, v| warn(" #{k}: #{v}") }
682
652
 
683
653
  return false if res.forbidden?
684
654
 
@@ -707,29 +677,33 @@ module Skylight
707
677
 
708
678
  def check_sockdir_permissions(sockdir_path)
709
679
  # Try to make the directory, don't blow up if we can't. Our writable? check will fail later.
710
- FileUtils.mkdir_p sockdir_path rescue nil
680
+ begin
681
+ FileUtils.mkdir_p sockdir_path
682
+ rescue StandardError
683
+ nil
684
+ end
711
685
 
712
686
  unless FileTest.writable?(sockdir_path)
713
- raise ConfigError, "Directory `#{sockdir_path}` is not writable. Please set daemon.sockdir_path in " \
714
- "your config to a writable path"
687
+ raise ConfigError,
688
+ "Directory `#{sockdir_path}` is not writable. Please set daemon.sockdir_path in " \
689
+ "your config to a writable path"
715
690
  end
716
691
 
717
692
  if check_nfs(sockdir_path)
718
- raise ConfigError, "Directory `#{sockdir_path}` is an NFS mount and will not allow sockets. Please set " \
719
- "daemon.sockdir_path in your config to a non-NFS path."
693
+ raise ConfigError,
694
+ "Directory `#{sockdir_path}` is an NFS mount and will not allow sockets. Please set " \
695
+ "daemon.sockdir_path in your config to a non-NFS path."
720
696
  end
721
697
  end
722
698
 
723
699
  def write(path)
724
700
  FileUtils.mkdir_p(File.dirname(path))
725
701
 
726
- File.open(path, "w") do |f|
727
- f.puts <<~YAML
702
+ File.open(path, "w") { |f| f.puts <<~YAML }
728
703
  ---
729
704
  # The authentication token for the application.
730
705
  authentication: #{self[:authentication]}
731
706
  YAML
732
- end
733
707
  end
734
708
 
735
709
  #
@@ -759,17 +733,11 @@ module Skylight
759
733
  end
760
734
 
761
735
  def components
762
- @components ||= {
763
- web: Util::Component.new(
764
- get(:env),
765
- Util::Component::DEFAULT_NAME
766
- ),
767
- worker: Util::Component.new(
768
- get(:env),
769
- get(:component) || get(:worker_component),
770
- force_worker: true
771
- )
772
- }
736
+ @components ||=
737
+ {
738
+ web: Util::Component.new(get(:env), Util::Component::DEFAULT_NAME),
739
+ worker: Util::Component.new(get(:env), get(:component) || get(:worker_component), force_worker: true)
740
+ }
773
741
  rescue ArgumentError => e
774
742
  raise ConfigError, e.message
775
743
  end
@@ -783,25 +751,20 @@ module Skylight
783
751
  end
784
752
 
785
753
  def as_json(*)
786
- {
787
- config: {
788
- priority: @priority.merge(component.as_json),
789
- values: @values
790
- }
791
- }
754
+ { config: { priority: @priority.merge(component.as_json), values: @values } }
792
755
  end
793
756
 
794
757
  private
795
758
 
796
- def check_nfs(path)
797
- # Should work on most *nix, though not on OS X
798
- `stat -f -L -c %T #{path} 2>&1`.strip == "nfs"
799
- end
759
+ def check_nfs(path)
760
+ # Should work on most *nix, though not on OS X
761
+ `stat -f -L -c %T #{path} 2>&1`.strip == "nfs"
762
+ end
800
763
 
801
- def reporting_env?
802
- # true if env was explicitly set,
803
- # or if we are auto-detecting via the opt-in SKYLIGHT_REPORT_RAILS_ENV=true
804
- !!(get(:report_rails_env) || get(:env))
805
- end
764
+ def reporting_env?
765
+ # true if env was explicitly set,
766
+ # or if we are auto-detecting via the opt-in SKYLIGHT_REPORT_RAILS_ENV=true
767
+ !!(get(:report_rails_env) || get(:env))
768
+ end
806
769
  end
807
770
  end