query_track 0.0.8 → 0.0.9

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: 11eafb45e2ddc8bb353f21db9208a07f66cca5ebc089985ca4521a5560f7fcfb
4
- data.tar.gz: fb7b68d7a32a8c28b8554009e18b39f681b922ead72052c842e7d14dfd937359
3
+ metadata.gz: 3721d96e0c635e1633e6da2f049188b125b96310c5af307abfa432755986f2da
4
+ data.tar.gz: 8096cc6850c1b5e4fa8bf54b4714616fb6f8433ac7ebcec95f166fddf6e5313c
5
5
  SHA512:
6
- metadata.gz: c63eb4682ce2bf6fc7f174a7bb6b6983bec52e6ed5c174a309dbe73aa9cda1b251f079b455edb0e7f56a0e853c9850ee3841667c73649fb000373ca73daf0139
7
- data.tar.gz: 60a112cc30412a12293ed6f52923b101e951488719227802d1794a43b39fae7c2de6bc56550a8d3eca32bc6a3ecd4d4fee75ad696297103fe53dc1aa6371ea3b
6
+ metadata.gz: e454a83da93cdbbd55c183c2a4d68927e6016e8c6b48638f872348d22c1974b4368323d4b5aa1d4fe25b867ccb7d223cb0f542d88fc2abbc2b4249f32452f820
7
+ data.tar.gz: a330eddd0467e492f6b39c6232ed1132f43a3d5e01e2bca3746dddeddac4da911946f811e51b6bbf8fb18b0eefa157e3a755fc3ba521bb3f51f00e475c99d3cb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- query_track (0.0.8)
4
+ query_track (0.0.9)
5
5
  activesupport
6
6
  dry-configurable
7
7
  slack_hook
@@ -9,44 +9,44 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.0.0)
12
+ activesupport (6.0.2.1)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 0.7, < 2)
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
- zeitwerk (~> 2.1, >= 2.1.8)
17
+ zeitwerk (~> 2.2)
18
18
  ast (2.4.0)
19
19
  byebug (11.0.1)
20
20
  concurrent-ruby (1.1.5)
21
21
  diff-lcs (1.3)
22
- dry-configurable (0.8.3)
22
+ dry-configurable (0.9.0)
23
23
  concurrent-ruby (~> 1.0)
24
24
  dry-core (~> 0.4, >= 0.4.7)
25
25
  dry-core (0.4.9)
26
26
  concurrent-ruby (~> 1.0)
27
- i18n (1.6.0)
27
+ i18n (1.7.0)
28
28
  concurrent-ruby (~> 1.0)
29
29
  jaro_winkler (1.5.3)
30
- minitest (5.11.3)
31
- parallel (1.17.0)
32
- parser (2.6.3.0)
30
+ minitest (5.13.0)
31
+ parallel (1.18.0)
32
+ parser (2.6.5.0)
33
33
  ast (~> 2.4.0)
34
34
  rainbow (3.0.0)
35
- rake (12.3.3)
36
- rspec (3.8.0)
37
- rspec-core (~> 3.8.0)
38
- rspec-expectations (~> 3.8.0)
39
- rspec-mocks (~> 3.8.0)
40
- rspec-core (3.8.2)
41
- rspec-support (~> 3.8.0)
42
- rspec-expectations (3.8.4)
35
+ rake (13.0.1)
36
+ rspec (3.9.0)
37
+ rspec-core (~> 3.9.0)
38
+ rspec-expectations (~> 3.9.0)
39
+ rspec-mocks (~> 3.9.0)
40
+ rspec-core (3.9.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-expectations (3.9.0)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.8.0)
45
- rspec-mocks (3.8.0)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-mocks (3.9.0)
46
46
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.8.0)
48
- rspec-support (3.8.2)
49
- rubocop (0.74.0)
47
+ rspec-support (~> 3.9.0)
48
+ rspec-support (3.9.0)
49
+ rubocop (0.75.1)
50
50
  jaro_winkler (~> 1.5.1)
51
51
  parallel (~> 1.10)
52
52
  parser (>= 2.6)
@@ -59,7 +59,7 @@ GEM
59
59
  tzinfo (1.2.5)
60
60
  thread_safe (~> 0.1)
61
61
  unicode-display_width (1.6.0)
62
- zeitwerk (2.1.9)
62
+ zeitwerk (2.2.2)
63
63
 
64
64
  PLATFORMS
65
65
  ruby
data/README.md CHANGED
@@ -8,20 +8,12 @@ Tool for finding time-consuming database queries for ActiveRecord-based Rails A
8
8
 
9
9
  ## Installation
10
10
 
11
- Add this line to your application's Gemfile:
11
+ Add this line to your application's `Gemfile` and then execute `bundle install`:
12
12
 
13
13
  ```ruby
14
14
  gem 'query_track'
15
15
  ```
16
16
 
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install query_track
24
-
25
17
  ## Usage
26
18
 
27
19
  ### SQL Duration Limit
@@ -72,7 +64,7 @@ end
72
64
 
73
65
  ### Slack Notifications
74
66
 
75
- To receive notifications about slow queries into Slack, you need to install [incoming-webhooks](https://reflow-files.slack.com/apps/A0F7XDUAZ-incoming-webhooks) and put link into config file:
67
+ To receive notifications about slow queries into Slack, you need to install [incoming-webhooks](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks) and put link into config file:
76
68
 
77
69
  ```ruby
78
70
  QueryTrack::Settings.configure do |config|
@@ -83,6 +75,27 @@ end
83
75
 
84
76
  # <img src='https://github.com/kirillshevch/query_track/blob/master/examples/slack.jpg' alt='Incoming Hook Example' />
85
77
 
78
+ ## Custom Notifications (Handlers)
79
+
80
+ You can write your own handler for slow queries. Send data to any source(for e.g. to logs storage) or make notification for another source(Email, Messengers, etc.)
81
+
82
+ ```ruby
83
+ QueryTrack::Settings.configure do |config|
84
+ config.duration = 0.5
85
+ config.notifications.custom_handler = -> (sql, duration, trace) {
86
+ # data processing...
87
+ }
88
+ end
89
+ ```
90
+
91
+ ## Production Usage Notes
92
+
93
+ When [QueryTrack](https://github.com/kirillshevch/query_track/blob/master/lib/query_track/notifications/slack.rb#L21) send slack hooks, request is executed in separate thread. So there should be no synchronous delays.
94
+
95
+ Subscription to SQL events and checking duration time actually take insignificant time in milliseconds.
96
+
97
+ If your project is horizontally scaled, you can install `query_track` for one of the node to avoid performance degrade for whole application.
98
+
86
99
  ## Contributing
87
100
 
88
101
  Bug reports and pull requests are welcome on GitHub at https://github.com/kirillshevch/query_track.
data/lib/query_track.rb CHANGED
@@ -5,6 +5,7 @@ require 'query_track/version'
5
5
  require 'query_track/settings'
6
6
  require 'query_track/trace'
7
7
  require 'query_track/filters'
8
+ require 'query_track/notifications/custom'
8
9
  require 'query_track/notifications/slack'
9
10
  require 'query_track/notifications/log'
10
11
  require 'query_track/event_processor'
@@ -16,6 +16,7 @@ module QueryTrack
16
16
  if duration_seconds > QueryTrack::Settings.config.duration
17
17
  QueryTrack::Notifications::Slack.new(event.payload[:sql], duration_seconds).call
18
18
  QueryTrack::Notifications::Log.new(event.payload[:sql], duration_seconds).call
19
+ QueryTrack::Notifications::Custom.new(event.payload[:sql], duration_seconds).call
19
20
  end
20
21
  end
21
22
 
@@ -0,0 +1,20 @@
1
+ module QueryTrack
2
+ module Notifications
3
+ class Custom
4
+ attr_reader :code, :duration
5
+
6
+ def initialize(code, duration)
7
+ @code = code.strip
8
+ @duration = duration
9
+ end
10
+
11
+ def call
12
+ return unless QueryTrack::Settings.config.notifications.custom_handler
13
+
14
+ trace = QueryTrack::Trace.new(caller).call
15
+
16
+ QueryTrack::Settings.config.notifications.custom_handler.call(code, duration, trace)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,6 +6,7 @@ module QueryTrack
6
6
 
7
7
  setting :notifications do
8
8
  setting :slack, ''
9
+ setting :custom_handler
9
10
  end
10
11
 
11
12
  setting :logs, false
@@ -1,3 +1,3 @@
1
1
  module QueryTrack
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_track
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Shevchenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-17 00:00:00.000000000 Z
11
+ date: 2019-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -146,6 +146,7 @@ files:
146
146
  - lib/query_track.rb
147
147
  - lib/query_track/event_processor.rb
148
148
  - lib/query_track/filters.rb
149
+ - lib/query_track/notifications/custom.rb
149
150
  - lib/query_track/notifications/log.rb
150
151
  - lib/query_track/notifications/slack.rb
151
152
  - lib/query_track/settings.rb