skylight 2.0.2 → 3.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -3
- data/README.md +4 -1
- data/ext/libskylight.yml +6 -7
- data/lib/skylight/api.rb +30 -1
- data/lib/skylight/cli.rb +4 -2
- data/lib/skylight/cli/merger.rb +305 -0
- data/lib/skylight/config.rb +33 -6
- data/lib/skylight/railtie.rb +9 -1
- data/lib/skylight/util/component.rb +33 -0
- data/lib/skylight/util/deploy.rb +2 -3
- data/lib/skylight/version.rb +1 -1
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9d371e3b8cc2f1e570e61130d352215e51107f6861840b1f2476c9c3e1a46ab
|
4
|
+
data.tar.gz: b037f983a6416f9af147156aab819a694a84e35ee0bc319d76578653a3186964
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9370e806f12f02205d3911f3de966f95dbde20b7c808d5ce6f1aa5276ff0f213581fc3c1205b19419ee6d861c5e37c449816d07142052ad5e32f794dd531ce0a
|
7
|
+
data.tar.gz: a1cc78dda26938c4312da0f57067a170ffee7c6059edaa2d01955426c5f2d366d644bf889a80305e3c04bf424a8a2a0dbf9cbf9343a0ba94cf20e3d6cbddab9d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 3.0.0-beta (August 2, 2018)
|
2
|
+
|
3
|
+
* [BETA FEATURE] First class support for [multiple application environments](https://www.skylight.io/support/environments)
|
4
|
+
* [IMPROVEMENT] Better instrumentation of ActiveJob enqueues
|
5
|
+
|
1
6
|
## 2.0.2 (June 4, 2018)
|
2
7
|
|
3
8
|
* [IMPROVEMENT] Improve handling of broken middleware traces
|
@@ -229,7 +234,7 @@
|
|
229
234
|
|
230
235
|
## 0.8.0 (August 13, 2015)
|
231
236
|
|
232
|
-
* [FEATURE] Add Grape instumentation. See
|
237
|
+
* [FEATURE] Add Grape instumentation. See https://docs.skylight.io/grape
|
233
238
|
* [FEATURE] Process ERB in config/skylight.yml
|
234
239
|
* [FEATURE] Add Rust based SQL lexing. Currently beta. Enable with `config.sql_mode = 'rust'`.
|
235
240
|
* [BUGFIX] Fixed a case where, With some logger configurations, duplicate messages could be written to STDOUT.
|
@@ -254,7 +259,7 @@
|
|
254
259
|
|
255
260
|
* [IMPROVEMENT] Eliminates runtime dependency on the Rails
|
256
261
|
constant across the entire codebase
|
257
|
-
* [FEATURE] Support for Sinatra applications. See
|
262
|
+
* [FEATURE] Support for Sinatra applications. See https://docs.skylight.io/sinatra/
|
258
263
|
* [FEATURE] Support for the Sequel ORM (off by default for Rails apps)
|
259
264
|
* [FEATURE] Support for Tilt templates (off by default for Rails apps)
|
260
265
|
|
@@ -309,7 +314,7 @@
|
|
309
314
|
|
310
315
|
## 0.3.18 (July 17, 2014)
|
311
316
|
|
312
|
-
* [FEATURE] Redis probe (Not enabled by default. See
|
317
|
+
* [FEATURE] Redis probe (Not enabled by default. See https://docs.skylight.io/agent/#railtie)
|
313
318
|
* [FEATURE] Support app creation with token instead of email/password
|
314
319
|
* [BUGFIX] App creation now works even when Webmock is enabled
|
315
320
|
* [BUGFIX] Fix instrumentation for methods ending in special chars
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Skylight Ruby Agent
|
2
2
|
|
3
|
+
![Rubygems Version](https://img.shields.io/gem/v/skylight.svg)
|
4
|
+
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=skylight&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=skylight&package-manager=bundler&version-scheme=semver)
|
5
|
+
|
3
6
|
Instrument your ruby application and send the data to the Skylight
|
4
7
|
servers.
|
5
8
|
|
@@ -10,4 +13,4 @@ For more documentation see https://www.skylight.io/support.
|
|
10
13
|
|
11
14
|
## Bug Reports and Feature Requests
|
12
15
|
|
13
|
-
If you've got a bug report or have a feature you'd like to request, please contact us at support@skylight.io or use the built-in messenger in the Skylight web interface. We'll be much quicker to respond that way :)
|
16
|
+
If you've got a bug report or have a feature you'd like to request, please contact us at support@skylight.io or use the built-in messenger in the Skylight web interface. We'll be much quicker to respond that way :)
|
data/ext/libskylight.yml
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
version: "2.0.0-b7a5dfb"
|
1
|
+
version: "3.0.0-4e3325d"
|
3
2
|
checksums:
|
4
|
-
x86-linux: "
|
5
|
-
x86_64-linux: "
|
6
|
-
x86_64-linux-musl: "
|
7
|
-
x86_64-darwin: "
|
8
|
-
x86_64-freebsd: "
|
3
|
+
x86-linux: "5f163ab012f92e4801783566e8d4804327448c603f57f4768d54de23f6c4768c"
|
4
|
+
x86_64-linux: "9ad7672ed16fe7c7e54b19fc85fe22388f478872df11eacceb7d881397bb4061"
|
5
|
+
x86_64-linux-musl: "f9a30d85dd0a63def447622ecdf5dbbddd379b14947e0f2d5c6b26546b9e6514"
|
6
|
+
x86_64-darwin: "85a0125a012de2d650b978b615a0a3c040894ed38eece293b5e467fd4a1bf2a4"
|
7
|
+
x86_64-freebsd: "c563ecff9289c3a716791a477cc360cd30ab84c4bbc4f888534b2a9c4a422d55"
|
data/lib/skylight/api.rb
CHANGED
@@ -8,7 +8,10 @@ module Skylight
|
|
8
8
|
|
9
9
|
attr_reader :config
|
10
10
|
|
11
|
-
class
|
11
|
+
class Error < StandardError; end
|
12
|
+
class Unauthorized < Error; end
|
13
|
+
class Conflict < Error; end
|
14
|
+
class CreateFailed < Error
|
12
15
|
attr_reader :res
|
13
16
|
|
14
17
|
def initialize(res)
|
@@ -102,6 +105,21 @@ module Skylight
|
|
102
105
|
res
|
103
106
|
end
|
104
107
|
|
108
|
+
def fetch_mergeable_apps(token)
|
109
|
+
headers = { 'x-skylight-merge-token' => token }
|
110
|
+
http_request(:merges, :get, headers).tap do |res|
|
111
|
+
raise error_for_status(res.status).new("HTTP #{res.status}: #{res.body}") unless res.success?
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def merge_apps!(token, app_guid:, component_guid:, environment:)
|
116
|
+
headers = { 'x-skylight-merge-token' => token }
|
117
|
+
body = { environment: environment, app_guid: app_guid, component_guid: component_guid }
|
118
|
+
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?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
105
123
|
def validate_config
|
106
124
|
res = http_request(:validation, :post, config)
|
107
125
|
ConfigValidationResults.new(config, res)
|
@@ -116,6 +134,17 @@ module Skylight
|
|
116
134
|
http.send(method, uri.path, *args)
|
117
135
|
end
|
118
136
|
|
137
|
+
def error_for_status(code)
|
138
|
+
case code
|
139
|
+
when 401
|
140
|
+
Unauthorized
|
141
|
+
when 409
|
142
|
+
Conflict
|
143
|
+
else
|
144
|
+
Error
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
119
148
|
end
|
120
149
|
|
121
150
|
end
|
data/lib/skylight/cli.rb
CHANGED
@@ -8,6 +8,7 @@ require 'active_support/inflector'
|
|
8
8
|
|
9
9
|
require 'skylight/cli/helpers'
|
10
10
|
require 'skylight/cli/doctor'
|
11
|
+
require 'skylight/cli/merger'
|
11
12
|
|
12
13
|
module Skylight
|
13
14
|
module CLI
|
@@ -16,6 +17,7 @@ module Skylight
|
|
16
17
|
include Helpers
|
17
18
|
|
18
19
|
register(Doctor, "doctor", "doctor", "Run some basic tests to look out for common problems")
|
20
|
+
register(Merger, "merge", "merge", "Merge one app into another (e.g., as a child environment)")
|
19
21
|
|
20
22
|
desc "setup TOKEN", "Sets up a new app using the provided token"
|
21
23
|
def setup(token)
|
@@ -35,7 +37,7 @@ to set it up as a new app in Skylight.
|
|
35
37
|
config[:authentication] = res.get('app.token')
|
36
38
|
config.write(config_path)
|
37
39
|
|
38
|
-
say "Congratulations. Your application is on Skylight!
|
40
|
+
say "Congratulations. Your application is on Skylight! https://www.skylight.io", :green
|
39
41
|
say <<-OUT
|
40
42
|
|
41
43
|
The application was registered for you and we generated a config file
|
@@ -47,7 +49,7 @@ The next step is for you to deploy your application to production. The
|
|
47
49
|
easiest way is to just commit the config file to your source control
|
48
50
|
repository and deploy from there. You can learn more about the process at:
|
49
51
|
|
50
|
-
|
52
|
+
https://docs.skylight.io/getting-set-up/#deployment
|
51
53
|
|
52
54
|
If you want to specify the authentication token as an environment variable,
|
53
55
|
you should set the `SKYLIGHT_AUTHENTICATION` variable to:
|
@@ -0,0 +1,305 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'skylight/util/http'
|
3
|
+
require 'thor'
|
4
|
+
require 'highline'
|
5
|
+
|
6
|
+
module Skylight
|
7
|
+
module CLI
|
8
|
+
class Merger < Thor::Group
|
9
|
+
include Helpers
|
10
|
+
|
11
|
+
def self.banner
|
12
|
+
"#{basename} skylight merge MERGE_TOKEN"
|
13
|
+
end
|
14
|
+
|
15
|
+
STRINGS = {
|
16
|
+
get_token: 'get your merge token from `https://www.skylight.io/merging`',
|
17
|
+
unlisted: "My app isn't listed here :("
|
18
|
+
}
|
19
|
+
|
20
|
+
argument :merge_token, type: :string, desc: STRINGS[:get_token]
|
21
|
+
|
22
|
+
def welcome
|
23
|
+
say "\nHello! Welcome to the `skylight merge` CLI!\n", :green
|
24
|
+
|
25
|
+
say "This CLI is for Skylight users who already have Skylight Environments set up\n" \
|
26
|
+
"using the legacy method of creating a separate Skylight app per environment.\n" \
|
27
|
+
"Use this CLI to merge legacy environment apps into their parent apps as Environments."
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_apps
|
31
|
+
say "\nFetching your apps from skylight.io..."
|
32
|
+
@apps = api.fetch_mergeable_apps(@merge_token).body
|
33
|
+
|
34
|
+
if @apps.count < 2
|
35
|
+
done!(
|
36
|
+
message: "It does not appear that you are the owner of enough apps (there's nothing we can merge).",
|
37
|
+
success: false
|
38
|
+
)
|
39
|
+
end
|
40
|
+
rescue Skylight::Api::Unauthorized
|
41
|
+
done!(
|
42
|
+
success: false,
|
43
|
+
message: "Provided merge token is invalid.\n" \
|
44
|
+
"Please #{STRINGS[:get_token]}" \
|
45
|
+
"and run `skylight merge <merge token>` again."
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def ask_for_parent_app
|
50
|
+
@parents ||= begin
|
51
|
+
a = (@apps + [{ name: STRINGS[:unlisted], components: [], unlisted: true }])
|
52
|
+
a.each_with_object({}).with_index do |(app, h), i|
|
53
|
+
h[i + 1] = OpenStruct.new(app)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
say "\nLet's begin!\n\n" \
|
58
|
+
"Please specify the \"parent\" app.\n" \
|
59
|
+
"In most cases, this will be the production app handling web requests.", :green
|
60
|
+
|
61
|
+
@parent_app = ask_for_app(@parents)
|
62
|
+
end
|
63
|
+
|
64
|
+
def confirm_parent
|
65
|
+
say "\nOk! The parent app is: #{@parent_app.name}", :green
|
66
|
+
end
|
67
|
+
|
68
|
+
def ask_for_child_app
|
69
|
+
say "Please specify the child app to be merged into the parent app as an Environment.", :green
|
70
|
+
@child_app = ask_for_app(children, &method(:format_component))
|
71
|
+
end
|
72
|
+
|
73
|
+
def confirm_child
|
74
|
+
say "\nOk! The child app is: #{set_color(format_component(@child_app), :yellow)}", :green
|
75
|
+
end
|
76
|
+
|
77
|
+
def ask_for_child_env
|
78
|
+
say "\nWhat environment is the child app?\n" \
|
79
|
+
"In many cases, this will be equivalent to the Rails " \
|
80
|
+
"environment, i.e., `development`.", :green
|
81
|
+
|
82
|
+
say "1. development"
|
83
|
+
say "2. staging"
|
84
|
+
say "3. [choose a different environment not listed here]"
|
85
|
+
|
86
|
+
i = ask("\nWhich number?").chomp.to_i
|
87
|
+
|
88
|
+
@child_env = case i
|
89
|
+
when 1 then 'development'
|
90
|
+
when 2 then 'staging'
|
91
|
+
when 3
|
92
|
+
specify_child_env
|
93
|
+
else
|
94
|
+
say("\nEh? Please enter 1, 2, or 3.", :red)
|
95
|
+
ask_for_child_env
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def confirm_child_env
|
100
|
+
say "\nOk! The child environment will be: #{set_color(@child_env, :yellow)}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def confirm_everything
|
104
|
+
say "\nOk! Now we're going to merge `#{set_color(format_component(@child_app), :yellow)}` " \
|
105
|
+
"into `#{set_color(@parent_app.name, :green)}` as `#{set_color(@child_env, :yellow)}`."
|
106
|
+
end
|
107
|
+
|
108
|
+
def do_confirm
|
109
|
+
proceed = ask("Proceed? [Y/n]", :yellow).chomp
|
110
|
+
|
111
|
+
case proceed.upcase
|
112
|
+
when "Y", ""
|
113
|
+
do_merge
|
114
|
+
when "N"
|
115
|
+
done!(
|
116
|
+
success: true,
|
117
|
+
message: "Ok, come back any time."
|
118
|
+
)
|
119
|
+
else
|
120
|
+
say("Please respond 'Y' to merge or 'n' to cancel.", :red)
|
121
|
+
do_confirm
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def print_new_config_instructions
|
126
|
+
say "\nSuccess!\n", :green
|
127
|
+
|
128
|
+
say "=======================================================\n", :yellow
|
129
|
+
|
130
|
+
say "IMPORTANT!\n" \
|
131
|
+
"If you use a config/skylight.yml file to configure Skylight:\n", :yellow
|
132
|
+
|
133
|
+
say "The #@child_env environment for the #{@parent_app.name} app\n" \
|
134
|
+
"will now connect using the default authentication token for the app.\n" \
|
135
|
+
"Remove any environment-specific `authentication` configs from the\n" \
|
136
|
+
"#{@parent_app.name} #@child_env environment.\n", :yellow
|
137
|
+
|
138
|
+
say "If you're running in Rails and your Rails environment exactly matches `#@child_env`,\n" \
|
139
|
+
"set `report_rails_env: true` to allow the agent to detect and report that\n" \
|
140
|
+
"environment when it connects.\n" \
|
141
|
+
"Otherwise, you should set `env: '#@child_env'` as environment-specific configuration for\n" \
|
142
|
+
"#@child_env's Rails environment. For example:\n" \
|
143
|
+
"```yml\n" \
|
144
|
+
"staging:\n" \
|
145
|
+
" env: staging-42\n" \
|
146
|
+
"```\n", :yellow
|
147
|
+
# TODO: https://github.com/tildeio/direwolf-agent/issues/380
|
148
|
+
# report_rails_env above is for beta only. Update for final release
|
149
|
+
# "we will automatically detect and report that environment when your agent connects.\n"
|
150
|
+
|
151
|
+
say "=======================================================\n", :yellow
|
152
|
+
|
153
|
+
say "IMPORTANT!\n" \
|
154
|
+
"If you configure Skylight using environment variables:\n", :yellow
|
155
|
+
|
156
|
+
say "Deploy the latest agent before updating your environment variables.\n", :yellow
|
157
|
+
|
158
|
+
say "The #@child_env environment for the #{@parent_app.name} app\n" \
|
159
|
+
"will now connect using the default authentication token for the app.\n" \
|
160
|
+
"Set `SKYLIGHT_AUTHENTICATION` in the #@child_env environment to the\n" \
|
161
|
+
"#{@parent_app.name} app's authentication token.\n", :yellow
|
162
|
+
|
163
|
+
say "If you're running in Rails and your Rails environment exactly matches `#@child_env`,\n" \
|
164
|
+
"set `SKYLIGHT_REPORT_RAILS_ENV=true` to allow the agent to detect and report\n" \
|
165
|
+
"that environment when it connects.\n" \
|
166
|
+
"Otherwise, you should set `SKYLIGHT_ENV=#@child_env` when running in this environment.\n", :yellow
|
167
|
+
# TODO: https://github.com/tildeio/direwolf-agent/issues/380
|
168
|
+
# SKYLIGHT_REPORT_RAILS_ENV above is for beta only. Update for final release
|
169
|
+
# "we will automatically detect and report that environment when your agent connects.\n"
|
170
|
+
|
171
|
+
say "=======================================================", :yellow
|
172
|
+
|
173
|
+
done!
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
|
178
|
+
def do_merge
|
179
|
+
say "Merging..."
|
180
|
+
|
181
|
+
api.merge_apps!(@merge_token,
|
182
|
+
app_guid: @parent_app.guid,
|
183
|
+
component_guid: @child_app.guid,
|
184
|
+
environment: @child_env
|
185
|
+
)
|
186
|
+
rescue => e
|
187
|
+
say("Something went wrong. Please contact support@skylight.io for more information.", :red)
|
188
|
+
done!(message: e.message, success: false)
|
189
|
+
end
|
190
|
+
|
191
|
+
def done!(message: nil, success: true)
|
192
|
+
shell.padding = 0
|
193
|
+
say "\n"
|
194
|
+
|
195
|
+
if success
|
196
|
+
say(message, :green) if message
|
197
|
+
say "If you have any questions, please contact support@skylight.io.", :green
|
198
|
+
exit 0
|
199
|
+
else
|
200
|
+
say message || "Skylight wasn't able to merge your apps.", :red
|
201
|
+
say "If you have any questions, please contact support@skylight.io.", :yellow
|
202
|
+
exit 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def ask_for_app(app_list, &formatter)
|
207
|
+
formatter ||= :name.to_proc
|
208
|
+
app_list.each do |index, app|
|
209
|
+
say("\t#{index}. #{formatter.(app)}")
|
210
|
+
end
|
211
|
+
|
212
|
+
n = ask("\nWhich number?").chomp.to_i
|
213
|
+
|
214
|
+
if !app_list.key?(n)
|
215
|
+
say "\nHmm?"
|
216
|
+
ask_for_app(app_list, &formatter)
|
217
|
+
elsif app_list[n].unlisted
|
218
|
+
done!(
|
219
|
+
success: false,
|
220
|
+
message: "Sorry, `skylight merge` is only able to merge apps that you own."
|
221
|
+
)
|
222
|
+
else
|
223
|
+
app_list[n]
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def api
|
228
|
+
@api ||= Skylight::Api.new(config)
|
229
|
+
end
|
230
|
+
|
231
|
+
def format_component(component)
|
232
|
+
parts = [].tap do |ary|
|
233
|
+
ary << component.name unless component.name == 'web'
|
234
|
+
ary << component.environment unless component.environment == 'production'
|
235
|
+
end
|
236
|
+
|
237
|
+
str = ''
|
238
|
+
str << component.app_name
|
239
|
+
str << Thor::Shell::Color.new.set_color(" (#{parts.join(':')})", :yellow) if parts.any?
|
240
|
+
str
|
241
|
+
end
|
242
|
+
|
243
|
+
def validate_mergeability(child_app, child_env)
|
244
|
+
errors = []
|
245
|
+
|
246
|
+
unless valid_component?(child_app.name, child_env)
|
247
|
+
errors << "Environment can only contain letters, numbers, and hyphens."
|
248
|
+
end
|
249
|
+
|
250
|
+
if @parent_app && parent_component_fingerprints.include?([child_app.name, child_env])
|
251
|
+
errors << "Sorry, `#{@parent_app.name}` already has a `#{child_env}` " \
|
252
|
+
"component that conflicts with this merge request. Please choose a new environment."
|
253
|
+
end
|
254
|
+
|
255
|
+
return child_env unless errors.any?
|
256
|
+
|
257
|
+
say errors.join("\n"), :red
|
258
|
+
|
259
|
+
yield
|
260
|
+
end
|
261
|
+
|
262
|
+
def valid_component?(component_name, env)
|
263
|
+
return false unless env
|
264
|
+
Skylight::Util::Component.new(env, component_name) && true
|
265
|
+
rescue ArgumentError
|
266
|
+
false
|
267
|
+
end
|
268
|
+
|
269
|
+
def parent_component_fingerprints
|
270
|
+
@parent_app.components.map { |x| x.values_at('name', 'environment') }
|
271
|
+
end
|
272
|
+
|
273
|
+
def children
|
274
|
+
Enumerator.new do |yielder|
|
275
|
+
@parents.each do |_, app|
|
276
|
+
next if app == @parent_app
|
277
|
+
app.components.each do |component|
|
278
|
+
yielder << OpenStruct.new({ app_name: app.name }.merge(component))
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
yielder << OpenStruct.new({ app_name: STRINGS[:unlisted], unlisted: true })
|
283
|
+
end.each_with_object({}).with_index do |(c, r), i|
|
284
|
+
r[i + 1] = c
|
285
|
+
end.tap do |result|
|
286
|
+
if result.values.all?(&:unlisted)
|
287
|
+
done!(
|
288
|
+
success: false,
|
289
|
+
message: "Sorry, you do not have any apps that can be merged into `#{@parent_app.name}`"
|
290
|
+
)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
def specify_child_env
|
296
|
+
validate_mergeability(
|
297
|
+
@child_app,
|
298
|
+
ask("Please enter your environment name (only lowercase letters, numbers, or hyphens): ", :green).chomp
|
299
|
+
) do
|
300
|
+
specify_child_env
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
data/lib/skylight/config.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'openssl'
|
2
|
+
require 'skylight/util/component'
|
2
3
|
require 'skylight/util/deploy'
|
3
4
|
require 'skylight/core/util/platform'
|
4
5
|
require 'skylight/util/hostname'
|
@@ -17,6 +18,11 @@ module Skylight
|
|
17
18
|
'HOSTNAME' => :hostname,
|
18
19
|
'SESSION_TOKEN' => :session_token,
|
19
20
|
|
21
|
+
# == Component settings ==
|
22
|
+
'ENV' => :'component.environment',
|
23
|
+
'COMPONENT' => :'component.name',
|
24
|
+
'REPORT_RAILS_ENV' => :report_rails_env,
|
25
|
+
|
20
26
|
# == Deploy settings ==
|
21
27
|
'DEPLOY_ID' => :'deploy.id',
|
22
28
|
'DEPLOY_GIT_SHA' => :'deploy.git_sha',
|
@@ -35,6 +41,7 @@ module Skylight
|
|
35
41
|
# == Skylight Remote ==
|
36
42
|
"AUTH_URL" => :auth_url,
|
37
43
|
"APP_CREATE_URL" => :app_create_url,
|
44
|
+
"MERGES_URL" => :merges_url,
|
38
45
|
"VALIDATION_URL" => :validation_url,
|
39
46
|
"AUTH_HTTP_DEFLATE" => :auth_http_deflate,
|
40
47
|
"AUTH_HTTP_CONNECT_TIMEOUT" => :auth_http_connect_timeout,
|
@@ -43,6 +50,7 @@ module Skylight
|
|
43
50
|
"REPORT_HTTP_DEFLATE" => :report_http_deflate,
|
44
51
|
"REPORT_HTTP_CONNECT_TIMEOUT" => :report_http_connect_timeout,
|
45
52
|
"REPORT_HTTP_READ_TIMEOUT" => :report_http_read_timeout,
|
53
|
+
"REPORT_HTTP_DISABLED" => :report_http_disabled,
|
46
54
|
|
47
55
|
# == Native agent settings ==
|
48
56
|
#
|
@@ -80,11 +88,13 @@ module Skylight
|
|
80
88
|
ret = super.merge(
|
81
89
|
:auth_url => 'https://auth.skylight.io/agent',
|
82
90
|
:app_create_url => 'https://www.skylight.io/apps',
|
91
|
+
:merges_url => 'https://www.skylight.io/merges',
|
83
92
|
:validation_url => 'https://auth.skylight.io/agent/config',
|
84
93
|
:'daemon.lazy_start' => true,
|
85
94
|
:hostname => Util::Hostname.default_hostname,
|
86
95
|
:use_old_sql_lexer => false,
|
87
|
-
:report_max_spans_exceeded => false
|
96
|
+
:report_max_spans_exceeded => false,
|
97
|
+
:report_rails_env => true,
|
88
98
|
)
|
89
99
|
|
90
100
|
if Core::Util::Platform::OS != 'darwin'
|
@@ -126,6 +136,7 @@ module Skylight
|
|
126
136
|
:report_http_deflate,
|
127
137
|
:report_http_connect_timeout,
|
128
138
|
:report_http_read_timeout,
|
139
|
+
:report_http_disabled,
|
129
140
|
:'daemon.lazy_start',
|
130
141
|
:'daemon.exec_path',
|
131
142
|
:'daemon.lib_path',
|
@@ -243,7 +254,7 @@ module Skylight
|
|
243
254
|
def to_native_env
|
244
255
|
ret = super
|
245
256
|
|
246
|
-
ret << "SKYLIGHT_AUTHENTICATION" <<
|
257
|
+
ret << "SKYLIGHT_AUTHENTICATION" << authentication_with_meta
|
247
258
|
ret << "SKYLIGHT_VALIDATE_AUTHENTICATION" << "false"
|
248
259
|
|
249
260
|
ret
|
@@ -267,14 +278,18 @@ authentication: #{self[:authentication]}
|
|
267
278
|
#
|
268
279
|
#
|
269
280
|
|
270
|
-
def
|
281
|
+
def authentication_with_meta
|
271
282
|
token = get(:authentication)
|
272
283
|
|
273
|
-
if token
|
274
|
-
|
284
|
+
if token
|
285
|
+
meta = { }
|
286
|
+
meta.merge!(deploy.to_query_hash) if deploy
|
287
|
+
meta[:component] = component.to_s if component
|
288
|
+
meta[:reporting_env] = true if reporting_env?
|
289
|
+
|
275
290
|
# A pipe should be a safe delimiter since it's not in the standard token
|
276
291
|
# and is encoded by URI
|
277
|
-
token += "|#{
|
292
|
+
token += "|#{URI.encode_www_form(meta)}"
|
278
293
|
end
|
279
294
|
|
280
295
|
token
|
@@ -284,6 +299,13 @@ authentication: #{self[:authentication]}
|
|
284
299
|
@deploy ||= Util::Deploy.build(self)
|
285
300
|
end
|
286
301
|
|
302
|
+
def component
|
303
|
+
@component ||= Util::Component.new(get(:'component.environment'),
|
304
|
+
get(:'component.name'))
|
305
|
+
rescue ArgumentError => e
|
306
|
+
raise Core::ConfigError, e.message
|
307
|
+
end
|
308
|
+
|
287
309
|
private
|
288
310
|
|
289
311
|
def check_nfs(path)
|
@@ -291,5 +313,10 @@ authentication: #{self[:authentication]}
|
|
291
313
|
`stat -f -L -c %T #{path} 2>&1`.strip == 'nfs'
|
292
314
|
end
|
293
315
|
|
316
|
+
def reporting_env?
|
317
|
+
# true if component.environment was explicitly set,
|
318
|
+
# or if we are auto-detecting via the opt-in SKYLIGHT_REPORT_RAILS_ENV=true
|
319
|
+
!!(get(:report_rails_env) || get(:'component.environment'))
|
320
|
+
end
|
294
321
|
end
|
295
322
|
end
|
data/lib/skylight/railtie.rb
CHANGED
@@ -19,7 +19,7 @@ module Skylight
|
|
19
19
|
# net_http, action_controller, action_dispatch, action_view, and middleware are on by default
|
20
20
|
# See https://www.skylight.io/support/getting-more-from-skylight#available-instrumentation-options
|
21
21
|
# for a full list.
|
22
|
-
config.skylight.probes = ['net_http', 'action_controller', 'action_dispatch', 'action_view', 'middleware']
|
22
|
+
config.skylight.probes = ['net_http', 'action_controller', 'action_dispatch', 'action_view', 'middleware', 'active_job_enqueue']
|
23
23
|
|
24
24
|
# The position in the middleware stack to place Skylight
|
25
25
|
# Default is first, but can be `{ after: Middleware::Name }` or `{ before: Middleware::Name }`
|
@@ -35,5 +35,13 @@ module Skylight
|
|
35
35
|
super + "\n(To disable this message for all local apps, run `skylight disable_dev_warning`.)"
|
36
36
|
end
|
37
37
|
|
38
|
+
def load_skylight_config(app)
|
39
|
+
super.tap do |config|
|
40
|
+
if config[:report_rails_env]
|
41
|
+
config[:'component.environment'] ||= Rails.env.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
38
46
|
end
|
39
47
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Skylight
|
2
|
+
module Util
|
3
|
+
class Component
|
4
|
+
|
5
|
+
attr_accessor :environment, :name
|
6
|
+
|
7
|
+
NAME_FORMAT = /\A[a-z0-9-]+\z/
|
8
|
+
DEFAULT_NAME = 'web'.freeze
|
9
|
+
DEFAULT_ENVIRONMENT = 'production'.freeze
|
10
|
+
|
11
|
+
def initialize(environment, name)
|
12
|
+
@environment = environment || DEFAULT_ENVIRONMENT
|
13
|
+
@name = name || DEFAULT_NAME
|
14
|
+
|
15
|
+
raise ArgumentError, "environment can't be blank" if @environment.empty?
|
16
|
+
validate_string!(@environment, 'environment')
|
17
|
+
validate_string!(@name, 'name')
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"#{name}:#{environment}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def validate_string!(string, kind)
|
27
|
+
return true if string =~ NAME_FORMAT
|
28
|
+
raise ArgumentError, "#{kind} can only contain lowercase letters, numbers, and dashes"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/skylight/util/deploy.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'uri'
|
3
2
|
require 'skylight/core/util/logging'
|
4
3
|
|
5
4
|
module Skylight
|
@@ -37,14 +36,14 @@ module Skylight
|
|
37
36
|
nil
|
38
37
|
end
|
39
38
|
|
40
|
-
def
|
39
|
+
def to_query_hash
|
41
40
|
hash = {
|
42
41
|
timestamp: timestamp,
|
43
42
|
deploy_id: id.to_s[0..100] # Keep this sane
|
44
43
|
}
|
45
44
|
hash[:git_sha] = git_sha[0..40] if git_sha # A valid SHA will never exceed 40
|
46
45
|
hash[:description] = description[0..255] if description # Avoid massive descriptions
|
47
|
-
|
46
|
+
hash
|
48
47
|
end
|
49
48
|
|
50
49
|
end
|
data/lib/skylight/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skylight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tilde, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: skylight-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0.beta
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0.beta
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: puma
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rack-test
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,6 +190,7 @@ files:
|
|
176
190
|
- lib/skylight/cli.rb
|
177
191
|
- lib/skylight/cli/doctor.rb
|
178
192
|
- lib/skylight/cli/helpers.rb
|
193
|
+
- lib/skylight/cli/merger.rb
|
179
194
|
- lib/skylight/config.rb
|
180
195
|
- lib/skylight/data/cacert.pem
|
181
196
|
- lib/skylight/errors.rb
|
@@ -188,6 +203,7 @@ files:
|
|
188
203
|
- lib/skylight/railtie.rb
|
189
204
|
- lib/skylight/sinatra.rb
|
190
205
|
- lib/skylight/trace.rb
|
206
|
+
- lib/skylight/util/component.rb
|
191
207
|
- lib/skylight/util/deploy.rb
|
192
208
|
- lib/skylight/util/hostname.rb
|
193
209
|
- lib/skylight/util/http.rb
|
@@ -232,7 +248,7 @@ files:
|
|
232
248
|
- lib/skylight/vendor/cli/thor/util.rb
|
233
249
|
- lib/skylight/vendor/cli/thor/version.rb
|
234
250
|
- lib/skylight/version.rb
|
235
|
-
homepage:
|
251
|
+
homepage: https://www.skylight.io
|
236
252
|
licenses:
|
237
253
|
- Nonstandard
|
238
254
|
metadata: {}
|
@@ -247,9 +263,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
247
263
|
version: 2.2.7
|
248
264
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
249
265
|
requirements:
|
250
|
-
- - "
|
266
|
+
- - ">"
|
251
267
|
- !ruby/object:Gem::Version
|
252
|
-
version:
|
268
|
+
version: 1.3.1
|
253
269
|
requirements: []
|
254
270
|
rubyforge_project:
|
255
271
|
rubygems_version: 2.7.6
|