prosopite 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0ac26c0cb3a9cab7e0702a6a03b9ad1e369312b2b57548bce8a46c484efaecd
4
- data.tar.gz: 9fd0432b2de7d83b9f3605bb73cd7df23481d07714a7a8f904bac9397e602430
3
+ metadata.gz: e45d47e93e239165f045462c1247f33b4dae5796e1c852fd7a2a6ade0977ef2a
4
+ data.tar.gz: 25c2afb9c1340d3e16c3fcd2ba880becdfc674c54aaecba4d83566c6585998de
5
5
  SHA512:
6
- metadata.gz: '0360859d4cce85abf4f997a79c77b011ef6540d45fd98fe01b9ee7b3465c766df62beee31a1ea67d770c596497dc928d304b05df04af8536c164d9aaacd2e193'
7
- data.tar.gz: 4175589affdabf476f9d346d25117f5a171c94ad95b82b53d4141f39298fdb364e1baaa95f8d9ba95de86d28397b0489217ef632041d5841553a351b92ac3d48
6
+ metadata.gz: 3eb734873fc1c396b5312dc70fe91a4c10a8adb4658bce2302559e8d61db22cc6e54429806e99e3014308b1e236b69a34f75e59bd3b789f36145843390776998
7
+ data.tar.gz: 626d2a7ebaf7553647672f137696adfe2aa70fe67589b7380c2366862c85022ee560dfbe2665f7580c4cd930a95d7c94e1a59557d4674c563379fef94e197846
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prosopite (0.1.4)
4
+ prosopite (0.1.5)
5
5
  pg_query (~> 1.3)
6
6
 
7
7
  GEM
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
- @scan = false
56
- Prosopite.send_notifications if @notifications.present?
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 fingerprint(query)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prosopite
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
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
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-26 00:00:00.000000000 Z
11
+ date: 2021-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg_query