optic-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/optic/rails/railtie.rb +69 -25
- data/lib/optic/rails/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 037a36f5c71f671b7a16453a1607bd13ef93d7eb854ced372d6acf07009012a5
|
4
|
+
data.tar.gz: a1ce7fc57558e87b59f9614c1bd76dcb160ff312470423d945a364811c4be121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfa40babcd6bbef3b11661c1f0683b271517c5032f02fa3326a81638eb73a632cd77bc31ebb6afc02174d60541a06116e30c19f1c643a36554beb3c2f1487250
|
7
|
+
data.tar.gz: 81b948991bd3fea677fdd4a883bb7fbad0b31859dd1597eb5692b4a8c11110d0be7336d06655902bcf1dee18576e8aaa49efecb2a58d4f1e9903edebbda508af
|
data/lib/optic/rails/railtie.rb
CHANGED
@@ -1,37 +1,81 @@
|
|
1
|
+
require "action_cable_client"
|
2
|
+
require "eventmachine"
|
3
|
+
|
1
4
|
module Optic
|
2
5
|
module Rails
|
3
6
|
class Railtie < ::Rails::Railtie
|
4
7
|
initializer "optic_rails.launch_client_thread" do |app|
|
8
|
+
# TODO use tagged logger, make it clear which thread log messages are coming from
|
9
|
+
|
10
|
+
# Get configuration
|
5
11
|
api_key = app.config.optic_api_key # TODO fail gracefully if missing
|
6
12
|
uri = app.config.optic_uri
|
7
|
-
puts "Launching Optic client thread"
|
8
|
-
Thread.new do
|
9
|
-
|
10
|
-
EventMachine.run do
|
11
|
-
puts "connecting"
|
12
|
-
client = ActionCableClient.new(uri, { channel: "MetricsChannel" }, true, { "Authorization" => "Bearer #{api_key}" })
|
13
|
-
client.connected do
|
14
|
-
puts "successfully connected"
|
15
|
-
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
client.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
logger = ::Rails.logger
|
15
|
+
|
16
|
+
logger.debug "Starting supervisor thread"
|
17
|
+
supervisor = Thread.new do
|
18
|
+
loop do
|
19
|
+
logger.debug "Starting worker thread"
|
20
|
+
worker = Thread.new do
|
21
|
+
EventMachine.run do
|
22
|
+
client = ActionCableClient.new(uri, { channel: "MetricsChannel" }, true, { "Authorization" => "Bearer #{api_key}" })
|
23
|
+
|
24
|
+
client.connected do
|
25
|
+
logger.debug "Optic agent connected"
|
26
|
+
end
|
27
|
+
|
28
|
+
client.disconnected do
|
29
|
+
logger.warn "Optic agent disconnected, killing client thread"
|
30
|
+
EventMachine.stop
|
31
|
+
end
|
32
|
+
|
33
|
+
client.errored do |msg|
|
34
|
+
logger.warn "Optic agent error: #{msg}"
|
35
|
+
EventMachine.stop
|
36
|
+
# TODO stop worker?
|
37
|
+
end
|
38
|
+
|
39
|
+
client.subscribed do
|
40
|
+
logger.debug "Optic agent subscribed"
|
41
|
+
end
|
42
|
+
|
43
|
+
client.pinged do |msg|
|
44
|
+
logger.debug "Optic agent pinged: #{msg}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# called whenever a message is received from the server
|
48
|
+
client.received do |message|
|
49
|
+
logger.debug "Optic agent received: #{message}"
|
50
|
+
command = message["message"]["command"]
|
51
|
+
|
52
|
+
case command
|
53
|
+
when "request_schema"
|
54
|
+
logger.debug "Optic agent got schema request"
|
55
|
+
client.perform "schema", message: Optic::Rails.get_entities
|
56
|
+
logger.debug "Optic agent sent schema"
|
57
|
+
when "request_metrics"
|
58
|
+
logger.debug "Optic agent got metrics request"
|
59
|
+
client.perform "metrics", message: Optic::Rails.get_metrics(message["message"]["pivot"])
|
60
|
+
logger.debug "Optic agent sent metrics"
|
61
|
+
else
|
62
|
+
logger.warn "Optic agent got unknown command: #{command}"
|
63
|
+
end
|
64
|
+
end
|
33
65
|
end
|
66
|
+
|
67
|
+
logger.warn "Stopping worker thread"
|
34
68
|
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
worker.join
|
72
|
+
rescue => e
|
73
|
+
logger.error "Worker thread died with error", e
|
74
|
+
end
|
75
|
+
|
76
|
+
logger.warn "Supervisor thread detected dead worker, sleeping"
|
77
|
+
sleep 5.0
|
78
|
+
logger.debug "Supervisor thread done sleeping"
|
35
79
|
end
|
36
80
|
end
|
37
81
|
end
|
data/lib/optic/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optic-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Vaynshtok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: action_cable_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rails
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|