query_track 0.0.8 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11eafb45e2ddc8bb353f21db9208a07f66cca5ebc089985ca4521a5560f7fcfb
4
- data.tar.gz: fb7b68d7a32a8c28b8554009e18b39f681b922ead72052c842e7d14dfd937359
3
+ metadata.gz: 01a6865f61ee0960a492d72de93188ecdf6e82fc053a3fd18d2c7ece60732eb7
4
+ data.tar.gz: ab85a1ae63609d4bcea01d2ea80b92d9c8c5d8f84fac06106ba9d0adc1c5679b
5
5
  SHA512:
6
- metadata.gz: c63eb4682ce2bf6fc7f174a7bb6b6983bec52e6ed5c174a309dbe73aa9cda1b251f079b455edb0e7f56a0e853c9850ee3841667c73649fb000373ca73daf0139
7
- data.tar.gz: 60a112cc30412a12293ed6f52923b101e951488719227802d1794a43b39fae7c2de6bc56550a8d3eca32bc6a3ecd4d4fee75ad696297103fe53dc1aa6371ea3b
6
+ metadata.gz: d8c187430dd1cf118ad844ee6f997e691ee6bd265a5157dd59601e68ff7ac6a7bc48ae563500d678caece8fba0e13cd055d1db48810232e719190afcae9dcc93
7
+ data.tar.gz: 6652e86015b8bb6de17a7b35afc28f3df14f992906670bfe4055ada592902f54841fe6e464d58e575c117e2a4c1987957d06069daeadbb4bb7864e3ef010af7e
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with Rake
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.0.10 2020-08-07
2
+
3
+ Added custom app directory ([evanboho](https://github.com/kirillshevch/query_track/pull/60))
4
+
5
+ # v0.0.9 2019-12-21
6
+
7
+ Added custom handles ([kirillshevch](https://github.com/kirillshevch/query_track/pull/29))
8
+
1
9
  # v0.0.8 2019-08-17
2
10
 
3
11
  Added enabled/disable config ([kirillshevch](https://github.com/kirillshevch/query_track/pull/13))
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.11)
5
5
  activesupport
6
6
  dry-configurable
7
7
  slack_hook
@@ -9,63 +9,67 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.0.0)
12
+ activesupport (6.1.5)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
17
- zeitwerk (~> 2.1, >= 2.1.8)
18
- ast (2.4.0)
19
- byebug (11.0.1)
20
- concurrent-ruby (1.1.5)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ ast (2.4.1)
19
+ byebug (11.1.3)
20
+ concurrent-ruby (1.1.10)
21
21
  diff-lcs (1.3)
22
- dry-configurable (0.8.3)
22
+ dry-configurable (0.13.0)
23
23
  concurrent-ruby (~> 1.0)
24
- dry-core (~> 0.4, >= 0.4.7)
25
- dry-core (0.4.9)
24
+ dry-core (~> 0.6)
25
+ dry-core (0.7.1)
26
26
  concurrent-ruby (~> 1.0)
27
- i18n (1.6.0)
27
+ i18n (1.10.0)
28
28
  concurrent-ruby (~> 1.0)
29
- jaro_winkler (1.5.3)
30
- minitest (5.11.3)
31
- parallel (1.17.0)
32
- parser (2.6.3.0)
33
- ast (~> 2.4.0)
29
+ minitest (5.15.0)
30
+ parallel (1.19.2)
31
+ parser (2.7.1.4)
32
+ ast (~> 2.4.1)
34
33
  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)
34
+ rake (13.0.1)
35
+ regexp_parser (1.7.1)
36
+ rexml (3.2.5)
37
+ rspec (3.9.0)
38
+ rspec-core (~> 3.9.0)
39
+ rspec-expectations (~> 3.9.0)
40
+ rspec-mocks (~> 3.9.0)
41
+ rspec-core (3.9.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-expectations (3.9.0)
43
44
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.8.0)
45
- rspec-mocks (3.8.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-mocks (3.9.0)
46
47
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.8.0)
48
- rspec-support (3.8.2)
49
- rubocop (0.74.0)
50
- jaro_winkler (~> 1.5.1)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-support (3.9.0)
50
+ rubocop (0.87.1)
51
51
  parallel (~> 1.10)
52
- parser (>= 2.6)
52
+ parser (>= 2.7.1.1)
53
53
  rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.7)
55
+ rexml
56
+ rubocop-ast (>= 0.1.0, < 1.0)
54
57
  ruby-progressbar (~> 1.7)
55
- unicode-display_width (>= 1.4.0, < 1.7)
58
+ unicode-display_width (>= 1.4.0, < 2.0)
59
+ rubocop-ast (0.1.0)
60
+ parser (>= 2.7.0.1)
56
61
  ruby-progressbar (1.10.1)
57
62
  slack_hook (0.1.2)
58
- thread_safe (0.3.6)
59
- tzinfo (1.2.5)
60
- thread_safe (~> 0.1)
61
- unicode-display_width (1.6.0)
62
- zeitwerk (2.1.9)
63
+ tzinfo (2.0.4)
64
+ concurrent-ruby (~> 1.0)
65
+ unicode-display_width (1.7.0)
66
+ zeitwerk (2.5.4)
63
67
 
64
68
  PLATFORMS
65
69
  ruby
66
70
 
67
71
  DEPENDENCIES
68
- bundler (~> 1.17)
72
+ bundler
69
73
  byebug
70
74
  query_track!
71
75
  rake
data/README.md CHANGED
@@ -1,27 +1,18 @@
1
1
  # QueryTrack
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/query_track.svg)](https://badge.fury.io/rb/query_track)
4
- [![CircleCI](https://circleci.com/gh/kirillshevch/query_track.svg?style=svg)](https://circleci.com/gh/kirillshevch/query_track)
5
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/15b0a6c0a1838b216db8/maintainability)](https://codeclimate.com/github/kirillshevch/query_track/maintainability)
6
5
 
7
6
  Tool for finding time-consuming database queries for ActiveRecord-based Rails Apps. Provides Slack notifications with backtrace, raw SQL, time duration, etc.
8
7
 
9
8
  ## Installation
10
9
 
11
- Add this line to your application's Gemfile:
10
+ Add this line to your application's `Gemfile` and then execute `bundle install`:
12
11
 
13
12
  ```ruby
14
13
  gem 'query_track'
15
14
  ```
16
15
 
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install query_track
24
-
25
16
  ## Usage
26
17
 
27
18
  ### SQL Duration Limit
@@ -49,7 +40,7 @@ end
49
40
 
50
41
  ### Filters
51
42
 
52
- To avoid noisy warnings from used gems, and places where fat queries are justified, you can filters SQL by backtrace.
43
+ To avoid noisy warnings from used gems, and places where fat queries are justified, you can filters SQL by backtrace.
53
44
  For example, you have installed `activeadmin` and want to skip everything from `app/admin`:
54
45
 
55
46
  ```ruby
@@ -58,10 +49,22 @@ QueryTrack::Settings.configure do |config|
58
49
  config.filters = ['app/admin']
59
50
  end
60
51
  ```
52
+ ### App Directory
53
+
54
+ QueryTrack finds the trace by filtering the caller by the app directory.
55
+ By default, the app directory is set to 'app', the default for Rails apps.
56
+ For apps that have a non-stanard app directory, this can be set with the `app_dir` config field:
57
+
58
+ ```ruby
59
+ QueryTrack::Settings.configure do |config|
60
+ config.duration = 0.5
61
+ config.app_dir = 'backend'
62
+ end
63
+ ```
61
64
 
62
65
  ### Enable/Disable toggle
63
66
 
64
- Enable/disable with ENV variables to turn it on/off without code push. By default *QueryTrack* is enabled.
67
+ Enable/disable with ENV variables to turn it on/off without code push. By default *QueryTrack* is enabled.
65
68
 
66
69
  ```ruby
67
70
  QueryTrack::Settings.configure do |config|
@@ -72,7 +75,7 @@ end
72
75
 
73
76
  ### Slack Notifications
74
77
 
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:
78
+ 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
79
 
77
80
  ```ruby
78
81
  QueryTrack::Settings.configure do |config|
@@ -83,6 +86,27 @@ end
83
86
 
84
87
  # <img src='https://github.com/kirillshevch/query_track/blob/master/examples/slack.jpg' alt='Incoming Hook Example' />
85
88
 
89
+ ## Custom Notifications (Handlers)
90
+
91
+ 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.)
92
+
93
+ ```ruby
94
+ QueryTrack::Settings.configure do |config|
95
+ config.duration = 0.5
96
+ config.notifications.custom_handler = -> (sql, duration, trace) {
97
+ # data processing...
98
+ }
99
+ end
100
+ ```
101
+
102
+ ## Production Usage Notes
103
+
104
+ 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.
105
+
106
+ Subscription to SQL events and checking duration time actually take insignificant time in milliseconds.
107
+
108
+ If your project is horizontally scaled, you can install `query_track` for one of the node to avoid performance degrade for whole application.
109
+
86
110
  ## Contributing
87
111
 
88
112
  Bug reports and pull requests are welcome on GitHub at https://github.com/kirillshevch/query_track.
@@ -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
@@ -1,7 +1,7 @@
1
1
  module QueryTrack
2
2
  module Notifications
3
3
  class Log
4
- attr_reader :code, :duration, :webhook_url
4
+ attr_reader :code, :duration
5
5
 
6
6
  def initialize(code, duration)
7
7
  @code = code.strip
@@ -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
@@ -13,5 +14,7 @@ module QueryTrack
13
14
  setting :filters, []
14
15
 
15
16
  setting :enabled, true
17
+
18
+ setting :app_dir, 'app'
16
19
  end
17
20
  end
@@ -7,7 +7,7 @@ module QueryTrack
7
7
  end
8
8
 
9
9
  def call
10
- full_trace.select { |v| v =~ %r{app/} }[0]
10
+ full_trace.select { |v| v =~ %r{#{QueryTrack::Settings.config.app_dir}/} }[0]
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module QueryTrack
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.11'
3
3
  end
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'
data/query_track.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'slack_hook'
27
27
  spec.add_dependency 'dry-configurable'
28
28
 
29
- spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'bundler'
30
30
  spec.add_development_dependency 'rubocop'
31
31
  spec.add_development_dependency 'rake'
32
32
  spec.add_development_dependency 'rspec'
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.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Shevchenko
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-17 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.17'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.17'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
- - ".circleci/config.yml"
132
+ - ".github/workflows/ruby.yml"
133
133
  - ".gitignore"
134
134
  - ".rspec"
135
135
  - ".rubocop.yml"
@@ -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
@@ -157,7 +158,7 @@ homepage: https://github.com/kirillshevch/query_track
157
158
  licenses:
158
159
  - MIT
159
160
  metadata: {}
160
- post_install_message:
161
+ post_install_message:
161
162
  rdoc_options: []
162
163
  require_paths:
163
164
  - lib
@@ -172,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
173
  - !ruby/object:Gem::Version
173
174
  version: '0'
174
175
  requirements: []
175
- rubygems_version: 3.0.3
176
- signing_key:
176
+ rubygems_version: 3.0.9
177
+ signing_key:
177
178
  specification_version: 4
178
179
  summary: Finding time-consuming database queries for ActiveRecord-based Rails Apps
179
180
  test_files: []
data/.circleci/config.yml DELETED
@@ -1,25 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.5-node
6
-
7
- steps:
8
- - checkout
9
-
10
- - restore_cache:
11
- keys:
12
- - query-track-bundle-v2-{{ checksum "query_track.gemspec" }}
13
-
14
- - run:
15
- name: Bundle Install
16
- command: bundle check || bundle install
17
-
18
- - save_cache:
19
- key: query-track-bundle-v2-{{ checksum "query_track.gemspec" }}
20
- paths:
21
- - vendor/bundle
22
-
23
- - run:
24
- name: Run Rspec
25
- command: bundle exec rspec