harness-rack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +9 -0
- data/harness-rack.gemspec +25 -0
- data/lib/harness-rack.rb +1 -0
- data/lib/harness/rack.rb +27 -0
- data/lib/harness/rack/version.rb +5 -0
- data/test/rack_test.rb +29 -0
- data/test/test_helper.rb +63 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 600cfa39ccca5590e6b0ecf0fc3481e371cf5a7e
|
4
|
+
data.tar.gz: 23ca354510f2f6045cf557ad5520a1bd83370a05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70cce98d0df93eaf7dd991d49c0553648900c5db66e9de8f11523223e08c7911d2b0c79e796d1bc124128900aca00215c6cbd6796ab587c0ff4ade1651c5e856
|
7
|
+
data.tar.gz: aba1001b8b188eeed1821a5ba5d8a18bfa27590bca301bc269e5a724a6b5dc73a3dbf60088f59dd401977f0a147ec1c68571439c12dccdc8577a392278f9e90d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ahawkins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Harness::Rack
|
2
|
+
|
3
|
+
Log every request's performance with Harness
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'harness-rack'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install harness-rack
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'harness/rack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "harness-rack"
|
8
|
+
spec.version = Harness::Rack::VERSION
|
9
|
+
spec.authors = ["ahawkins"]
|
10
|
+
spec.email = ["adam@hawkins.io"]
|
11
|
+
spec.description = %q{Instrument all rack requests with Harness}
|
12
|
+
spec.summary = %q{}
|
13
|
+
spec.homepage = "https://github.com/ahawkins/harness-rack"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "harness"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/harness-rack.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'harness/rack'
|
data/lib/harness/rack.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "harness/rack/version"
|
2
|
+
|
3
|
+
require 'harness'
|
4
|
+
|
5
|
+
module Harness
|
6
|
+
class RackInstrumenter
|
7
|
+
include Instrumentation
|
8
|
+
|
9
|
+
def initialize(app, namespace = nil)
|
10
|
+
@app, @namespace = app, namespace
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
status, headers, body = time stat_name('rack.request', 'all') do
|
15
|
+
@app.call env
|
16
|
+
end
|
17
|
+
|
18
|
+
increment "#{stat_name("rack.request")}.#{status}"
|
19
|
+
|
20
|
+
[status, headers, body]
|
21
|
+
end
|
22
|
+
|
23
|
+
def stat_name(name, type = nil)
|
24
|
+
[name, @namespace, type].compact.join('.')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/rack_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class RackInstrumenterTest < MiniTest::Unit::TestCase
|
4
|
+
def app
|
5
|
+
@app ||= lambda { |env| [200, { }, [ ]] }
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_reports_total_run_time
|
9
|
+
instrumentor = Harness::RackInstrumenter.new app
|
10
|
+
instrumentor.call({})
|
11
|
+
|
12
|
+
assert_timer 'rack.request.all'
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_counts_requests_by_status_code
|
16
|
+
instrumentor = Harness::RackInstrumenter.new app
|
17
|
+
instrumentor.call({})
|
18
|
+
|
19
|
+
assert_increment 'rack.request.200'
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_accepts_a_namespace
|
23
|
+
instrumentor = Harness::RackInstrumenter.new app, 'foo'
|
24
|
+
instrumentor.call({})
|
25
|
+
|
26
|
+
assert_increment 'rack.request.foo.200'
|
27
|
+
assert_timer 'rack.request.foo.all'
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'harness-rack'
|
3
|
+
require 'minitest/unit'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class MiniTest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
Harness.config.collector = Harness::FakeCollector.new
|
9
|
+
Harness.config.queue = Harness::SyncQueue.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_timer(name)
|
13
|
+
refute_empty timers
|
14
|
+
timer = timers.find { |t| t.name == name }
|
15
|
+
assert timer, "Timer #{name} not logged!"
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_increment(name)
|
19
|
+
refute_empty increments
|
20
|
+
increment = increments.find { |i| i.name == name }
|
21
|
+
assert increment, "Increment #{name} not logged!"
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_decrement(name)
|
25
|
+
refute_empty decrements
|
26
|
+
decrement = decrements.find { |i| i.name == name }
|
27
|
+
assert decrement, "decrement #{name} not logged!"
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_gauge(name)
|
31
|
+
refute_empty gauges
|
32
|
+
gauge = gauges.find { |g| g.name == name }
|
33
|
+
assert gauge, "gauge #{name} not logged!"
|
34
|
+
end
|
35
|
+
|
36
|
+
def instrument(name, data = {}, &block)
|
37
|
+
ActiveSupport::Notifications.instrument name, data, &block
|
38
|
+
end
|
39
|
+
|
40
|
+
def collector
|
41
|
+
Harness.config.collector
|
42
|
+
end
|
43
|
+
|
44
|
+
def timers
|
45
|
+
collector.timers
|
46
|
+
end
|
47
|
+
|
48
|
+
def increments
|
49
|
+
collector.increments
|
50
|
+
end
|
51
|
+
|
52
|
+
def decrements
|
53
|
+
collector.decrements
|
54
|
+
end
|
55
|
+
|
56
|
+
def counters
|
57
|
+
collector.counters
|
58
|
+
end
|
59
|
+
|
60
|
+
def gauges
|
61
|
+
collector.gauges
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: harness-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ahawkins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: harness
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Instrument all rack requests with Harness
|
56
|
+
email:
|
57
|
+
- adam@hawkins.io
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- harness-rack.gemspec
|
68
|
+
- lib/harness-rack.rb
|
69
|
+
- lib/harness/rack.rb
|
70
|
+
- lib/harness/rack/version.rb
|
71
|
+
- test/rack_test.rb
|
72
|
+
- test/test_helper.rb
|
73
|
+
homepage: https://github.com/ahawkins/harness-rack
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: ''
|
97
|
+
test_files:
|
98
|
+
- test/rack_test.rb
|
99
|
+
- test/test_helper.rb
|