prosopite 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -0
- data/lib/prosopite.rb +26 -8
- data/lib/prosopite/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: e45d47e93e239165f045462c1247f33b4dae5796e1c852fd7a2a6ade0977ef2a
|
4
|
+
data.tar.gz: 25c2afb9c1340d3e16c3fcd2ba880becdfc674c54aaecba4d83566c6585998de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb734873fc1c396b5312dc70fe91a4c10a8adb4658bce2302559e8d61db22cc6e54429806e99e3014308b1e236b69a34f75e59bd3b789f36145843390776998
|
7
|
+
data.tar.gz: 626d2a7ebaf7553647672f137696adfe2aa70fe67589b7380c2366862c85022ee560dfbe2665f7580c4cd930a95d7c94e1a59557d4674c563379fef94e197846
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -77,6 +77,11 @@ Leg::Design.last(20) do |l|
|
|
77
77
|
end
|
78
78
|
```
|
79
79
|
|
80
|
+
## Why a new gem
|
81
|
+
|
82
|
+
Creating a new gem makes more sense since bullet's core mechanism is completely
|
83
|
+
different from prosopite's.
|
84
|
+
|
80
85
|
## How it works
|
81
86
|
|
82
87
|
Prosopite monitors all SQL queries using the Active Support instrumentation
|
data/lib/prosopite.rb
CHANGED
@@ -10,7 +10,9 @@ module Prosopite
|
|
10
10
|
:whitelist
|
11
11
|
|
12
12
|
def scan
|
13
|
+
@scan ||= false
|
13
14
|
return if scan?
|
15
|
+
|
14
16
|
subscribe
|
15
17
|
|
16
18
|
@query_counter = Hash.new(0)
|
@@ -18,6 +20,7 @@ module Prosopite
|
|
18
20
|
@query_caller = {}
|
19
21
|
|
20
22
|
@whitelist ||= []
|
23
|
+
|
21
24
|
@scan = true
|
22
25
|
end
|
23
26
|
|
@@ -28,6 +31,13 @@ module Prosopite
|
|
28
31
|
def finish
|
29
32
|
return unless scan?
|
30
33
|
|
34
|
+
@scan = false
|
35
|
+
|
36
|
+
create_notifications
|
37
|
+
send_notifications if @notifications.present?
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_notifications
|
31
41
|
@notifications = {}
|
32
42
|
|
33
43
|
@query_counter.each do |location_key, count|
|
@@ -51,19 +61,20 @@ module Prosopite
|
|
51
61
|
end
|
52
62
|
end
|
53
63
|
end
|
64
|
+
end
|
54
65
|
|
55
|
-
|
56
|
-
|
66
|
+
def fingerprint(query)
|
67
|
+
if ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')
|
68
|
+
mysql_fingerprint(query)
|
69
|
+
else
|
70
|
+
PgQuery.fingerprint(query)
|
71
|
+
end
|
57
72
|
end
|
58
73
|
|
59
74
|
# Many thanks to https://github.com/genkami/fluent-plugin-query-fingerprint/
|
60
|
-
def
|
75
|
+
def mysql_fingerprint(query)
|
61
76
|
query = query.dup
|
62
77
|
|
63
|
-
unless ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')
|
64
|
-
return PgQuery.fingerprint(query)
|
65
|
-
end
|
66
|
-
|
67
78
|
return "mysqldump" if query =~ %r#\ASELECT /\*!40001 SQL_NO_CACHE \*/ \* FROM `#
|
68
79
|
return "percona-toolkit" if query =~ %r#\*\w+\.\w+:[0-9]/[0-9]\*/#
|
69
80
|
if match = /\A\s*(call\s+\S+)\(/i.match(query)
|
@@ -108,6 +119,11 @@ module Prosopite
|
|
108
119
|
end
|
109
120
|
|
110
121
|
def send_notifications
|
122
|
+
@rails_logger ||= false
|
123
|
+
@stderr_logger ||= false
|
124
|
+
@prosopite_logger ||= false
|
125
|
+
@raise ||= false
|
126
|
+
|
111
127
|
notifications_str = ''
|
112
128
|
|
113
129
|
@notifications.each do |queries, kaller|
|
@@ -133,8 +149,8 @@ module Prosopite
|
|
133
149
|
end
|
134
150
|
|
135
151
|
def subscribe
|
152
|
+
@subscribed ||= false
|
136
153
|
return if @subscribed
|
137
|
-
@subscribed = true
|
138
154
|
|
139
155
|
ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, _, _, _, data|
|
140
156
|
sql = data[:sql]
|
@@ -150,6 +166,8 @@ module Prosopite
|
|
150
166
|
end
|
151
167
|
end
|
152
168
|
end
|
169
|
+
|
170
|
+
@subscribed = true
|
153
171
|
end
|
154
172
|
end
|
155
173
|
end
|
data/lib/prosopite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prosopite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mpampis Kostas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg_query
|