skylight 3.1.4 → 5.3.4

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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +465 -294
  3. data/CLA.md +1 -1
  4. data/CONTRIBUTING.md +11 -3
  5. data/ERRORS.md +3 -0
  6. data/LICENSE.md +8 -18
  7. data/README.md +1 -2
  8. data/bin/skylight +1 -1
  9. data/ext/extconf.rb +118 -122
  10. data/ext/libskylight.yml +8 -6
  11. data/ext/skylight_native.c +56 -100
  12. data/lib/skylight/api.rb +41 -27
  13. data/lib/skylight/cli/doctor.rb +68 -70
  14. data/lib/skylight/cli/helpers.rb +3 -5
  15. data/lib/skylight/cli/merger.rb +99 -92
  16. data/lib/skylight/cli.rb +40 -43
  17. data/lib/skylight/config.rb +656 -201
  18. data/lib/skylight/data/cacert.pem +730 -1023
  19. data/lib/skylight/deprecation.rb +17 -0
  20. data/lib/skylight/errors.rb +34 -16
  21. data/lib/skylight/extensions/source_location.rb +291 -0
  22. data/lib/skylight/extensions.rb +95 -0
  23. data/lib/skylight/formatters/http.rb +18 -0
  24. data/lib/skylight/gc.rb +99 -0
  25. data/lib/skylight/helpers.rb +82 -39
  26. data/lib/skylight/instrumenter.rb +339 -9
  27. data/lib/skylight/middleware.rb +147 -1
  28. data/lib/skylight/native.rb +71 -23
  29. data/lib/skylight/native_ext_fetcher.rb +39 -47
  30. data/lib/skylight/normalizers/action_controller/process_action.rb +68 -0
  31. data/lib/skylight/normalizers/action_controller/send_file.rb +51 -0
  32. data/lib/skylight/normalizers/action_dispatch/process_middleware.rb +22 -0
  33. data/lib/skylight/normalizers/action_dispatch/route_set.rb +27 -0
  34. data/lib/skylight/normalizers/action_view/render_collection.rb +24 -0
  35. data/lib/skylight/normalizers/action_view/render_layout.rb +25 -0
  36. data/lib/skylight/normalizers/action_view/render_partial.rb +23 -0
  37. data/lib/skylight/normalizers/action_view/render_template.rb +23 -0
  38. data/lib/skylight/normalizers/active_job/perform.rb +87 -0
  39. data/lib/skylight/normalizers/active_model_serializers/render.rb +32 -0
  40. data/lib/skylight/normalizers/active_record/instantiation.rb +16 -0
  41. data/lib/skylight/normalizers/active_record/sql.rb +20 -0
  42. data/lib/skylight/normalizers/active_storage.rb +28 -0
  43. data/lib/skylight/normalizers/active_support/cache.rb +11 -0
  44. data/lib/skylight/normalizers/active_support/cache_clear.rb +16 -0
  45. data/lib/skylight/normalizers/active_support/cache_decrement.rb +16 -0
  46. data/lib/skylight/normalizers/active_support/cache_delete.rb +16 -0
  47. data/lib/skylight/normalizers/active_support/cache_exist.rb +16 -0
  48. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +16 -0
  49. data/lib/skylight/normalizers/active_support/cache_generate.rb +16 -0
  50. data/lib/skylight/normalizers/active_support/cache_increment.rb +16 -0
  51. data/lib/skylight/normalizers/active_support/cache_read.rb +16 -0
  52. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +16 -0
  53. data/lib/skylight/normalizers/active_support/cache_write.rb +16 -0
  54. data/lib/skylight/normalizers/coach/handler_finish.rb +44 -0
  55. data/lib/skylight/normalizers/coach/middleware_finish.rb +33 -0
  56. data/lib/skylight/normalizers/couch_potato/query.rb +20 -0
  57. data/lib/skylight/normalizers/data_mapper/sql.rb +12 -0
  58. data/lib/skylight/normalizers/default.rb +24 -0
  59. data/lib/skylight/normalizers/elasticsearch/request.rb +20 -0
  60. data/lib/skylight/normalizers/faraday/request.rb +38 -0
  61. data/lib/skylight/normalizers/grape/endpoint.rb +28 -0
  62. data/lib/skylight/normalizers/grape/endpoint_render.rb +25 -0
  63. data/lib/skylight/normalizers/grape/endpoint_run.rb +39 -0
  64. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +20 -0
  65. data/lib/skylight/normalizers/grape/format_response.rb +20 -0
  66. data/lib/skylight/normalizers/graphiti/render.rb +22 -0
  67. data/lib/skylight/normalizers/graphiti/resolve.rb +31 -0
  68. data/lib/skylight/normalizers/graphql/base.rb +127 -0
  69. data/lib/skylight/normalizers/render.rb +79 -0
  70. data/lib/skylight/normalizers/sequel/sql.rb +12 -0
  71. data/lib/skylight/normalizers/shrine.rb +32 -0
  72. data/lib/skylight/normalizers/sql.rb +41 -0
  73. data/lib/skylight/normalizers.rb +157 -0
  74. data/lib/skylight/probes/action_controller.rb +52 -0
  75. data/lib/skylight/probes/action_dispatch/request_id.rb +33 -0
  76. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +30 -0
  77. data/lib/skylight/probes/action_dispatch.rb +2 -0
  78. data/lib/skylight/probes/action_view.rb +42 -0
  79. data/lib/skylight/probes/active_job.rb +27 -0
  80. data/lib/skylight/probes/active_job_enqueue.rb +35 -0
  81. data/lib/skylight/probes/active_model_serializers.rb +50 -0
  82. data/lib/skylight/probes/active_record_async.rb +96 -0
  83. data/lib/skylight/probes/delayed_job.rb +144 -0
  84. data/lib/skylight/probes/elasticsearch.rb +45 -0
  85. data/lib/skylight/probes/excon/middleware.rb +65 -0
  86. data/lib/skylight/probes/excon.rb +25 -0
  87. data/lib/skylight/probes/faraday.rb +23 -0
  88. data/lib/skylight/probes/graphql.rb +38 -0
  89. data/lib/skylight/probes/httpclient.rb +44 -0
  90. data/lib/skylight/probes/middleware.rb +135 -0
  91. data/lib/skylight/probes/mongo.rb +169 -0
  92. data/lib/skylight/probes/mongoid.rb +6 -0
  93. data/lib/skylight/probes/net_http.rb +54 -0
  94. data/lib/skylight/probes/rack_builder.rb +37 -0
  95. data/lib/skylight/probes/redis.rb +68 -0
  96. data/lib/skylight/probes/sequel.rb +29 -0
  97. data/lib/skylight/probes/sinatra.rb +66 -0
  98. data/lib/skylight/probes/sinatra_add_middleware.rb +10 -10
  99. data/lib/skylight/probes/tilt.rb +25 -0
  100. data/lib/skylight/probes.rb +172 -0
  101. data/lib/skylight/railtie.rb +172 -15
  102. data/lib/skylight/sidekiq.rb +47 -0
  103. data/lib/skylight/sinatra.rb +2 -2
  104. data/lib/skylight/subscriber.rb +130 -0
  105. data/lib/skylight/test.rb +147 -0
  106. data/lib/skylight/trace.rb +331 -15
  107. data/lib/skylight/user_config.rb +60 -0
  108. data/lib/skylight/util/allocation_free.rb +26 -0
  109. data/lib/skylight/util/clock.rb +57 -0
  110. data/lib/skylight/util/component.rb +47 -9
  111. data/lib/skylight/util/deploy.rb +24 -40
  112. data/lib/skylight/util/gzip.rb +20 -0
  113. data/lib/skylight/util/hostname.rb +4 -4
  114. data/lib/skylight/util/http.rb +62 -71
  115. data/lib/skylight/util/instrumenter_method.rb +26 -0
  116. data/lib/skylight/util/logging.rb +136 -0
  117. data/lib/skylight/util/lru_cache.rb +36 -0
  118. data/lib/skylight/util/platform.rb +74 -0
  119. data/lib/skylight/util/proxy.rb +13 -0
  120. data/lib/skylight/util/ssl.rb +4 -28
  121. data/lib/skylight/util.rb +12 -0
  122. data/lib/skylight/vendor/cli/thor/rake_compat.rb +1 -1
  123. data/lib/skylight/version.rb +5 -1
  124. data/lib/skylight/vm/gc.rb +60 -0
  125. data/lib/skylight.rb +213 -24
  126. metadata +171 -53
@@ -86,14 +86,6 @@ typedef void* (*blocking_fn_t)(void*);
86
86
  #define WITHOUT_GVL(fn, a) \
87
87
  rb_thread_call_without_gvl((blocking_fn_t)(fn), (a), 0, 0)
88
88
 
89
- // Ruby 1.9
90
- #elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
91
-
92
- typedef VALUE (*blocking_fn_t)(void*);
93
- #define WITHOUT_GVL(fn, a) \
94
- rb_thread_blocking_region((blocking_fn_t)(fn), (a), 0, 0)
95
-
96
-
97
89
  #endif
98
90
 
99
91
 
@@ -103,7 +95,6 @@ typedef VALUE (*blocking_fn_t)(void*);
103
95
 
104
96
  VALUE rb_mSkylight;
105
97
  VALUE rb_eNativeError;
106
- VALUE rb_mCore;
107
98
  VALUE rb_mUtil;
108
99
  VALUE rb_cClock;
109
100
  VALUE rb_cTrace;
@@ -140,7 +131,7 @@ load_libskylight(VALUE klass, VALUE path) {
140
131
 
141
132
  /*
142
133
  *
143
- * class Skylight::Core::Util::Clock
134
+ * class Skylight::Util::Clock
144
135
  *
145
136
  */
146
137
 
@@ -152,7 +143,7 @@ clock_high_res_time(VALUE self) {
152
143
 
153
144
  /*
154
145
  *
155
- * class Skylight::Core::Instrumenter
146
+ * class Skylight::Instrumenter
156
147
  *
157
148
  */
158
149
 
@@ -243,33 +234,9 @@ instrumenter_submit_trace(VALUE self, VALUE rb_trace) {
243
234
  return Qnil;
244
235
  }
245
236
 
246
- static VALUE
247
- instrumenter_track_desc(VALUE self, VALUE rb_endpoint, VALUE rb_desc) {
248
- int tracked;
249
- sky_instrumenter_t* instrumenter;
250
-
251
- CHECK_TYPE(rb_endpoint, T_STRING);
252
- CHECK_TYPE(rb_desc, T_STRING);
253
-
254
- tracked = 0;
255
-
256
- My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
257
-
258
- CHECK_FFI(
259
- sky_instrumenter_track_desc(instrumenter, STR2BUF(rb_endpoint), STR2BUF(rb_desc), &tracked),
260
- "Instrumenter#native_track_desc");
261
-
262
- if (tracked) {
263
- return Qtrue;
264
- }
265
- else {
266
- return Qfalse;
267
- }
268
- }
269
-
270
237
  /*
271
238
  *
272
- * class Skylight::Core::Trace
239
+ * class Skylight::Trace
273
240
  *
274
241
  */
275
242
 
@@ -334,6 +301,34 @@ trace_set_endpoint(VALUE self, VALUE endpoint) {
334
301
  return Qnil;
335
302
  }
336
303
 
304
+ static VALUE
305
+ trace_get_component(VALUE self) {
306
+ sky_trace_t* trace;
307
+ sky_buf_t component;
308
+
309
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
310
+
311
+ CHECK_FFI(
312
+ sky_trace_component(trace, &component),
313
+ "Trace#native_get_component");
314
+
315
+ return BUF2STR(component);
316
+ }
317
+
318
+ static VALUE
319
+ trace_set_component(VALUE self, VALUE component) {
320
+ sky_trace_t* trace;
321
+
322
+ CHECK_TYPE(component, T_STRING);
323
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
324
+
325
+ CHECK_FFI(
326
+ sky_trace_set_component(trace, STR2BUF(component)),
327
+ "Trace#native_set_component");
328
+
329
+ return Qnil;
330
+ }
331
+
337
332
  static VALUE
338
333
  trace_use_pruning(VALUE self) {
339
334
  sky_trace_t* trace;
@@ -475,15 +470,31 @@ trace_span_set_description(VALUE self, VALUE span, VALUE desc) {
475
470
 
476
471
  static VALUE
477
472
  trace_span_set_meta(VALUE self, VALUE span, VALUE meta) {
478
- UNUSED(self);
479
- UNUSED(span);
480
- UNUSED(meta);
473
+ sky_trace_t* trace;
474
+ VALUE rb_source_location;
475
+
476
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
477
+
478
+ CHECK_TYPE(span, T_FIXNUM);
479
+ CHECK_TYPE(meta, T_HASH);
480
+
481
+ rb_source_location = rb_hash_lookup(meta, ID2SYM(rb_intern("source_location")));
482
+ if (rb_source_location != Qnil) {
483
+ sky_buf_t source_location;
484
+
485
+ CHECK_TYPE(rb_source_location, T_STRING);
486
+ source_location = STR2BUF(rb_source_location);
487
+
488
+ sky_trace_span_add_string_annotation(trace, FIX2UINT(span), 3, source_location);
489
+ }
490
+
481
491
  return Qnil;
482
492
  }
483
493
 
484
494
  static VALUE
485
- trace_span_started(VALUE self) {
495
+ trace_span_started(VALUE self, VALUE span) {
486
496
  UNUSED(self);
497
+ UNUSED(span);
487
498
  return Qnil;
488
499
  }
489
500
 
@@ -496,79 +507,25 @@ trace_span_set_exception(VALUE self, VALUE span, VALUE exception, VALUE exceptio
496
507
  return Qnil;
497
508
  }
498
509
 
499
- static VALUE
500
- trace_span_get_correlation_header(VALUE self, VALUE span_id) {
501
- UNUSED(self);
502
- UNUSED(span_id);
503
- return Qnil;
504
- }
505
-
506
- static VALUE
507
- lex_sql(VALUE klass, VALUE rb_sql) {
508
- sky_buf_t sql;
509
- sky_buf_t title;
510
- sky_buf_t statement;
511
- uint8_t title_store[128];
512
- VALUE rb_statement;
513
- VALUE ret;
514
-
515
- UNUSED(klass);
516
- CHECK_TYPE(rb_sql, T_STRING);
517
-
518
- sql = STR2BUF(rb_sql);
519
- title = (sky_buf_t) {
520
- .data = title_store,
521
- .len = sizeof(title_store),
522
- };
523
-
524
- // The statement cannot be longer than the original sql string
525
- rb_statement = rb_str_buf_new(RSTRING_LEN(rb_sql));
526
- statement = (sky_buf_t) {
527
- .data = RSTRING_PTR(rb_statement),
528
- .len = RSTRING_LEN(rb_sql),
529
- };
530
-
531
- CHECK_FFI(sky_lex_sql(sql, &title, &statement),
532
- "Skylight#lex_sql");
533
-
534
- // Set the statement return
535
- rb_str_set_len(rb_statement, statement.len);
536
- rb_enc_associate(rb_statement, rb_utf8_encoding());
537
-
538
- ret = rb_ary_new2(2);
539
-
540
- if (title.len > 0) {
541
- rb_ary_store(ret, 0, BUF2STR(title));
542
- }
543
- else {
544
- rb_ary_store(ret, 0, Qnil);
545
- }
546
-
547
- rb_ary_store(ret, 1, rb_statement);
548
-
549
- return ret;
550
- }
551
-
552
510
  void Init_skylight_native() {
553
511
  rb_mSkylight = rb_define_module("Skylight");
554
512
 
555
513
  rb_eNativeError = rb_const_get(rb_mSkylight, rb_intern("NativeError"));
556
514
 
557
515
  rb_define_singleton_method(rb_mSkylight, "load_libskylight", load_libskylight, 1);
558
- rb_define_singleton_method(rb_mSkylight, "lex_sql", lex_sql, 1);
559
-
560
- rb_mCore = rb_define_module_under(rb_mSkylight, "Core");
561
516
 
562
- // FIXME: Don't put these under Core
563
- rb_mUtil = rb_define_module_under(rb_mCore, "Util");
517
+ rb_mUtil = rb_define_module_under(rb_mSkylight, "Util");
564
518
  rb_cClock = rb_define_class_under(rb_mUtil, "Clock", rb_cObject);
565
519
  rb_define_method(rb_cClock, "native_hrtime", clock_high_res_time, 0);
566
520
 
567
521
  rb_cTrace = rb_const_get(rb_mSkylight, rb_intern("Trace"));
568
522
  rb_define_singleton_method(rb_cTrace, "native_new", trace_new, 4);
523
+ rb_undef_alloc_func(rb_cTrace);
569
524
  rb_define_method(rb_cTrace, "native_get_started_at", trace_get_started_at, 0);
570
525
  rb_define_method(rb_cTrace, "native_get_endpoint", trace_get_endpoint, 0);
571
526
  rb_define_method(rb_cTrace, "native_set_endpoint", trace_set_endpoint, 1);
527
+ rb_define_method(rb_cTrace, "native_get_component", trace_get_component, 0);
528
+ rb_define_method(rb_cTrace, "native_set_component", trace_set_component, 1);
572
529
  rb_define_method(rb_cTrace, "native_use_pruning", trace_use_pruning, 0);
573
530
  rb_define_method(rb_cTrace, "native_set_exception", trace_set_exception, 1);
574
531
  rb_define_method(rb_cTrace, "native_get_uuid", trace_get_uuid, 0);
@@ -581,12 +538,11 @@ void Init_skylight_native() {
581
538
  rb_define_method(rb_cTrace, "native_span_set_meta", trace_span_set_meta, 2);
582
539
  rb_define_method(rb_cTrace, "native_span_started", trace_span_started, 1);
583
540
  rb_define_method(rb_cTrace, "native_span_set_exception", trace_span_set_exception, 3);
584
- rb_define_method(rb_cTrace, "native_span_get_correlation_header", trace_span_get_correlation_header, 1);
585
541
 
586
542
  rb_cInstrumenter = rb_const_get(rb_mSkylight, rb_intern("Instrumenter"));
587
543
  rb_define_singleton_method(rb_cInstrumenter, "native_new", instrumenter_new, 2);
544
+ rb_undef_alloc_func(rb_cInstrumenter);
588
545
  rb_define_method(rb_cInstrumenter, "native_start", instrumenter_start, 0);
589
546
  rb_define_method(rb_cInstrumenter, "native_stop", instrumenter_stop, 0);
590
547
  rb_define_method(rb_cInstrumenter, "native_submit_trace", instrumenter_submit_trace, 1);
591
- rb_define_method(rb_cInstrumenter, "native_track_desc", instrumenter_track_desc, 2);
592
548
  }
data/lib/skylight/api.rb CHANGED
@@ -1,16 +1,22 @@
1
- require 'uri'
2
- require 'skylight/util/http'
1
+ require "uri"
2
+ require "skylight/util/http"
3
3
 
4
4
  module Skylight
5
5
  # @api private
6
6
  class Api
7
- include Core::Util::Logging
7
+ include Util::Logging
8
8
 
9
9
  attr_reader :config
10
10
 
11
- class Error < StandardError; end
12
- class Unauthorized < Error; end
13
- class Conflict < Error; end
11
+ class Error < StandardError
12
+ end
13
+
14
+ class Unauthorized < Error
15
+ end
16
+
17
+ class Conflict < Error
18
+ end
19
+
14
20
  class CreateFailed < Error
15
21
  attr_reader :res
16
22
 
@@ -21,14 +27,15 @@ module Skylight
21
27
 
22
28
  def errors
23
29
  return unless res.respond_to?(:body) && res.body.is_a?(Hash)
24
- res.body['errors']
30
+
31
+ res.body["errors"]
25
32
  end
26
33
 
27
34
  def to_s
28
35
  if errors
29
36
  errors.inspect
30
37
  elsif res
31
- "#{res.class.to_s}: #{res.to_s}"
38
+ "#{res.class}: #{res}"
32
39
  else
33
40
  super
34
41
  end
@@ -36,8 +43,7 @@ module Skylight
36
43
  end
37
44
 
38
45
  class ConfigValidationResults
39
-
40
- include Core::Util::Logging
46
+ include Util::Logging
41
47
 
42
48
  attr_reader :raw_response
43
49
 
@@ -46,7 +52,7 @@ module Skylight
46
52
  @raw_response = raw_response
47
53
  end
48
54
 
49
- def is_error_response?
55
+ def error_response?
50
56
  raw_response.is_a?(Util::HTTP::ErrorResponse) || status > 499
51
57
  end
52
58
 
@@ -55,7 +61,7 @@ module Skylight
55
61
  end
56
62
 
57
63
  def body
58
- return nil if is_error_response?
64
+ return nil if error_response?
59
65
 
60
66
  unless raw_response.body.is_a?(Hash)
61
67
  warn("Unable to parse server response: status=%s, body=%s", raw_response.status, raw_response.body)
@@ -67,11 +73,15 @@ module Skylight
67
73
 
68
74
  def token_valid?
69
75
  # Don't prevent boot if it's an error response, so assume token is valid
70
- return true if is_error_response?
76
+ return true if error_response?
77
+
71
78
  # A 2xx response means everything is good!
72
79
  return true if raw_response.success?
73
- # A 422 means an invalid config, but the token must be valid if we got this far
74
- return true if status === 422
80
+ return false if status == 401
81
+
82
+ # A 403/422 means an invalid config,
83
+ # but the token must be valid if we got this far
84
+ true
75
85
  end
76
86
 
77
87
  def config_valid?
@@ -79,44 +89,50 @@ module Skylight
79
89
  raw_response.success?
80
90
  end
81
91
 
92
+ def forbidden?
93
+ status == 403
94
+ end
95
+
82
96
  def validation_errors
83
- return if config_valid?
84
- body ? body['errors'] : nil
97
+ return {} if config_valid? || !body
98
+
99
+ body["errors"]
85
100
  end
86
101
 
87
102
  def corrected_config
88
- return if config_valid?
89
- body ? body['corrected'] : nil
90
- end
103
+ return nil if config_valid? || !body
91
104
 
105
+ body["corrected"]
106
+ end
92
107
  end
93
108
 
94
109
  def initialize(config)
95
110
  @config = config
96
111
  end
97
112
 
98
- def create_app(name, token=nil)
113
+ def create_app(name, token = nil)
99
114
  params = { app: { name: name } }
100
115
  params[:token] = token if token
101
116
 
102
117
  res = http_request(:app_create, :post, params)
103
118
 
104
119
  raise CreateFailed, res unless res.success?
120
+
105
121
  res
106
122
  end
107
123
 
108
124
  def fetch_mergeable_apps(token)
109
- headers = { 'x-skylight-merge-token' => token }
125
+ headers = { "x-skylight-merge-token" => token }
110
126
  http_request(:merges, :get, headers).tap do |res|
111
- raise error_for_status(res.status).new("HTTP #{res.status}: #{res.body}") unless res.success?
127
+ raise error_for_status(res.status), "HTTP #{res.status}: #{res.body}" unless res.success?
112
128
  end
113
129
  end
114
130
 
115
131
  def merge_apps!(token, app_guid:, component_guid:, environment:)
116
- headers = { 'x-skylight-merge-token' => token }
132
+ headers = { "x-skylight-merge-token" => token }
117
133
  body = { environment: environment, app_guid: app_guid, component_guid: component_guid }
118
134
  http_request(:merges, :post, body, headers).tap do |res|
119
- raise error_for_status(res.status).new("HTTP #{res.status}: #{res.body}") unless res.success?
135
+ raise error_for_status(res.status), "HTTP #{res.status}: #{res.body}" unless res.success?
120
136
  end
121
137
  end
122
138
 
@@ -144,7 +160,5 @@ module Skylight
144
160
  Error
145
161
  end
146
162
  end
147
-
148
163
  end
149
-
150
164
  end
@@ -1,4 +1,4 @@
1
- require 'skylight/util/http'
1
+ require "skylight/util/http"
2
2
 
3
3
  module Skylight
4
4
  module CLI
@@ -20,11 +20,13 @@ module Skylight
20
20
  say "Failed to verify SSL certificate.", :red
21
21
  if Util::SSL.ca_cert_file?
22
22
  say "Certificates located at #{Util::SSL.ca_cert_file_or_default} may be out of date.", :yellow
23
- if is_mac? && has_rvm?
23
+ if mac? && rvm_present?
24
24
  say "Please update your certificates with RVM by running `rvm osx-ssl-certs update all`.", :yellow
25
25
  say "Alternatively, try setting `SKYLIGHT_FORCE_OWN_CERTS=1` in your environment.", :yellow
26
26
  else
27
- say "Please update your local certificates or try setting `SKYLIGHT_FORCE_OWN_CERTS=1` in your environment.", :yellow
27
+ say "Please update your local certificates or try setting `SKYLIGHT_FORCE_OWN_CERTS=1` in your " \
28
+ "environment.",
29
+ :yellow
28
30
  end
29
31
  end
30
32
  else
@@ -39,7 +41,7 @@ module Skylight
39
41
  say "Checking for Rails"
40
42
 
41
43
  indent do
42
- if is_rails?
44
+ if rails?
43
45
  say "Rails application detected", :green
44
46
  else
45
47
  say "No Rails application detected", :yellow
@@ -63,11 +65,9 @@ module Skylight
63
65
  say "Unable to load native extension", :yellow
64
66
 
65
67
  indent do
66
- install_log = File.expand_path("../../../ext/install.log", __FILE__)
68
+ install_log = File.expand_path("../../../ext/install.log", __dir__)
67
69
  if File.exist?(install_log)
68
- File.readlines(install_log).each do |line|
69
- say line, :red
70
- end
70
+ File.readlines(install_log).each { |line| say line, :red }
71
71
  else
72
72
  say "Reason unknown", :red
73
73
  end
@@ -84,20 +84,18 @@ module Skylight
84
84
  say "Checking for valid configuration"
85
85
 
86
86
  indent do
87
- begin
88
- config.validate!
89
- say "Configuration is valid", :green
90
- rescue Core::ConfigError => e
91
- encountered_error!
92
-
93
- say "Configuration is invalid", :red
94
- indent do
95
- say e.message, :red
96
- say "This may occur if you are configuring with ENV variables and didn't set them in this shell."
97
- end
98
-
99
- done!
87
+ config.validate!
88
+ say "Configuration is valid", :green
89
+ rescue ConfigError => e
90
+ encountered_error!
91
+
92
+ say "Configuration is invalid", :red
93
+ indent do
94
+ say e.message, :red
95
+ say "This may occur if you are configuring with ENV variables and didn't set them in this shell."
100
96
  end
97
+
98
+ done!
101
99
  end
102
100
 
103
101
  puts "\n"
@@ -109,16 +107,19 @@ module Skylight
109
107
  indent do
110
108
  # Set this after we validate. It will give us more detailed information on start.
111
109
  logger = Logger.new("/dev/null") # Rely on `say` in the formatter instead
110
+
112
111
  # Log everything
113
112
  logger.level = Logger::DEBUG
113
+
114
114
  # Remove excess formatting
115
- logger.formatter = proc { |severity, datetime, progname, msg|
116
- msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ", '')
117
- say "#{severity} - #{msg}" # Definitely non-standard
118
- }
115
+ logger.formatter =
116
+ proc do |severity, _datetime, _progname, msg|
117
+ msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ", "")
118
+ say "#{severity} - #{msg}" # Definitely non-standard
119
+ end
119
120
  config.logger = logger
120
121
 
121
- config.set(:'daemon.lazy_start', false)
122
+ config.set(:"daemon.lazy_start", false)
122
123
 
123
124
  started = Skylight.start!(config)
124
125
 
@@ -139,7 +140,7 @@ module Skylight
139
140
  daemon_running = false
140
141
  while tries < 5
141
142
  `ps cax | grep skylightd`
142
- if $?.success?
143
+ if $CHILD_STATUS.success?
143
144
  daemon_running = true
144
145
  break
145
146
  end
@@ -166,58 +167,55 @@ module Skylight
166
167
 
167
168
  private
168
169
 
169
- # Overwrite the default helper method to load from Rails
170
- def config
171
- return @config if @config
170
+ # Overwrite the default helper method to load from Rails
171
+ def config
172
+ return @config if @config
172
173
 
173
- # MEGAHAX
174
- if is_rails?
175
- # Normally auto-loaded, but we haven't loaded Rails by the time Skylight is loaded
176
- require 'skylight/railtie'
177
- require rails_rb
178
-
179
- railtie = Skylight::Railtie.send(:new)
180
- @config = railtie.send(:load_skylight_config, Rails.application)
181
- else
182
- super
183
- end
184
- end
174
+ # MEGAHAX
175
+ if rails?
176
+ # Normally auto-loaded, but we haven't loaded Rails by the time Skylight is loaded
177
+ require "skylight/railtie"
178
+ require rails_rb
185
179
 
186
- def is_mac?
187
- Core::Util::Platform::OS == 'darwin'
180
+ railtie = Skylight::Railtie.send(:new)
181
+ @config = railtie.send(:load_skylight_config, Rails.application)
182
+ else
183
+ super
188
184
  end
185
+ end
189
186
 
190
- # NOTE: This check won't work correctly on Windows
191
- def has_rvm?
192
- if @has_rvm.nil?
193
- @has_rvm = system("which rvm > /dev/null");
194
- end
195
- @has_rvm
196
- end
187
+ def mac?
188
+ Util::Platform::OS == "darwin"
189
+ end
197
190
 
198
- def encountered_error!
199
- @has_errors = true
200
- end
191
+ # NOTE: This check won't work correctly on Windows
192
+ def rvm_present?
193
+ @has_rvm = system("which rvm > /dev/null") if @has_rvm.nil?
194
+ @has_rvm
195
+ end
201
196
 
202
- def has_errors?
203
- @has_errors
204
- end
197
+ def encountered_error!
198
+ @has_errors = true
199
+ end
205
200
 
206
- def done!
207
- shell.padding = 0
208
- say "\n\n"
201
+ def has_errors?
202
+ @has_errors
203
+ end
209
204
 
210
- if has_errors?
211
- say "Skylight Doctor found some errors. Please review the output above.", :red
212
- say "If you have any further questions, please contact support@skylight.io.", :yellow
213
- exit 1
214
- else
215
- say "All checks passed!", :green
216
- say "If you're still having trouble, please contact support@skylight.io.", :yellow
217
- exit 0
218
- end
205
+ def done!
206
+ shell.padding = 0
207
+ say "\n\n"
208
+
209
+ if has_errors?
210
+ say "Skylight Doctor found some errors. Please review the output above.", :red
211
+ say "If you have any further questions, please contact support@skylight.io.", :yellow
212
+ exit 1
213
+ else
214
+ say "All checks passed!", :green
215
+ say "If you're still having trouble, please contact support@skylight.io.", :yellow
216
+ exit 0
219
217
  end
220
-
218
+ end
221
219
  end
222
220
  end
223
221
  end
@@ -1,7 +1,6 @@
1
1
  module Skylight
2
2
  module CLI
3
3
  module Helpers
4
-
5
4
  private
6
5
 
7
6
  # Duplicated below
@@ -9,7 +8,7 @@ module Skylight
9
8
  File.expand_path("config/application.rb")
10
9
  end
11
10
 
12
- def is_rails?
11
+ def rails?
13
12
  File.exist?(rails_rb)
14
13
  end
15
14
 
@@ -20,13 +19,12 @@ module Skylight
20
19
 
21
20
  # Sets the output padding while executing a block and resets it.
22
21
  #
23
- def indent(count = 1, &block)
22
+ def indent(count = 1)
24
23
  orig_padding = shell.padding
25
24
  shell.padding += count
26
25
  yield
27
26
  shell.padding = orig_padding
28
27
  end
29
-
30
28
  end
31
29
  end
32
- end
30
+ end