dry-monitor 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rubocop_todo.yml DELETED
@@ -1,7 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2015-10-30 01:32:46 +0000 using RuboCop version 0.34.2.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
- bundler_args: --without benchmarks tools
5
- before_install: gem update --system
6
- before_script:
7
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
8
- - chmod +x ./cc-test-reporter
9
- - ./cc-test-reporter before-build
10
- after_script:
11
- - "[ -d coverage ] && ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
12
- script:
13
- - bundle exec rake ci
14
- rvm:
15
- - 2.6.0
16
- - 2.5.3
17
- - 2.4.5
18
- - 2.3.8
19
- - jruby-9.2.5.0
20
- env:
21
- global:
22
- - COVERAGE=true
23
- notifications:
24
- email: false
25
- webhooks:
26
- urls:
27
- - https://webhooks.gitter.im/e/19098b4253a72c9796db
28
- on_success: change # options: [always|never|change] default: always
29
- on_failure: always # options: [always|never|change] default: always
30
- on_start: false # default: false
data/CONTRIBUTING.md DELETED
@@ -1,29 +0,0 @@
1
- # Issue Guidelines
2
-
3
- ## Reporting bugs
4
-
5
- If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
6
-
7
- ## Reporting feature requests
8
-
9
- Report a feature request **only after discussing it first on [discuss.dry-rb.org](https://discuss.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
-
11
- ## Reporting questions, support requests, ideas, concerns etc.
12
-
13
- **PLEASE DON'T** - use [discuss.dry-rb.org](http://discuss.dry-rb.org) instead.
14
-
15
- # Pull Request Guidelines
16
-
17
- A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
18
-
19
- Other requirements:
20
-
21
- 1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
22
- 2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
23
- 3) Add API documentation if it's a new feature
24
- 4) Update API documentation if it changes an existing feature
25
- 5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
26
-
27
- # Asking for help
28
-
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discuss.dry-rb.org](https://discuss.dry-rb.org).
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'dry-events', git: 'https://github.com/dry-rb/dry-events.git', branch: 'master'
6
-
7
- group :test do
8
- gem 'rack'
9
- gem 'simplecov', platform: :mri, require: false
10
- end
11
-
12
- group :tools do
13
- gem 'byebug', platform: :mri
14
- end
data/Rakefile DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
-
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
5
-
6
- require 'rspec/core'
7
- require 'rspec/core/rake_task'
8
-
9
- task default: :spec
10
-
11
- desc 'Run all specs in spec directory'
12
- RSpec::Core::RakeTask.new(:spec)
13
-
14
- desc "Run CI tasks"
15
- task ci: [:spec]
data/rakelib/rubocop.rake DELETED
@@ -1,18 +0,0 @@
1
- begin
2
- require 'rubocop/rake_task'
3
-
4
- Rake::Task[:default].enhance [:rubocop]
5
-
6
- RuboCop::RakeTask.new do |task|
7
- task.options << '--display-cop-names'
8
- end
9
-
10
- namespace :rubocop do
11
- desc 'Generate a configuration file acting as a TODO list.'
12
- task :auto_gen_config do
13
- exec 'bundle exec rubocop --auto-gen-config'
14
- end
15
- end
16
-
17
- rescue LoadError
18
- end
@@ -1,37 +0,0 @@
1
- RSpec.describe 'Subscribing to instrumentation events' do
2
- subject(:notifications) { Dry::Monitor::Notifications.new(:app) }
3
-
4
- before do
5
- Dry::Monitor::Notifications.register_event(:sql, { name: 'rom[sql]' })
6
- end
7
-
8
- describe '#instrument' do
9
- it 'allows subscribing via block' do
10
- captured = []
11
- payload = { query: 'SELECT 1 FROM users' }
12
-
13
- notifications.subscribe(:sql) do |event|
14
- captured << [event.id, event[:query]]
15
- end
16
-
17
- notifications.instrument(:sql, payload)
18
-
19
- expect(captured).to eql([[:sql, 'SELECT 1 FROM users']])
20
- end
21
-
22
- it 'allows instrumenting via block' do
23
- captured = []
24
- payload = { query: 'SELECT 1 FROM users' }
25
-
26
- notifications.subscribe(:sql) do |event|
27
- captured << [event.id, event[:query]]
28
- end
29
-
30
- notifications.instrument(:sql, payload) do
31
- payload
32
- end
33
-
34
- expect(captured).to eql([[:sql, 'SELECT 1 FROM users']])
35
- end
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- RSpec.describe Dry::Monitor::Logger do
2
- subject(:logger) do
3
- Dry::Monitor::Logger.new($stdout)
4
- end
5
-
6
- describe '#info' do
7
- it 'outputs with configured formatter' do
8
- expect { logger.info('test') }.to output("test\n").to_stdout
9
- end
10
- end
11
- end
@@ -1,98 +0,0 @@
1
- RSpec.describe Dry::Monitor::Rack::Middleware do
2
- subject(:middleware) { Dry::Monitor::Rack::Middleware.new(notifications).new(rack_app) }
3
-
4
- let(:notifications) do
5
- Dry::Monitor::Notifications.new(:test)
6
- end
7
-
8
- let(:rack_app) do
9
- double(:rack_app)
10
- end
11
-
12
- let(:log_file_path) do
13
- SPEC_ROOT.join('test_logs/middleware.log')
14
- end
15
-
16
- let(:rack_logger) do
17
- Dry::Monitor::Rack::Logger.new(Dry::Monitor::Logger.new(log_file_path))
18
- end
19
-
20
- let(:env) do
21
- { 'REQUEST_METHOD' => 'GET',
22
- 'PATH_INFO' => '/hello-world',
23
- 'REMOTE_ADDR' => '0.0.0.0',
24
- 'QUERY_STRING' => query_params }
25
- end
26
-
27
- let(:query_params) do
28
- %w[
29
- _csrf=123456
30
- password=secret
31
- user[password]=secret
32
- others[][password]=secret1
33
- others[][password]=secret2
34
- foo=bar
35
- one=1
36
- ids[]=1
37
- ids[]=2
38
- ].join('&')
39
- end
40
-
41
- describe '#call' do
42
- before do
43
- File.open(log_file_path, 'w').close
44
- rack_logger.attach(middleware)
45
- end
46
-
47
- it 'triggers start/stop events for with a rack request' do
48
- expect(rack_app).to receive(:call).with(env).and_return([200, :total_success])
49
-
50
- status, response = middleware.call(env)
51
-
52
- expect(status).to be(200)
53
- expect(response).to be(:total_success)
54
-
55
- log_file_content = File.read(log_file_path)
56
-
57
- expect(log_file_content).to include('Started GET "/hello-world"')
58
- expect(log_file_content).to include('Finished GET "/hello-world"')
59
- expect(log_file_content).to include('Query parameters {"_csrf"=>"[FILTERED]", "password"=>"[FILTERED]", "user"=>{"password"=>"[FILTERED]"}, "others"=>[{"password"=>"[FILTERED]"}, {"password"=>"[FILTERED]"}], "foo"=>"bar", "one"=>"1", "ids"=>["1", "2"]}')
60
- end
61
- end
62
-
63
- describe '#on' do
64
- it 'subscribe a listener to a specific request event' do
65
- captured = []
66
-
67
- middleware.on(:error) do |event|
68
- captured << event[:exception]
69
- captured << event[:env]
70
- end
71
-
72
- exception = 'oops'
73
- env = { 'REQUEST_METHOD' => 'GET' }
74
-
75
- middleware.instrument(:error, exception: exception, env: env)
76
-
77
- expect(captured).to eql([exception, env])
78
- end
79
- end
80
-
81
- describe 'rack logger' do
82
- before do
83
- File.open(log_file_path, 'w').close
84
- rack_logger.attach(middleware)
85
- end
86
-
87
- it 'logs exceptions' do
88
- exception = double(:exception, message: 'oops', backtrace: ['/some/path.rb'])
89
-
90
- middleware.instrument(:error, exception: exception, env: env)
91
-
92
- log_file_content = File.read(log_file_path)
93
-
94
- expect(log_file_content).to include('oops')
95
- expect(log_file_content).to include('/some/path.rb')
96
- end
97
- end
98
- end
@@ -1,58 +0,0 @@
1
- RSpec.describe Dry::Monitor::SQL::Logger do
2
- subject(:logger) { sql_logger.new(Dry::Monitor::Logger.new(log_file_path)) }
3
-
4
- let(:notifications) do
5
- Dry::Monitor::Notifications.new(:test)
6
- end
7
-
8
- let(:log_file_path) do
9
- SPEC_ROOT.join('test_logs/sql.log')
10
- end
11
-
12
- let(:log_file_content) { File.read(log_file_path) }
13
-
14
- shared_context '#subscribe' do
15
- let(:query) do
16
- 'SELECT id, name FROM users'
17
- end
18
-
19
- before do
20
- File.open(log_file_path, 'w').close
21
-
22
- logger.subscribe(notifications)
23
-
24
- notifications.instrument(:sql, name: 'users', query: query) do
25
- sleep 0.0025
26
- end
27
- end
28
-
29
- it 'writes sql query info' do
30
- expect(log_file_content).to include('Loaded "users" in')
31
- end
32
- end
33
-
34
- context 'without colors' do
35
- let(:sql_logger) do
36
- Dry::Monitor::SQL::Logger.load_extensions(:rouge_colorizer)
37
- Dry::Monitor::SQL::Logger
38
- end
39
-
40
- include_context '#subscribe' do
41
- let(:colored_query) do
42
- "\e[38;5;203mSELECT\e[39m\e[38;5;230m"
43
- end
44
-
45
- it 'writes sql query in logs' do
46
- expect(log_file_content).to include(colored_query)
47
- end
48
- end
49
- end
50
-
51
- context 'without colors' do
52
- let(:sql_logger) do
53
- Dry::Monitor::SQL::Logger
54
- end
55
-
56
- include_context '#subscribe'
57
- end
58
- end
data/spec/spec_helper.rb DELETED
@@ -1,22 +0,0 @@
1
- if RUBY_ENGINE == 'ruby' && ENV['CI'] == 'true'
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter '/spec/'
5
- end
6
- end
7
-
8
- begin
9
- require 'byebug'
10
- rescue LoadError; end
11
-
12
- require 'dry-monitor'
13
- Dry::Monitor.load_extensions(:sql, :rack)
14
-
15
- SPEC_ROOT = Pathname(__dir__)
16
-
17
- Dir[SPEC_ROOT.join('shared/**/*.rb')].each(&method(:require))
18
- Dir[SPEC_ROOT.join('support/**/*.rb')].each(&method(:require))
19
-
20
- RSpec.configure do |config|
21
- config.disable_monkey_patching!
22
- end
File without changes