query_track 0.0.1 → 0.0.2

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: 5c122b692e3d0759318d5b4dc02d57a4d9b97435916c1fb4bfe19db40033bb22
4
- data.tar.gz: 72cd1a23053496a135b6a1414e92409a1ad581bad29fb06c2c4429cec4baf3d2
3
+ metadata.gz: 8f31144226dbe92c02734f5a0b93409093c8e91e0eaf603788117e55c912421a
4
+ data.tar.gz: e7d31eb7e89d0571f937001c95d8583e6c91ec0fb8078af329ec6074d187164d
5
5
  SHA512:
6
- metadata.gz: a98d3ea20b02490fa1b0da6bc1b41db364c7889f6e79191570af221ac2e4ff9fcf20228de2dc9f5e8e4d11cd96881271962c7a8feaadc522f1fcdc8b0ecad381
7
- data.tar.gz: 463aa697653af58b1a0272699f1cdfd71f1d12543fe38dbd7129f7a0ccaa85406af301f792d1568ae95351333ecbe0dc5ecd289739cc0f6badfd18964389f8f1
6
+ metadata.gz: aec3bfb5ba36a462103e316507bef71e6d047390b224654212aa90a87a078a45af249397a3cd5b9e05cfeb00665ecc164f28d5da7f20ee824fc408a45316c797
7
+ data.tar.gz: 6e19299d4c7c445d12959a276ba570b29758fbed2c6c69f3deaaf67d31836227078569c1d7550233687b2aa8f58e6eb044ecf15d341cc8a9ff985876b075cfef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.0.2 2019-07-22
2
+
3
+ Add console log, fix disabling of slack notifications. ([kirillshevch](https://github.com/kirillshevch/query_track/pull/2))
4
+
1
5
  # v0.0.1 2019-07-20
2
6
 
3
7
  Initial release with event processing, slack notifications and duration limit. ([kirillshevch](https://github.com/kirillshevch/query_track/pull/1))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- query_track (0.0.1)
4
+ query_track (0.0.2)
5
5
  activesupport
6
6
  dry-configurable
7
7
  slack_hook
@@ -36,7 +36,7 @@ GEM
36
36
  rspec-core (~> 3.8.0)
37
37
  rspec-expectations (~> 3.8.0)
38
38
  rspec-mocks (~> 3.8.0)
39
- rspec-core (3.8.0)
39
+ rspec-core (3.8.2)
40
40
  rspec-support (~> 3.8.0)
41
41
  rspec-expectations (3.8.4)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
data/README.md CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
+ ### SQL Duration Limit
27
+
26
28
  Specify SQL duration query limit:
27
29
 
28
30
  ```ruby
@@ -31,6 +33,21 @@ QueryTrack::Settings.configure do |config|
31
33
  end
32
34
  ```
33
35
 
36
+ ### Console Log
37
+
38
+ Enable console logs from config:
39
+
40
+ ```ruby
41
+ QueryTrack::Settings.configure do |config|
42
+ config.duration = 0.5
43
+ config.logs = true
44
+ end
45
+ ```
46
+
47
+ # <img src='https://github.com/kirillshevch/query_track/blob/master/examples/console.jpg' alt='Log Example' />
48
+
49
+ ### Slack Notifications
50
+
34
51
  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:
35
52
 
36
53
  ```ruby
@@ -40,7 +57,11 @@ QueryTrack::Settings.configure do |config|
40
57
  end
41
58
  ```
42
59
 
43
- # <img src='https://github.com/kirillshevch/query_track/blob/master/slack.jpg' alt='Incoming Hook Example' />
60
+ # <img src='https://github.com/kirillshevch/query_track/blob/master/examples/slack.jpg' alt='Incoming Hook Example' />
61
+
62
+ ### Filters
63
+
64
+ `TODO`
44
65
 
45
66
  ## Contributing
46
67
 
Binary file
File without changes
@@ -11,6 +11,7 @@ module QueryTrack
11
11
 
12
12
  if event.duration > QueryTrack::Settings.config.duration
13
13
  QueryTrack::Notifications::Slack.new(event.payload[:sql], event.duration).call
14
+ QueryTrack::Notifications::Log.new(event.payload[:sql], event.duration).call
14
15
  end
15
16
  end
16
17
  end
@@ -0,0 +1,20 @@
1
+ module QueryTrack
2
+ module Notifications
3
+ class Log
4
+ attr_reader :code, :duration, :webhook_url
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.logs
13
+
14
+ trace = QueryTrack::Trace.new(caller).call
15
+
16
+ QueryTrack.logger.info "\n#{code}\nDuration: #{duration}s\nTrace: #{trace}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -10,9 +10,11 @@ module QueryTrack
10
10
  end
11
11
 
12
12
  def call
13
+ return if webhook_url.nil? || webhook_url.empty?
14
+
13
15
  slack_hook = SlackHook::Incoming.new(webhook_url)
14
16
 
15
- trace = caller.select { |v| v =~ %r{app/} }[0]
17
+ trace = QueryTrack::Trace.new(caller).call
16
18
 
17
19
  payload = { blocks: blocks(trace) }
18
20
 
@@ -7,5 +7,7 @@ module QueryTrack
7
7
  setting :notifications do
8
8
  setting :slack, ''
9
9
  end
10
+
11
+ setting :logs, false
10
12
  end
11
13
  end
@@ -0,0 +1,13 @@
1
+ module QueryTrack
2
+ class Trace
3
+ attr_reader :full_trace
4
+
5
+ def initialize(full_trace)
6
+ @full_trace = full_trace
7
+ end
8
+
9
+ def call
10
+ full_trace.select { |v| v =~ %r{app/} }[0]
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module QueryTrack
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/query_track.rb CHANGED
@@ -3,11 +3,21 @@ require 'active_support/notifications'
3
3
  require 'slack_hook'
4
4
  require 'query_track/version'
5
5
  require 'query_track/settings'
6
+ require 'query_track/trace'
6
7
  require 'query_track/notifications/slack'
8
+ require 'query_track/notifications/log'
7
9
  require 'query_track/event_processor'
8
10
  require 'subscriber'
11
+ require 'logger'
9
12
 
10
13
  module QueryTrack
11
- class Error < StandardError; end
12
- # Your code goes here...
14
+ class << self
15
+ attr_writer :logger
16
+
17
+ def logger
18
+ @logger ||= Logger.new($stdout).tap do |log|
19
+ log.progname = self.name
20
+ end
21
+ end
22
+ end
13
23
  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.1
4
+ version: 0.0.2
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-07-20 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -141,14 +141,17 @@ files:
141
141
  - Rakefile
142
142
  - bin/console
143
143
  - bin/setup
144
+ - examples/console.jpg
145
+ - examples/slack.jpg
144
146
  - lib/query_track.rb
145
147
  - lib/query_track/event_processor.rb
148
+ - lib/query_track/notifications/log.rb
146
149
  - lib/query_track/notifications/slack.rb
147
150
  - lib/query_track/settings.rb
151
+ - lib/query_track/trace.rb
148
152
  - lib/query_track/version.rb
149
153
  - lib/subscriber.rb
150
154
  - query_track.gemspec
151
- - slack.jpg
152
155
  homepage: https://github.com/kirillshevch/query_track
153
156
  licenses:
154
157
  - MIT