optic-rails 1.0.1 → 1.1.0
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.rb +35 -7
- data/lib/optic/rails/railtie.rb +13 -12
- data/lib/optic/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 318832502d533bdc4808c18673502e01d2d6328045d6584b2dfe50466bff7adb
|
4
|
+
data.tar.gz: ef480667fe0aedd7abd18d56b38dd29562f3718777bda9cc71c3705d066fc684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7594caeb737ca76c140c718d8cecc85080f3a7c3b21c9c547602b98f56630df389c17e299610a9452015f5d1222a3f80a97f6c61bde4072f137f4addcf1ceb23
|
7
|
+
data.tar.gz: a02c3eac8e8f416c633961ff71e8cbe23c3193ca426ae80170436761d422a4ca1740c15fca08ca0ea46b0a09a213facef9a0a1e76d45ea10dae92d7b55555c39
|
data/lib/optic/rails.rb
CHANGED
@@ -13,7 +13,7 @@ module Optic
|
|
13
13
|
{
|
14
14
|
name: klass.name,
|
15
15
|
table_name: klass.table_name,
|
16
|
-
|
16
|
+
entity_attribute_names: klass.attribute_names,
|
17
17
|
table_exists: klass.table_exists?,
|
18
18
|
associations: klass.reflect_on_all_associations.map do |reflection|
|
19
19
|
{
|
@@ -29,15 +29,35 @@ module Optic
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def metrics
|
32
|
+
def metrics(instructions)
|
33
33
|
with_connection do |connection|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
instructions.map do |instruction|
|
35
|
+
name = instruction["entity"]
|
36
|
+
entity = name.constantize.unscoped
|
37
|
+
|
38
|
+
query =
|
39
|
+
if pivot_name = instruction["pivot"]
|
40
|
+
pivot = pivot_name.constantize
|
41
|
+
join_path = instruction["join_path"]
|
42
|
+
joins = join_path.reverse.map(&:to_sym).inject { |acc, elt| { elt => acc } }
|
43
|
+
entity
|
44
|
+
.joins(joins)
|
45
|
+
.group(qualified_primary_key(pivot))
|
46
|
+
.select(qualified_primary_key(pivot), qualified_column(pivot, instruction["pivot_attribute_name"]), "COUNT(*)")
|
47
|
+
.to_sql
|
48
|
+
else
|
49
|
+
entity.select("COUNT(*)").to_sql
|
50
|
+
end
|
51
|
+
|
52
|
+
{ metric_configuration_id: instruction["metric_configuration_id"], result: connection.execute(query).to_a }
|
38
53
|
end
|
54
|
+
end
|
55
|
+
end
|
39
56
|
|
40
|
-
|
57
|
+
def instances(pivot_name)
|
58
|
+
with_connection do |connection|
|
59
|
+
pivot = pivot_name.constantize
|
60
|
+
{ instances: connection.execute(pivot.unscoped.select("*").to_sql).to_a }
|
41
61
|
end
|
42
62
|
end
|
43
63
|
|
@@ -57,6 +77,14 @@ module Optic
|
|
57
77
|
end
|
58
78
|
end
|
59
79
|
|
80
|
+
def qualified_column(entity, attribute)
|
81
|
+
%Q|"#{entity.table_name}"."#{attribute}"|
|
82
|
+
end
|
83
|
+
|
84
|
+
def qualified_primary_key(entity)
|
85
|
+
qualified_column(entity, entity.primary_key)
|
86
|
+
end
|
87
|
+
|
60
88
|
def active_record_klasses
|
61
89
|
base_klass = ApplicationRecord rescue ActiveRecord::Base
|
62
90
|
ObjectSpace.each_object(Class).find_all { |klass| klass < base_klass }
|
data/lib/optic/rails/railtie.rb
CHANGED
@@ -44,8 +44,8 @@ module Optic
|
|
44
44
|
EventMachine.stop
|
45
45
|
end
|
46
46
|
|
47
|
-
client.errored do |
|
48
|
-
logger.warn "Optic agent error: #{
|
47
|
+
client.errored do |data|
|
48
|
+
logger.warn "Optic agent error: #{data}"
|
49
49
|
EventMachine.stop
|
50
50
|
end
|
51
51
|
|
@@ -53,28 +53,29 @@ module Optic
|
|
53
53
|
logger.debug "Optic agent subscribed"
|
54
54
|
end
|
55
55
|
|
56
|
-
client.pinged do |
|
57
|
-
logger.debug "Optic agent pinged: #{
|
56
|
+
client.pinged do |data|
|
57
|
+
logger.debug "Optic agent pinged: #{data}"
|
58
58
|
client.perform "pong", message: {}
|
59
59
|
end
|
60
60
|
|
61
61
|
# called whenever a message is received from the server
|
62
|
-
client.received do |
|
63
|
-
logger.debug "Optic agent received: #{
|
64
|
-
|
62
|
+
client.received do |data|
|
63
|
+
logger.debug "Optic agent received: #{data}"
|
64
|
+
message = data["message"]
|
65
|
+
command = message["command"]
|
65
66
|
|
66
67
|
case command
|
67
68
|
when "request_schema"
|
68
|
-
logger.debug "Optic agent got schema request"
|
69
69
|
client.perform "schema", message: Optic::Rails.entities
|
70
|
-
logger.debug "Optic agent sent schema"
|
71
70
|
when "request_metrics"
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
client.perform "metrics", message: Optic::Rails.metrics(message["instructions"])
|
72
|
+
when "request_instances"
|
73
|
+
client.perform "instances", message: Optic::Rails.instances(message["pivot"])
|
75
74
|
else
|
76
75
|
logger.warn "Optic agent got unknown command: #{command}"
|
77
76
|
end
|
77
|
+
|
78
|
+
logger.debug "Optic agent completed command: #{command}"
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
data/lib/optic/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optic-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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-06-
|
11
|
+
date: 2018-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: action_cable_client
|