skylight 1.7.2 → 2.0.0.beta1

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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -33
  3. data/ext/extconf.rb +32 -6
  4. data/ext/libskylight.yml +6 -9
  5. data/ext/skylight_native.c +49 -18
  6. data/lib/skylight.rb +35 -1
  7. data/lib/skylight/api.rb +4 -2
  8. data/lib/skylight/cli.rb +1 -1
  9. data/lib/skylight/cli/doctor.rb +6 -4
  10. data/lib/skylight/config.rb +149 -518
  11. data/lib/skylight/data/cacert.pem +236 -812
  12. data/lib/skylight/helpers.rb +5 -1
  13. data/lib/skylight/instrumenter.rb +10 -241
  14. data/lib/skylight/middleware.rb +1 -89
  15. data/lib/skylight/native.rb +8 -6
  16. data/lib/skylight/native_ext_fetcher.rb +251 -0
  17. data/lib/skylight/normalizers/active_job/enqueue_at.rb +2 -20
  18. data/lib/skylight/probes/sinatra_add_middleware.rb +22 -0
  19. data/lib/skylight/railtie.rb +11 -131
  20. data/lib/skylight/sinatra.rb +1 -5
  21. data/lib/skylight/trace.rb +1 -229
  22. data/lib/skylight/util/http.rb +3 -3
  23. data/lib/skylight/vendor/cli/thor/actions/directory.rb +5 -15
  24. data/lib/skylight/version.rb +1 -1
  25. metadata +114 -91
  26. data/lib/skylight/compat.rb +0 -76
  27. data/lib/skylight/core.rb +0 -149
  28. data/lib/skylight/deprecation.rb +0 -55
  29. data/lib/skylight/formatters/http.rb +0 -20
  30. data/lib/skylight/gc.rb +0 -107
  31. data/lib/skylight/normalizers.rb +0 -192
  32. data/lib/skylight/normalizers/action_controller/process_action.rb +0 -50
  33. data/lib/skylight/normalizers/action_controller/send_file.rb +0 -50
  34. data/lib/skylight/normalizers/action_view/render_collection.rb +0 -22
  35. data/lib/skylight/normalizers/action_view/render_partial.rb +0 -21
  36. data/lib/skylight/normalizers/action_view/render_template.rb +0 -21
  37. data/lib/skylight/normalizers/active_model_serializers/render.rb +0 -26
  38. data/lib/skylight/normalizers/active_record/instantiation.rb +0 -17
  39. data/lib/skylight/normalizers/active_record/sql.rb +0 -55
  40. data/lib/skylight/normalizers/active_support/cache.rb +0 -51
  41. data/lib/skylight/normalizers/active_support/cache_clear.rb +0 -16
  42. data/lib/skylight/normalizers/active_support/cache_decrement.rb +0 -16
  43. data/lib/skylight/normalizers/active_support/cache_delete.rb +0 -16
  44. data/lib/skylight/normalizers/active_support/cache_exist.rb +0 -16
  45. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +0 -16
  46. data/lib/skylight/normalizers/active_support/cache_generate.rb +0 -16
  47. data/lib/skylight/normalizers/active_support/cache_increment.rb +0 -16
  48. data/lib/skylight/normalizers/active_support/cache_read.rb +0 -16
  49. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +0 -16
  50. data/lib/skylight/normalizers/active_support/cache_write.rb +0 -16
  51. data/lib/skylight/normalizers/coach/handler_finish.rb +0 -36
  52. data/lib/skylight/normalizers/coach/middleware_finish.rb +0 -23
  53. data/lib/skylight/normalizers/couch_potato/query.rb +0 -20
  54. data/lib/skylight/normalizers/default.rb +0 -27
  55. data/lib/skylight/normalizers/elasticsearch/request.rb +0 -20
  56. data/lib/skylight/normalizers/faraday/request.rb +0 -38
  57. data/lib/skylight/normalizers/grape/endpoint.rb +0 -30
  58. data/lib/skylight/normalizers/grape/endpoint_render.rb +0 -26
  59. data/lib/skylight/normalizers/grape/endpoint_run.rb +0 -33
  60. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +0 -23
  61. data/lib/skylight/normalizers/moped/query.rb +0 -100
  62. data/lib/skylight/probes.rb +0 -129
  63. data/lib/skylight/probes/action_controller.rb +0 -64
  64. data/lib/skylight/probes/action_dispatch.rb +0 -30
  65. data/lib/skylight/probes/action_view.rb +0 -43
  66. data/lib/skylight/probes/active_model_serializers.rb +0 -55
  67. data/lib/skylight/probes/elasticsearch.rb +0 -37
  68. data/lib/skylight/probes/excon.rb +0 -26
  69. data/lib/skylight/probes/excon/middleware.rb +0 -68
  70. data/lib/skylight/probes/faraday.rb +0 -22
  71. data/lib/skylight/probes/grape.rb +0 -88
  72. data/lib/skylight/probes/httpclient.rb +0 -46
  73. data/lib/skylight/probes/middleware.rb +0 -68
  74. data/lib/skylight/probes/mongo.rb +0 -161
  75. data/lib/skylight/probes/mongoid.rb +0 -21
  76. data/lib/skylight/probes/moped.rb +0 -39
  77. data/lib/skylight/probes/net_http.rb +0 -58
  78. data/lib/skylight/probes/redis.rb +0 -71
  79. data/lib/skylight/probes/sequel.rb +0 -37
  80. data/lib/skylight/probes/sinatra.rb +0 -76
  81. data/lib/skylight/probes/tilt.rb +0 -31
  82. data/lib/skylight/subscriber.rb +0 -122
  83. data/lib/skylight/user_config.rb +0 -60
  84. data/lib/skylight/util.rb +0 -17
  85. data/lib/skylight/util/allocation_free.rb +0 -26
  86. data/lib/skylight/util/clock.rb +0 -54
  87. data/lib/skylight/util/deploy.rb +0 -132
  88. data/lib/skylight/util/gzip.rb +0 -21
  89. data/lib/skylight/util/inflector.rb +0 -112
  90. data/lib/skylight/util/logging.rb +0 -127
  91. data/lib/skylight/util/multi_io.rb +0 -21
  92. data/lib/skylight/util/native_ext_fetcher.rb +0 -253
  93. data/lib/skylight/util/platform.rb +0 -75
  94. data/lib/skylight/util/proxy.rb +0 -13
  95. data/lib/skylight/vendor/active_support/notifications.rb +0 -207
  96. data/lib/skylight/vendor/active_support/notifications/fanout.rb +0 -159
  97. data/lib/skylight/vendor/active_support/notifications/instrumenter.rb +0 -72
  98. data/lib/skylight/vendor/active_support/per_thread_registry.rb +0 -52
  99. data/lib/skylight/vendor/thread_safe.rb +0 -126
  100. data/lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb +0 -133
  101. data/lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb +0 -76
  102. data/lib/skylight/vm/gc.rb +0 -70
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38b118d85b7e46213e2514bbaa79fea48031adab3189a911220efc8a73d8d193
4
- data.tar.gz: 1c9654be2fe1269c907a39d18621116f62f66f268dd0c137bc6e01ef6aec77e7
3
+ metadata.gz: 257ac0e93ef049212cce0ee890a96265fbc0e6b4cf1b3a0e7e8ddb944ae30fb3
4
+ data.tar.gz: 5a31861bfd7feba873b7c40605acf861ab2b1861b586c0d027d3b3e6d2557b3b
5
5
  SHA512:
6
- metadata.gz: db3dd167fdfe558b82794cfd832f7f35732ad9c63bcf63d6d68645fdce714f4793cb5cfb055668843fd5993806a92bf7233a8093e1b5d4c84580048c253a5cbb
7
- data.tar.gz: 6445f6c23aa6d6fc3ca14dbfb46606756234294806dcd6b92042a7edfc6e2cff586a778c7053ff22a26698c45bb7723903cb7c8954b6aea2e6bdd50b99a5c164
6
+ metadata.gz: ba086a499bb89abbfd796b58093ddac311f610e04f1c29d8e398343daa63c3c879a96cccbb43acb25b411e1bf931f8b3390eb4d2fb83b067f103e2d2e0224b18
7
+ data.tar.gz: 27190de3814b1d7c83775e5cc2e015a85e0fbf211d78ee225bd3bfcbdd9d6b8ba10883926dd3ba4691aab601cc2109c89ee71aaff141eab9e60cc28077ae62f1
@@ -1,41 +1,12 @@
1
- ## 1.7.2 (December 14 2018)
2
- * [BUGFIX] (Backported from 3.1.x series) Fix issue where routes in mounted engines could cause spans to be closed out-of-order.
1
+ ## 2.0.0-beta1
3
2
 
4
- ## 1.7.1 (October 16 2018)
5
- * [BUGFIX] (Backported from 2.x series) Fix issue wherein certain error-handling patterns could break the middleware probe.
6
-
7
- ## 1.7.0 (April 24, 2018)
8
-
9
- * [FEATURE] New API for loading Probes. Example: `Skylight.probe(:excon')`
10
- * [FEATURE] New API for enabling non-default Normalizers. Example: `Skylight.enable_normalizer('active_job')`
11
- * [DEPRECATION] Support for Rails versions prior to 4.2
12
- * [DEPRECATION] Support for Tilt versions prior to 1.4.1
13
- * [DEPRECATION] Support for Sinatra versions prior to 1.4
14
- * [DEPRECATION] Support for Grape versions prior to 0.13.0
15
-
16
- ## 1.6.1 (April 12, 2018)
17
-
18
- * [IMPROVEMENT] Include endpoint name in error logging
19
- * [BUGFIX] Make sure to correctly release broken traces
20
- * [BUGFIX] Keep the `require` method private when overwriting
21
-
22
- ## 1.6.0 (March 21, 2018)
23
-
24
- * [FEATURE] Time spent the Rails router is now identified separately in the trace
25
- * [IMPROVEMENT] Switch logger to debug mode if tracing is enabled
26
- * [IMPROVEMENT] Improved logging for a number of error cases
27
- * [IMPROVEMENT] Middleware probe should now accept anything allowed by Rack::Lint
28
- * [IMPROVEMENT] We were using arity checks to determine Rails version but due to other libraries' monkey patches this could sometimes fail. We just check version numbers now.
29
- * [BUGFIX] Middleware probe no longer errors when Middleware returns a frozen array
30
-
31
- ## 1.5.1 (February 7, 2018)
32
-
33
- * [BUGFIX] `skylight doctor` no longer erroneously reports inability to reach Skylight servers.
3
+ * [FEATURE] New SQL lexer to support a wider variety of SQL queries.
4
+ * [BREAKING] Drop support for a number of deprecated libraries, including Rails prior to 4.2, Ruby prior to 2.2, and Sinatra prior to 1.4.
34
5
 
35
6
  ## 1.5.0 (December 6, 2017)
36
7
 
37
8
  * [FEATURE] [Coach](https://github.com/gocardless/coach) instrumentation. Enabled automatically via ActiveSupport::Notifications.
38
- * [FEATURE] Option to enable or disable agent by setting SKYLIGHT_ENABLED via ENV.
9
+ * [FEATURE] Option to enable or disable agent by setting SKYLIGHT_ENABLE via ENV.
39
10
  * [IMPROVEMENT] Better logging for certain error cases.
40
11
  * [BUGFIX] Backport a SPEC compliance fix for older Rack::ETag to resolve case where the Middleware probe could cause empty traces.
41
12
  * [BUGFIX] Fix a case where using the non-block form of `Skylight.instrument` with `Skylight.done` could cause lost trace data.
@@ -5,12 +5,38 @@ require 'logger'
5
5
  require 'fileutils'
6
6
 
7
7
  $:.unshift File.expand_path("../../lib", __FILE__)
8
+
8
9
  require 'skylight/version'
9
- require 'skylight/util/multi_io'
10
- require 'skylight/util/native_ext_fetcher'
11
- require 'skylight/util/platform'
12
10
 
13
- include Skylight::Util
11
+ # Don't use the gem for dev
12
+ if File.exists?(File.expand_path("../../Gemfile", __FILE__))
13
+ # This approach won't work in production since skylight-core isn't in the skylight gem
14
+ $:.unshift File.expand_path("../../skylight-core/lib", __FILE__)
15
+ else
16
+ # Is there a better way to get this into lib?
17
+ gem 'skylight-core', Skylight::Core::VERSION.tr('-', '.')
18
+ end
19
+
20
+ require 'skylight/native_ext_fetcher'
21
+ require 'skylight/core/util/platform'
22
+
23
+ # Util allowing proxying writes to multiple location
24
+ class MultiIO
25
+
26
+ def initialize(*targets)
27
+ @targets = targets
28
+ end
29
+
30
+ def write(*args)
31
+ @targets.each {|t| t.write(*args)}
32
+ end
33
+
34
+ def close
35
+ @targets.each(&:close)
36
+ end
37
+ end
38
+
39
+ include Skylight::Core::Util
14
40
 
15
41
  SKYLIGHT_INSTALL_LOG = File.expand_path("../install.log", __FILE__)
16
42
  SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV['SKYLIGHT_REQUIRED'] !~ /^false$/i
@@ -126,7 +152,7 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
126
152
  end
127
153
 
128
154
  begin
129
- res = NativeExtFetcher.fetch(
155
+ res = Skylight::NativeExtFetcher.fetch(
130
156
  source: SKYLIGHT_SOURCE_URL,
131
157
  version: version,
132
158
  target: hdrpath,
@@ -220,7 +246,7 @@ $CFLAGS << " -std=c99 -Wall -fno-strict-aliasing"
220
246
 
221
247
  # Allow stricter checks to be turned on for development or debugging
222
248
  if SKYLIGHT_EXT_STRICT
223
- $CFLAGS << " -Wextra"
249
+ $CFLAGS << " -pedantic"
224
250
  end
225
251
 
226
252
  # TODO: Compute the relative path to the location
@@ -1,11 +1,8 @@
1
1
  ---
2
- version: "1.4.0-7aecded"
2
+ version: "2.0.0-7fe2c49"
3
3
  checksums:
4
- x86-linux: "79162dfc4dee8954869d2820e60e8d15d4f4915f66e29bedd15e68030acd5b27"
5
- x86_64-linux: "117ac0ff29240a518717fcf52f7cd3eeec69a135c481693b8eb259bb4c2b528c"
6
- x86_64-linux-musl: "bab4030060eb4b83d0543839e0f51b09545d7d5b20c3f7dd35ae6f81f3189499"
7
- x86_64-darwin: "1c0fdb68c0dde34a1b0842403db2ea2ca6a0de2fb7d729e869f395f6d10383b5"
8
- # Temporarily divergent Rust build for FreeBSD
9
- x86_64-freebsd:
10
- version: "1.4.1-33c50db"
11
- checksum: "c71d958fdba4c6ea1f62aea03474e2b479e787d5e21a436dabf00218ea25d2b0"
4
+ x86-linux: "57e0b65fd5bd03be9ad406711279d6164982107a4af144a85d4a352f035244ff"
5
+ x86_64-linux: "5a2648e000f7b184dfaadd01f37399e808c80826613279571b61e4d7b122118a"
6
+ x86_64-linux-musl: "39fc56d55782af71c8c37f93d1082e05c9a4c0decb68487ea6695d95971985f6"
7
+ x86_64-darwin: "05a68826b7cef60c19d22302ec4f5eaa5134fd3be6d19513f6de76337fccb734"
8
+ x86_64-freebsd: "97f4a65c0ba19cfa236fec73f2fdd74e0df9ae0e12ecec7709c996a3c4eb10f2"
@@ -73,6 +73,7 @@ STR2BUF(VALUE str) {
73
73
  * Ruby GVL helpers
74
74
  */
75
75
 
76
+ // FIXME: This conditional doesn't logically cover every case
76
77
  #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \
77
78
  defined(HAVE_RUBY_THREAD_H)
78
79
 
@@ -98,10 +99,9 @@ typedef VALUE (*blocking_fn_t)(void*);
98
99
  */
99
100
 
100
101
  VALUE rb_mSkylight;
102
+ VALUE rb_mCore;
101
103
  VALUE rb_mUtil;
102
104
  VALUE rb_cClock;
103
- VALUE rb_cTrace;
104
- VALUE rb_cInstrumenter;
105
105
 
106
106
  static const char* no_instrumenter_msg =
107
107
  "Instrumenter not currently running";
@@ -133,7 +133,7 @@ load_libskylight(VALUE klass, VALUE path) {
133
133
 
134
134
  /*
135
135
  *
136
- * class Skylight::Util::Clock
136
+ * class Skylight::Core::Util::Clock
137
137
  *
138
138
  */
139
139
 
@@ -145,7 +145,7 @@ clock_high_res_time(VALUE self) {
145
145
 
146
146
  /*
147
147
  *
148
- * class Skylight::Instrumenter
148
+ * class Skylight::Core::Instrumenter
149
149
  *
150
150
  */
151
151
 
@@ -155,7 +155,6 @@ instrumenter_new(VALUE klass, VALUE rb_env) {
155
155
  sky_buf_t env[256];
156
156
  int i, envc;
157
157
 
158
- UNUSED(klass);
159
158
  CHECK_TYPE(rb_env, T_ARRAY);
160
159
 
161
160
  if (RARRAY_LEN(rb_env) >= 256) {
@@ -178,7 +177,7 @@ instrumenter_new(VALUE klass, VALUE rb_env) {
178
177
  sky_instrumenter_new(env, envc, &instrumenter),
179
178
  "failed to initialize instrumenter");
180
179
 
181
- return Data_Wrap_Struct(rb_cInstrumenter, NULL, sky_instrumenter_free, instrumenter);
180
+ return Data_Wrap_Struct(klass, NULL, sky_instrumenter_free, instrumenter);
182
181
  }
183
182
 
184
183
  static void*
@@ -262,15 +261,16 @@ instrumenter_track_desc(VALUE self, VALUE rb_endpoint, VALUE rb_desc) {
262
261
 
263
262
  /*
264
263
  *
265
- * class Skylight::Trace
264
+ * class Skylight::Core::Trace
266
265
  *
267
266
  */
268
267
 
269
268
  static VALUE
270
- trace_new(VALUE klass, VALUE start, VALUE uuid, VALUE endpoint) {
269
+ trace_new(VALUE klass, VALUE start, VALUE uuid, VALUE endpoint, VALUE meta) {
271
270
  sky_trace_t* trace;
272
271
 
273
- UNUSED(klass);
272
+ UNUSED(meta);
273
+
274
274
  CHECK_NUMERIC(start);
275
275
  CHECK_TYPE(uuid, T_STRING);
276
276
  CHECK_TYPE(endpoint, T_STRING);
@@ -281,7 +281,7 @@ trace_new(VALUE klass, VALUE start, VALUE uuid, VALUE endpoint) {
281
281
 
282
282
  sky_clear_allocation_count();
283
283
 
284
- return Data_Wrap_Struct(rb_cTrace, NULL, sky_trace_free, trace);
284
+ return Data_Wrap_Struct(klass, NULL, sky_trace_free, trace);
285
285
  }
286
286
 
287
287
  static VALUE
@@ -326,6 +326,11 @@ trace_set_endpoint(VALUE self, VALUE endpoint) {
326
326
  return Qnil;
327
327
  }
328
328
 
329
+ static VALUE
330
+ trace_set_exception(VALUE self, VALUE exception) {
331
+ return Qnil;
332
+ }
333
+
329
334
  static VALUE
330
335
  trace_get_uuid(VALUE self) {
331
336
  sky_trace_t* trace;
@@ -414,7 +419,22 @@ trace_span_set_description(VALUE self, VALUE span, VALUE desc) {
414
419
  }
415
420
 
416
421
  static VALUE
417
- lex_sql(VALUE klass, VALUE rb_sql) {
422
+ trace_span_set_meta(VALUE self, VALUE span, VALUE meta) {
423
+ return Qnil;
424
+ }
425
+
426
+ static VALUE
427
+ trace_span_set_exception(VALUE self, VALUE span, VALUE exception, VALUE exception_details) {
428
+ return Qnil;
429
+ }
430
+
431
+ static VALUE
432
+ trace_span_get_correlation_header(VALUE self, VALUE span_id) {
433
+ return Qnil;
434
+ }
435
+
436
+ static VALUE
437
+ lex_sql(VALUE klass, VALUE rb_sql, VALUE rb_use_old_lexer) {
418
438
  sky_buf_t sql;
419
439
  sky_buf_t title;
420
440
  sky_buf_t statement;
@@ -438,9 +458,13 @@ lex_sql(VALUE klass, VALUE rb_sql) {
438
458
  .len = RSTRING_LEN(rb_sql),
439
459
  };
440
460
 
441
- CHECK_FFI(
442
- sky_lex_sql(sql, &title, &statement),
461
+ if (RTEST(rb_use_old_lexer)) {
462
+ CHECK_FFI(sky_lex_sql_old(sql, &title, &statement),
463
+ "native lex_sql_old failed");
464
+ } else {
465
+ CHECK_FFI(sky_lex_sql(sql, &title, &statement),
443
466
  "native lex_sql failed");
467
+ }
444
468
 
445
469
  // Set the statement return
446
470
  rb_str_set_len(rb_statement, statement.len);
@@ -463,24 +487,31 @@ lex_sql(VALUE klass, VALUE rb_sql) {
463
487
  void Init_skylight_native() {
464
488
  rb_mSkylight = rb_define_module("Skylight");
465
489
  rb_define_singleton_method(rb_mSkylight, "load_libskylight", load_libskylight, 1);
466
- rb_define_singleton_method(rb_mSkylight, "lex_sql", lex_sql, 1);
490
+ rb_define_singleton_method(rb_mSkylight, "lex_sql", lex_sql, 2);
491
+
492
+ rb_mCore = rb_define_module_under(rb_mSkylight, "Core");
467
493
 
468
- rb_mUtil = rb_define_module_under(rb_mSkylight, "Util");
494
+ // FIXME: Don't put these under Core
495
+ rb_mUtil = rb_define_module_under(rb_mCore, "Util");
469
496
  rb_cClock = rb_define_class_under(rb_mUtil, "Clock", rb_cObject);
470
497
  rb_define_method(rb_cClock, "native_hrtime", clock_high_res_time, 0);
471
498
 
472
- rb_cTrace = rb_define_class_under(rb_mSkylight, "Trace", rb_cObject);
473
- rb_define_singleton_method(rb_cTrace, "native_new", trace_new, 3);
499
+ VALUE rb_cTrace = rb_const_get(rb_mSkylight, rb_intern("Trace"));
500
+ rb_define_singleton_method(rb_cTrace, "native_new", trace_new, 4);
474
501
  rb_define_method(rb_cTrace, "native_get_started_at", trace_get_started_at, 0);
475
502
  rb_define_method(rb_cTrace, "native_get_endpoint", trace_get_endpoint, 0);
476
503
  rb_define_method(rb_cTrace, "native_set_endpoint", trace_set_endpoint, 1);
504
+ rb_define_method(rb_cTrace, "native_set_exception", trace_set_exception, 1);
477
505
  rb_define_method(rb_cTrace, "native_get_uuid", trace_get_uuid, 0);
478
506
  rb_define_method(rb_cTrace, "native_start_span", trace_start_span, 2);
479
507
  rb_define_method(rb_cTrace, "native_stop_span", trace_stop_span, 2);
480
508
  rb_define_method(rb_cTrace, "native_span_set_title", trace_span_set_title, 2);
481
509
  rb_define_method(rb_cTrace, "native_span_set_description", trace_span_set_description, 2);
510
+ rb_define_method(rb_cTrace, "native_span_set_meta", trace_span_set_meta, 2);
511
+ rb_define_method(rb_cTrace, "native_span_set_exception", trace_span_set_exception, 3);
512
+ rb_define_method(rb_cTrace, "native_span_get_correlation_header", trace_span_get_correlation_header, 1);
482
513
 
483
- rb_cInstrumenter = rb_define_class_under(rb_mSkylight, "Instrumenter", rb_cObject);
514
+ VALUE rb_cInstrumenter = rb_const_get(rb_mSkylight, rb_intern("Instrumenter"));
484
515
  rb_define_singleton_method(rb_cInstrumenter, "native_new", instrumenter_new, 1);
485
516
  rb_define_method(rb_cInstrumenter, "native_start", instrumenter_start, 0);
486
517
  rb_define_method(rb_cInstrumenter, "native_stop", instrumenter_stop, 0);
@@ -1,2 +1,36 @@
1
+ require 'skylight/version'
1
2
  require 'skylight/core'
2
- require 'skylight/probes'
3
+ require 'skylight/trace'
4
+ require 'skylight/instrumenter'
5
+ require 'skylight/middleware'
6
+ require 'skylight/api'
7
+ require 'skylight/helpers'
8
+ require 'skylight/config'
9
+ require 'skylight/native'
10
+
11
+ module Skylight
12
+ # Used from the CLI
13
+ autoload :CLI, 'skylight/cli'
14
+
15
+ # Specifically check for Railtie since we've had at least one case of a
16
+ # customer having Rails defined without having all of Rails loaded.
17
+ if defined?(Rails::Railtie)
18
+ require 'skylight/railtie'
19
+ end
20
+
21
+ include Core::Instrumentable
22
+
23
+ def self.instrumenter_class
24
+ Instrumenter
25
+ end
26
+
27
+ def self.config_class
28
+ Config
29
+ end
30
+
31
+ # Install probes
32
+ def self.probe(*probes)
33
+ Core::Probes.probe(*probes)
34
+ end
35
+
36
+ end
@@ -1,9 +1,10 @@
1
1
  require 'uri'
2
+ require 'skylight/util/http'
2
3
 
3
4
  module Skylight
4
5
  # @api private
5
6
  class Api
6
- include Util::Logging
7
+ include Core::Util::Logging
7
8
 
8
9
  attr_reader :config
9
10
 
@@ -33,7 +34,7 @@ module Skylight
33
34
 
34
35
  class ConfigValidationResults
35
36
 
36
- include Util::Logging
37
+ include Core::Util::Logging
37
38
 
38
39
  attr_reader :raw_response
39
40
 
@@ -116,4 +117,5 @@ module Skylight
116
117
  end
117
118
 
118
119
  end
120
+
119
121
  end
@@ -128,7 +128,7 @@ you should set the `SKYLIGHT_AUTHENTICATION` variable to:
128
128
  end
129
129
 
130
130
  def api
131
- config.api
131
+ @api ||= Api.new(config)
132
132
  end
133
133
 
134
134
  def user_config
@@ -1,3 +1,5 @@
1
+ require 'skylight/util/http'
2
+
1
3
  module Skylight
2
4
  module CLI
3
5
  class Doctor < Thor::Group
@@ -9,7 +11,7 @@ module Skylight
9
11
  say "Checking SSL"
10
12
  http = Util::HTTP.new(config)
11
13
  indent do
12
- req = http.get("/status")
14
+ req = http.get("/", "Accept" => "text/html")
13
15
  if req.success?
14
16
  say "OK", :green
15
17
  else
@@ -85,7 +87,7 @@ module Skylight
85
87
  begin
86
88
  config.validate!
87
89
  say "Configuration is valid", :green
88
- rescue ConfigError => e
90
+ rescue Core::ConfigError => e
89
91
  encountered_error!
90
92
 
91
93
  say "Configuration is invalid", :red
@@ -111,7 +113,7 @@ module Skylight
111
113
  logger.level = Logger::DEBUG
112
114
  # Remove excess formatting
113
115
  logger.formatter = proc { |severity, datetime, progname, msg|
114
- msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ", '')
116
+ msg = msg.sub("[SKYLIGHT] [#{Skylight::Core::VERSION}] ", '')
115
117
  say "#{severity} - #{msg}" # Definitely non-standard
116
118
  }
117
119
  config.logger = logger
@@ -182,7 +184,7 @@ module Skylight
182
184
  end
183
185
 
184
186
  def is_mac?
185
- Util::Platform::OS == 'darwin'
187
+ Core::Util::Platform::OS == 'darwin'
186
188
  end
187
189
 
188
190
  # NOTE: This check won't work correctly on Windows
@@ -1,314 +1,181 @@
1
- require 'yaml'
2
- require 'fileutils'
3
- require 'thread'
4
1
  require 'openssl'
5
- require 'erb'
6
- require 'json'
7
- require 'skylight/util/deploy'
2
+ require 'skylight/core/util/deploy'
3
+ require 'skylight/core/util/platform'
8
4
  require 'skylight/util/hostname'
9
- require 'skylight/util/logging'
10
- require 'skylight/util/platform'
11
5
  require 'skylight/util/ssl'
12
- require 'skylight/util/proxy'
13
6
 
14
7
  module Skylight
15
- class Config
16
- include Util::Logging
17
-
18
- # @api private
19
- MUTEX = Mutex.new
20
-
21
- # Map environment variable keys with Skylight configuration keys
22
- ENV_TO_KEY = {
23
- # == Authentication ==
24
- 'AUTHENTICATION' => :authentication,
25
-
26
- # == App settings ==
27
- 'ROOT' => :root,
28
- 'HOSTNAME' => :hostname,
29
- 'SESSION_TOKEN' => :session_token,
30
-
31
- # == Deploy settings ==
32
- 'DEPLOY_ID' => :'deploy.id',
33
- 'DEPLOY_GIT_SHA' => :'deploy.git_sha',
34
- 'DEPLOY_DESCRIPTION' => :'deploy.description',
35
-
36
- # == Logging ==
37
- 'LOG_FILE' => :log_file,
38
- 'LOG_LEVEL' => :log_level,
39
- 'ALERT_LOG_FILE' => :alert_log_file,
40
- 'LOG_SQL_PARSE_ERRORS' => :log_sql_parse_errors,
41
-
42
- # == Proxy ==
43
- 'PROXY_URL' => :proxy_url,
44
-
45
- # == Instrumenter ==
46
- "IGNORED_ENDPOINT" => :ignored_endpoint,
47
- "IGNORED_ENDPOINTS" => :ignored_endpoints,
48
- "ENABLE_SEGMENTS" => :enable_segments,
49
-
50
- # == Skylight Remote ==
51
- "AUTH_URL" => :auth_url,
52
- "APP_CREATE_URL" => :app_create_url,
53
- "VALIDATION_URL" => :validation_url,
54
- "AUTH_HTTP_DEFLATE" => :auth_http_deflate,
55
- "AUTH_HTTP_CONNECT_TIMEOUT" => :auth_http_connect_timeout,
56
- "AUTH_HTTP_READ_TIMEOUT" => :auth_http_read_timeout,
57
- "REPORT_URL" => :report_url,
58
- "REPORT_HTTP_DEFLATE" => :report_http_deflate,
59
- "REPORT_HTTP_CONNECT_TIMEOUT" => :report_http_connect_timeout,
60
- "REPORT_HTTP_READ_TIMEOUT" => :report_http_read_timeout,
61
-
62
- # == User config settings ==
63
- "USER_CONFIG_PATH" => :'user_config_path',
64
-
65
- # == Native agent settings ==
66
- #
67
- "LAZY_START" => :'daemon.lazy_start',
68
- "DAEMON_EXEC_PATH" => :'daemon.exec_path',
69
- "DAEMON_LIB_PATH" => :'daemon.lib_path',
70
- "PIDFILE_PATH" => :'daemon.pidfile_path',
71
- "SOCKDIR_PATH" => :'daemon.sockdir_path',
72
- "BATCH_QUEUE_DEPTH" => :'daemon.batch_queue_depth',
73
- "BATCH_SAMPLE_SIZE" => :'daemon.batch_sample_size',
74
- "BATCH_FLUSH_INTERVAL" => :'daemon.batch_flush_interval',
75
- "DAEMON_TICK_INTERVAL" => :'daemon.tick_interval',
76
- "DAEMON_SANITY_CHECK_INTERVAL" => :'daemon.sanity_check_interval',
77
- "DAEMON_INACTIVITY_TIMEOUT" => :'daemon.inactivity_timeout',
78
- "CLIENT_MAX_TRIES" => :'daemon.max_connect_tries',
79
- "CLIENT_CONN_TRY_WIN" => :'daemon.connect_try_window',
80
- "MAX_PRESPAWN_JITTER" => :'daemon.max_prespawn_jitter',
81
- "DAEMON_WAIT_TIMEOUT" => :'daemon.wait_timeout',
82
- "CLIENT_CHECK_INTERVAL" => :'daemon.client_check_interval',
83
- "CLIENT_QUEUE_DEPTH" => :'daemon.client_queue_depth',
84
- "CLIENT_WRITE_TIMEOUT" => :'daemon.client_write_timeout',
85
- "SSL_CERT_PATH" => :'daemon.ssl_cert_path',
86
- "SSL_CERT_DIR" => :'daemon.ssl_cert_dir',
87
-
88
- # == Heroku settings ==
89
- #
90
- "HEROKU_DYNO_INFO_PATH" => :'heroku.dyno_info_path',
91
-
92
- # == Legacy env vars ==
93
- #
94
- 'AGENT_LOCKFILE' => :'agent.lockfile',
95
- 'AGENT_SOCKFILE_PATH' => :'agent.sockfile_path'
96
- }
97
-
98
- # Default values for Skylight configuration keys
99
- DEFAULTS = {
100
- :auth_url => 'https://auth.skylight.io/agent',
101
- :app_create_url => 'https://www.skylight.io/apps',
102
- :validation_url => 'https://auth.skylight.io/agent/config',
103
- :'daemon.lazy_start' => true,
104
- :log_file => '-'.freeze,
105
- :log_level => 'INFO'.freeze,
106
- :alert_log_file => '-'.freeze,
107
- :log_sql_parse_errors => false,
108
- :enable_segments => true,
109
- :hostname => Util::Hostname.default_hostname,
110
- :'heroku.dyno_info_path' => '/etc/heroku/dyno'
111
- }
112
-
113
- if Skylight::Util::Platform::OS != 'darwin'
114
- DEFAULTS[:'daemon.ssl_cert_path'] = Util::SSL.ca_cert_file_or_default
115
- DEFAULTS[:'daemon.ssl_cert_dir'] = Util::SSL.ca_cert_dir
116
- end
117
-
118
- if Skylight.native?
119
- native_path = Skylight.libskylight_path
120
-
121
- DEFAULTS[:'daemon.lib_path'] = native_path
122
- DEFAULTS[:'daemon.exec_path'] = File.join(native_path, 'skylightd')
123
- end
124
-
125
- DEFAULTS.freeze
126
-
127
- REQUIRED = {
128
- authentication: "authentication token",
129
- hostname: "server hostname",
130
- auth_url: "authentication url",
131
- validation_url: "config validation url" }
132
-
133
- SERVER_VALIDATE = [
134
- # Nothing is validated for now, but this is a list of symbols
135
- # for the key we want to validate.
136
- ]
137
-
138
- NATIVE_ENV = [
139
- :version,
140
- :root,
141
- :hostname,
142
- :deploy_id,
143
- :session_token,
144
- :proxy_url,
145
- :auth_url,
146
- :auth_http_deflate,
147
- :auth_http_connect_timeout,
148
- :auth_http_read_timeout,
149
- :report_url,
150
- :report_http_deflate,
151
- :report_http_connect_timeout,
152
- :report_http_read_timeout,
153
- :'daemon.lazy_start',
154
- :'daemon.exec_path',
155
- :'daemon.lib_path',
156
- :'daemon.pidfile_path',
157
- :'daemon.sockdir_path',
158
- :'daemon.batch_queue_depth',
159
- :'daemon.batch_sample_size',
160
- :'daemon.batch_flush_interval',
161
- :'daemon.tick_interval',
162
- :'daemon.sanity_check_interval',
163
- :'daemon.inactivity_timeout',
164
- :'daemon.max_connect_tries',
165
- :'daemon.connect_try_window',
166
- :'daemon.max_prespawn_jitter',
167
- :'daemon.wait_timeout',
168
- :'daemon.client_check_interval',
169
- :'daemon.client_queue_depth',
170
- :'daemon.client_write_timeout',
171
- :'daemon.ssl_cert_path',
172
- :'daemon.ssl_cert_dir'
173
- ]
174
-
175
- # Maps legacy config keys to new config keys
176
- LEGACY = {
177
- :'agent.sockfile_path' => :'daemon.sockdir_path',
178
- :'agent.lockfile' => :'daemon.pidfile_path'
179
- }
180
-
181
- VALIDATORS = {
182
- :'agent.interval' => [lambda { |v, c| Integer === v && v > 0 }, "must be an integer greater than 0"]
183
- }
184
-
185
- # @api private
186
- attr_reader :environment
187
-
188
- # @api private
189
- def initialize(*args)
190
- attrs = {}
191
-
192
- if Hash === args.last
193
- attrs = args.pop.dup
194
- end
195
-
196
- @values = {}
197
- @priority = {}
198
- @regexp = nil
199
-
200
- p = attrs.delete(:priority)
201
-
202
- if @environment = args[0]
203
- @regexp = /^#{Regexp.escape(@environment)}\.(.+)$/
204
- end
205
-
206
- attrs.each do |k, v|
207
- self[k] = v
208
- end
209
-
210
- if p
211
- p.each do |k, v|
212
- @priority[Config.remap_key(k)] = v
213
- end
214
- end
8
+ class Config < Core::Config
9
+
10
+ def self.env_to_key
11
+ @env_to_key ||= super.merge(
12
+ # == Authentication ==
13
+ 'AUTHENTICATION' => :authentication,
14
+
15
+ # == App settings ==
16
+ 'ROOT' => :root,
17
+ 'HOSTNAME' => :hostname,
18
+ 'SESSION_TOKEN' => :session_token,
19
+
20
+ # == Deploy settings ==
21
+ 'DEPLOY_ID' => :'deploy.id',
22
+ 'DEPLOY_GIT_SHA' => :'deploy.git_sha',
23
+ 'DEPLOY_DESCRIPTION' => :'deploy.description',
24
+
25
+ # == Sql Lexer ==
26
+ 'USE_OLD_SQL_LEXER' => :use_old_sql_lexer,
27
+
28
+ # == Instrumenter ==
29
+ "IGNORED_ENDPOINT" => :ignored_endpoint,
30
+ "IGNORED_ENDPOINTS" => :ignored_endpoints,
31
+
32
+ # == Skylight Remote ==
33
+ "AUTH_URL" => :auth_url,
34
+ "APP_CREATE_URL" => :app_create_url,
35
+ "VALIDATION_URL" => :validation_url,
36
+ "AUTH_HTTP_DEFLATE" => :auth_http_deflate,
37
+ "AUTH_HTTP_CONNECT_TIMEOUT" => :auth_http_connect_timeout,
38
+ "AUTH_HTTP_READ_TIMEOUT" => :auth_http_read_timeout,
39
+ "REPORT_URL" => :report_url,
40
+ "REPORT_HTTP_DEFLATE" => :report_http_deflate,
41
+ "REPORT_HTTP_CONNECT_TIMEOUT" => :report_http_connect_timeout,
42
+ "REPORT_HTTP_READ_TIMEOUT" => :report_http_read_timeout,
43
+
44
+ # == Native agent settings ==
45
+ #
46
+ "LAZY_START" => :'daemon.lazy_start',
47
+ "DAEMON_EXEC_PATH" => :'daemon.exec_path',
48
+ "DAEMON_LIB_PATH" => :'daemon.lib_path',
49
+ "PIDFILE_PATH" => :'daemon.pidfile_path',
50
+ "SOCKDIR_PATH" => :'daemon.sockdir_path',
51
+ "BATCH_QUEUE_DEPTH" => :'daemon.batch_queue_depth',
52
+ "BATCH_SAMPLE_SIZE" => :'daemon.batch_sample_size',
53
+ "BATCH_FLUSH_INTERVAL" => :'daemon.batch_flush_interval',
54
+ "DAEMON_TICK_INTERVAL" => :'daemon.tick_interval',
55
+ "DAEMON_SANITY_CHECK_INTERVAL" => :'daemon.sanity_check_interval',
56
+ "DAEMON_INACTIVITY_TIMEOUT" => :'daemon.inactivity_timeout',
57
+ "CLIENT_MAX_TRIES" => :'daemon.max_connect_tries',
58
+ "CLIENT_CONN_TRY_WIN" => :'daemon.connect_try_window',
59
+ "MAX_PRESPAWN_JITTER" => :'daemon.max_prespawn_jitter',
60
+ "DAEMON_WAIT_TIMEOUT" => :'daemon.wait_timeout',
61
+ "CLIENT_CHECK_INTERVAL" => :'daemon.client_check_interval',
62
+ "CLIENT_QUEUE_DEPTH" => :'daemon.client_queue_depth',
63
+ "CLIENT_WRITE_TIMEOUT" => :'daemon.client_write_timeout',
64
+ "SSL_CERT_PATH" => :'daemon.ssl_cert_path',
65
+ "SSL_CERT_DIR" => :'daemon.ssl_cert_dir',
66
+
67
+ # == Legacy env vars ==
68
+ #
69
+ 'AGENT_LOCKFILE' => :'agent.lockfile',
70
+ 'AGENT_SOCKFILE_PATH' => :'agent.sockfile_path'
71
+ )
215
72
  end
216
73
 
217
- def self.load(opts = {}, env = ENV)
218
- attrs = {}
219
- version = nil
220
-
221
- path = opts.delete(:file)
222
- environment = opts.delete(:environment)
223
-
224
- if path
225
- error = nil
226
- begin
227
- attrs = YAML.load(ERB.new(File.read(path)).result)
228
- error = "empty file" unless attrs
229
- error = "invalid format" if attrs && !attrs.is_a?(Hash)
230
- rescue Exception => e
231
- error = e.message
74
+ # Default values for Skylight configuration keys
75
+ def self.default_values
76
+ @default_values ||= begin
77
+ ret = super.merge(
78
+ :auth_url => 'https://auth.skylight.io/agent',
79
+ :app_create_url => 'https://www.skylight.io/apps',
80
+ :validation_url => 'https://auth.skylight.io/agent/config',
81
+ :'daemon.lazy_start' => true,
82
+ :hostname => Util::Hostname.default_hostname,
83
+ :use_old_sql_lexer => false
84
+ )
85
+
86
+ if Core::Util::Platform::OS != 'darwin'
87
+ ret[:'daemon.ssl_cert_path'] = Util::SSL.ca_cert_file_or_default
88
+ ret[:'daemon.ssl_cert_dir'] = Util::SSL.ca_cert_dir
232
89
  end
233
90
 
234
- raise ConfigError, "could not load config file; msg=#{error}" if error
91
+ if Skylight.native?
92
+ native_path = Skylight.libskylight_path
235
93
 
236
- version = File.mtime(path).to_i
237
- end
238
-
239
- if env
240
- attrs[:priority] = remap_env(env)
241
- end
242
-
243
- config = new(environment, attrs)
94
+ ret[:'daemon.lib_path'] = native_path
95
+ ret[:'daemon.exec_path'] = File.join(native_path, 'skylightd')
96
+ end
244
97
 
245
- opts.each do |k, v|
246
- config[k] = v
98
+ ret
247
99
  end
248
-
249
- config
250
100
  end
251
101
 
252
- def self.remap_key(key)
253
- key = key.to_sym
254
- LEGACY[key] || key
102
+ def self.required_keys
103
+ @required_keys ||= super.merge(
104
+ authentication: "authentication token",
105
+ hostname: "server hostname",
106
+ auth_url: "authentication url",
107
+ validation_url: "config validation url"
108
+ )
255
109
  end
256
110
 
257
- # @api private
258
- def self.remap_env(env)
259
- ret = {}
260
-
261
- return ret unless env
262
-
263
- # Only set if it exists, we don't want to set to a nil value
264
- if proxy_url = Util::Proxy.detect_url(env)
265
- ret[:proxy_url] = proxy_url
266
- end
267
-
268
- env.each do |k, val|
269
- # Support deprecated SK_ key prefix
270
- next unless k =~ /^(?:SK|SKYLIGHT)_(.+)$/
271
-
272
- if key = ENV_TO_KEY[$1]
273
- ret[key] =
274
- case val
275
- when /^false$/i then false
276
- when /^true$/i then true
277
- when /^(nil|null)$/i then nil
278
- when /^\d+$/ then val.to_i
279
- when /^\d+\.\d+$/ then val.to_f
280
- else val
281
- end
282
- end
283
- end
111
+ def self.native_env_keys
112
+ @native_env_keys ||= super + [
113
+ :version,
114
+ :root,
115
+ :hostname,
116
+ :deploy_id,
117
+ :session_token,
118
+ :auth_url,
119
+ :auth_http_deflate,
120
+ :auth_http_connect_timeout,
121
+ :auth_http_read_timeout,
122
+ :report_url,
123
+ :report_http_deflate,
124
+ :report_http_connect_timeout,
125
+ :report_http_read_timeout,
126
+ :'daemon.lazy_start',
127
+ :'daemon.exec_path',
128
+ :'daemon.lib_path',
129
+ :'daemon.pidfile_path',
130
+ :'daemon.sockdir_path',
131
+ :'daemon.batch_queue_depth',
132
+ :'daemon.batch_sample_size',
133
+ :'daemon.batch_flush_interval',
134
+ :'daemon.tick_interval',
135
+ :'daemon.sanity_check_interval',
136
+ :'daemon.inactivity_timeout',
137
+ :'daemon.max_connect_tries',
138
+ :'daemon.connect_try_window',
139
+ :'daemon.max_prespawn_jitter',
140
+ :'daemon.wait_timeout',
141
+ :'daemon.client_check_interval',
142
+ :'daemon.client_queue_depth',
143
+ :'daemon.client_write_timeout',
144
+ :'daemon.ssl_cert_path',
145
+ :'daemon.ssl_cert_dir'
146
+ ]
147
+ end
148
+
149
+ def self.legacy_keys
150
+ @legacy_keys ||= super.merge(
151
+ :'agent.sockfile_path' => :'daemon.sockdir_path',
152
+ :'agent.lockfile' => :'daemon.pidfile_path'
153
+ )
154
+ end
284
155
 
285
- ret
156
+ def self.validators
157
+ @validators ||= super.merge(
158
+ :'agent.interval' => [lambda { |v, c| Integer === v && v > 0 }, "must be an integer greater than 0"]
159
+ )
286
160
  end
287
161
 
162
+ # @api private
288
163
  def api
289
164
  @api ||= Api.new(self)
290
165
  end
291
166
 
292
167
  # @api private
293
168
  def validate!
294
- REQUIRED.each do |k, v|
295
- unless get(k)
296
- raise ConfigError, "#{v} required"
297
- end
298
- end
169
+ super
299
170
 
300
171
  # TODO: Move this out of the validate! method: https://github.com/tildeio/direwolf-agent/issues/273
301
172
  # FIXME: Why not set the sockdir_path and pidfile_path explicitly?
302
173
  # That way we don't have to keep this in sync with the Rust repo.
303
174
  sockdir_path = File.expand_path(self[:'daemon.sockdir_path'] || '.', root)
304
175
  pidfile_path = File.expand_path(self[:'daemon.pidfile_path'] || 'skylight.pid', sockdir_path)
305
- log_file = self[:log_file]
306
- alert_log_file = self[:alert_log_file]
307
176
 
308
177
  check_file_permissions(pidfile_path, "daemon.pidfile_path or daemon.sockdir_path")
309
178
  check_sockdir_permissions(sockdir_path)
310
- check_logfile_permissions(log_file, "log_file")
311
- check_logfile_permissions(alert_log_file, "alert_log_file")
312
179
 
313
180
  true
314
181
  end
@@ -336,7 +203,7 @@ module Skylight
336
203
  corrected_config = res.corrected_config
337
204
  unless corrected_config
338
205
  # Use defaults if no corrected config is available. This will happen if the request failed.
339
- corrected_config = Hash[SERVER_VALIDATE.map{|k| [k, DEFAULTS[k]] }]
206
+ corrected_config = Hash[self.class.server_validated_keys.map{|k| [k, [k]] }]
340
207
  end
341
208
 
342
209
  config_to_update = corrected_config.select{|k,v| get(k) != v }
@@ -357,139 +224,23 @@ module Skylight
357
224
  return true
358
225
  end
359
226
 
360
- def check_file_permissions(file, key)
361
- file_root = File.dirname(file)
362
-
363
- # Try to make the directory, don't blow up if we can't. Our writable? check will fail later.
364
- FileUtils.mkdir_p file_root rescue nil
365
-
366
- if File.exist?(file) && !FileTest.writable?(file)
367
- raise ConfigError, "File `#{file}` is not writable. Please set #{key} in your config to a writable path"
368
- end
369
-
370
- unless FileTest.writable?(file_root)
371
- raise ConfigError, "Directory `#{file_root}` is not writable. Please set #{key} in your config to a writable path"
372
- end
373
- end
374
-
375
227
  def check_sockdir_permissions(sockdir_path)
376
228
  # Try to make the directory, don't blow up if we can't. Our writable? check will fail later.
377
229
  FileUtils.mkdir_p sockdir_path rescue nil
378
230
 
379
231
  unless FileTest.writable?(sockdir_path)
380
- raise ConfigError, "Directory `#{sockdir_path}` is not writable. Please set daemon.sockdir_path in your config to a writable path"
232
+ raise Core::ConfigError, "Directory `#{sockdir_path}` is not writable. Please set daemon.sockdir_path in your config to a writable path"
381
233
  end
382
234
 
383
235
  if check_nfs(sockdir_path)
384
- raise ConfigError, "Directory `#{sockdir_path}` is an NFS mount and will not allow sockets. Please set daemon.sockdir_path in your config to a non-NFS path."
236
+ raise Core::ConfigError, "Directory `#{sockdir_path}` is an NFS mount and will not allow sockets. Please set daemon.sockdir_path in your config to a non-NFS path."
385
237
  end
386
238
  end
387
239
 
388
- def check_logfile_permissions(log_file, key)
389
- return if log_file == '-' # STDOUT
390
- log_file = File.expand_path(log_file, root)
391
- check_file_permissions(log_file, key)
392
- end
393
-
394
- def key?(key)
395
- key = Config.remap_key(key)
396
- @priority.key?(key) || @values.key?(key)
397
- end
398
-
399
- def get(key, default = nil, &blk)
400
- key = Config.remap_key(key)
401
-
402
- return @priority[key] if @priority.key?(key)
403
- return @values[key] if @values.key?(key)
404
- return DEFAULTS[key] if DEFAULTS.key?(key)
405
-
406
- if default
407
- return default
408
- elsif blk
409
- return blk.call(key)
410
- end
411
-
412
- nil
413
- end
414
-
415
- alias [] get
416
-
417
- def set(key, val, scope = nil)
418
- if scope
419
- key = [scope, key].join('.')
420
- end
421
-
422
- if Hash === val
423
- val.each do |k, v|
424
- set(k, v, key)
425
- end
426
- else
427
- k = Config.remap_key(key)
428
-
429
- if validator = VALIDATORS[k]
430
- blk, msg = validator
431
-
432
- unless blk.call(val, self)
433
- error_msg = "invalid value for #{k} (#{val})"
434
- error_msg << ", #{msg}" if msg
435
- raise ConfigError, error_msg
436
- end
437
- end
438
-
439
- if @regexp && k =~ @regexp
440
- @priority[$1.to_sym] = val
441
- end
442
-
443
- @values[k] = val
444
- end
445
- end
446
-
447
- alias []= set
448
-
449
- def send_or_get(v)
450
- respond_to?(v) ? send(v) : get(v)
451
- end
452
-
453
- def duration_ms(key, default = nil)
454
- if (v = self[key]) && v.to_s =~ /^\s*(\d+)(s|sec|ms|micros|nanos)?\s*$/
455
- v = $1.to_i
456
- case $2
457
- when "ms"
458
- v
459
- when "micros"
460
- v / 1_000
461
- when "nanos"
462
- v / 1_000_000
463
- else # "s", "sec", nil
464
- v * 1000
465
- end
466
- else
467
- default
468
- end
469
- end
470
-
471
- def to_json
472
- JSON.generate(
473
- config: {
474
- priority: @priority,
475
- values: @values
476
- }
477
- )
478
- end
479
-
480
240
  def to_native_env
481
- ret = []
241
+ ret = super
482
242
 
483
243
  ret << "SKYLIGHT_AUTHENTICATION" << authentication_with_deploy
484
-
485
- NATIVE_ENV.each do |key|
486
- value = send_or_get(key)
487
- unless value.nil?
488
- env_key = ENV_TO_KEY.key(key) || key.upcase
489
- ret << "SKYLIGHT_#{env_key}" << cast_for_env(value)
490
- end
491
- end
492
-
493
244
  ret << "SKYLIGHT_VALIDATE_AUTHENTICATION" << "false"
494
245
 
495
246
  ret
@@ -513,42 +264,6 @@ authentication: #{self[:authentication]}
513
264
  #
514
265
  #
515
266
 
516
- def version
517
- VERSION
518
- end
519
-
520
- # @api private
521
- def gc
522
- @gc ||= GC.new(self, get('gc.profiler', VM::GC.new))
523
- end
524
-
525
- # @api private
526
- def ignore_token?
527
- get('test.ignore_token')
528
- end
529
-
530
- # @api private
531
- def ignored_endpoints
532
- @ignored_endpoints ||=
533
- begin
534
- ignored_endpoints = get(:ignored_endpoints)
535
-
536
- # If, for some odd reason you have a comma in your endpoint name, use the
537
- # YML config instead.
538
- if ignored_endpoints.is_a?(String)
539
- ignored_endpoints = ignored_endpoints.split(/\s*,\s*/)
540
- end
541
-
542
- val = Array(get(:ignored_endpoint))
543
- val.concat(Array(ignored_endpoints))
544
- val
545
- end
546
- end
547
-
548
- def root
549
- self[:root] || Dir.pwd
550
- end
551
-
552
267
  def authentication_with_deploy
553
268
  token = get(:authentication)
554
269
 
@@ -562,49 +277,8 @@ authentication: #{self[:authentication]}
562
277
  token
563
278
  end
564
279
 
565
- def logger
566
- @logger ||=
567
- MUTEX.synchronize do
568
- load_logger
569
- end
570
- end
571
-
572
- def logger=(logger)
573
- @logger = logger
574
- end
575
-
576
- def alert_logger
577
- @alert_logger ||= MUTEX.synchronize do
578
- unless l = @alert_logger
579
- out = get(:alert_log_file)
580
- out = Util::AlertLogger.new(load_logger) if out == '-'
581
-
582
- l = create_logger(out)
583
- l.level = Logger::DEBUG
584
- end
585
-
586
- l
587
- end
588
- end
589
-
590
- def alert_logger=(logger)
591
- @alert_logger = logger
592
- end
593
-
594
- def on_heroku?
595
- File.exist?(get(:'heroku.dyno_info_path'))
596
- end
597
-
598
280
  def deploy
599
- @deploy ||= Util::Deploy.build(self)
600
- end
601
-
602
- def enable_segments?
603
- !!get(:enable_segments)
604
- end
605
-
606
- def user_config
607
- @user_config ||= UserConfig.new(self)
281
+ @deploy ||= Core::Util::Deploy.build(self)
608
282
  end
609
283
 
610
284
  private
@@ -614,48 +288,5 @@ authentication: #{self[:authentication]}
614
288
  `stat -f -L -c %T #{path} 2>&1`.strip == 'nfs'
615
289
  end
616
290
 
617
- def create_logger(out)
618
- if out.is_a?(String)
619
- out = File.expand_path(out, root)
620
- # May be redundant since we also do this in the permissions check
621
- FileUtils.mkdir_p(File.dirname(out))
622
- end
623
-
624
- Logger.new(out)
625
- rescue
626
- Logger.new(STDOUT)
627
- end
628
-
629
- def load_logger
630
- unless l = @logger
631
- out = get(:log_file)
632
- out = STDOUT if out == '-'
633
-
634
- l = create_logger(out)
635
-
636
- if ENV[TRACE_ENV_KEY]
637
- l.level = Logger::DEBUG
638
- else
639
- l.level =
640
- case get(:log_level)
641
- when /^debug$/i then Logger::DEBUG
642
- when /^info$/i then Logger::INFO
643
- when /^warn$/i then Logger::WARN
644
- when /^error$/i then Logger::ERROR
645
- end
646
- end
647
- end
648
-
649
- l
650
- end
651
-
652
- def cast_for_env(v)
653
- case v
654
- when true then 'true'
655
- when false then 'false'
656
- when nil then 'nil'
657
- else v.to_s
658
- end
659
- end
660
291
  end
661
292
  end