rack-doge 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87761889060a812f09c81772a68b8716e3fa3c28
4
+ data.tar.gz: f87eefc8a9bcff2404db9a7cb7434cb23650c4b3
5
+ SHA512:
6
+ metadata.gz: 77532518a884c0c7c6c510ad8313e25c9c9bee1031a02c94e8c243bca7cff4b725d7f4908064a669edecb5e161bec85585d887d1a1e84e8ed502bcf947b4abd3
7
+ data.tar.gz: 21b8e778f94f30b12326e0460a314a95f5bff4c51e0944daac3d6d745e9ac121af374c8c46ab31838b397097d206ccc59091e4754d4e695904cb95e6fbc11501
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,29 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Documentation cache and generated files:
13
+ /.yardoc/
14
+ /_yardoc/
15
+ /doc/
16
+ /rdoc/
17
+
18
+ ## Environment normalisation:
19
+ /.bundle/
20
+ /lib/bundler/man/
21
+
22
+ # for a library or gem, you might want to ignore these files since the code is
23
+ # intended to run in multiple environments; otherwise, check them in:
24
+ Gemfile.lock
25
+ .ruby-version
26
+ .ruby-gemset
27
+
28
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
29
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-doge.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chad Bailey
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,33 @@
1
+ # rack-doge
2
+
3
+ Add this gem to a Rails app to get a log line like this for each request:
4
+
5
+ at=info thread_id=70351652783840 process_id=55394 request_id=013f9cc29c1e4c483435dbc15ab260f4 pre_request=0ms rack_in=202ms app=505ms rack_out=301ms
6
+
7
+ That includes:
8
+
9
+ * `thread_id`: For tracking requests across threads, (e.g. Puma)
10
+ * `process_id`: For tracking requests across workers (e.g. Puma or Unicorn)
11
+ * `request_id`: Correlate with you app (or Heroku router) logs
12
+ * `pre_request`: Measure the time between `HTTP_X_REQUEST_START` and the start of your rack stack (similar to New Relic's 'reuqest queueing' metric)
13
+ * `rack_in`: The time in the rack stack before your app sees the request
14
+ * `app`: The time spent processing the request in your app
15
+ * `rack_out`: The time spent going back out of the rack stack
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'rack-doge'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/doge.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "rack/doge/version"
2
+
3
+ module Rack
4
+ module Doge
5
+ # Your code goes here...
6
+ end
7
+ end
data/doge/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Doge
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,23 @@
1
+ require 'doge/notify'
2
+ module Rack
3
+ module Doge
4
+ class BaseDoge
5
+ include Notify
6
+
7
+ def initialize(app, logger = nil)
8
+ @logger = logger
9
+ @app = app
10
+ @instrument_name = "rack.doge"
11
+ @logger = ::Logger.new($stdout) if @logger.nil?
12
+ # @logger.formatter = L2MetFormatter.new
13
+ end
14
+
15
+ protected
16
+
17
+ def time_ms
18
+ (Time.now.to_f * 1000.0).round
19
+ end
20
+
21
+ end
22
+ end
23
+ end
data/lib/doge/end.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Rack
2
+ module Doge
3
+ class End < BaseDoge
4
+ # This middleware should run as late in the stack as possible.
5
+ def call(env)
6
+ env["RACK_IN_END"] = time_ms
7
+ status, headers, response = @app.call(env)
8
+ env["RACK_OUT_START"] = time_ms
9
+ [status, headers, response]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Rack
2
+ module Doge
3
+ module Notify
4
+ def should_notify?
5
+ if defined?(ActiveSupport::Notifications)
6
+ ActiveSupport::Notifications.notifier.listening?(@instrument_name)
7
+ end
8
+ end
9
+
10
+ def notify(data)
11
+ ActiveSupport::Notifications.instrument(@instrument_name, data)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Rack
2
+ module Doge
3
+ class DogeRailtie < Rails::Railtie
4
+ initializer "doge_railtie.configure_rails_initialization" do |app|
5
+ app.middleware.insert 0, Rack::Doge::Start
6
+ app.middleware.insert 0, Rack::Doge::Reporter
7
+ app.middleware.use Rack::Doge::End
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module Rack
2
+ module Doge
3
+ class Reporter < BaseDoge
4
+ def call(env)
5
+ @metrics = {}
6
+
7
+ status, headers, response = @app.call(env)
8
+
9
+ measure_pre_request_time(env)
10
+ measure(:rack_in, :rack_in_start, :rack_in_end, env)
11
+ measure(:app, :rack_in_end, :rack_out_start, env)
12
+ measure(:rack_out, :rack_out_start, :rack_out_end, env)
13
+
14
+ @metrics = {thread_id: Thread.current.object_id, process_id: Process.pid, request_id: (env["action_dispatch.request_id"] || "")}.merge(@metrics)
15
+ notify(@metrics) if should_notify?
16
+ @logger.info "at=info " + @metrics.map { |k, v| "#{k}=#{v}"}.join(" ")
17
+
18
+ [status, headers, response]
19
+ end
20
+
21
+ private
22
+
23
+ def measure(measurement, start_time, end_time, env)
24
+ starting = env[start_time.to_s.upcase].to_i
25
+ ending = env[end_time.to_s.upcase].to_i
26
+ if starting > 0 && ending > 0
27
+ @metrics[measurement] = (ending - starting).to_s + "ms"
28
+ end
29
+ end
30
+
31
+ def measure_pre_request_time(env)
32
+ if (request_start = (env["HTTP_X_REQUEST_START"] || 0).to_i) > 0
33
+ @metrics[:pre_request] = (env["RACK_IN_START"] - request_start).to_s + "ms"
34
+ else
35
+ @metrics[:pre_request] = "0ms"
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
data/lib/doge/start.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Rack
2
+ module Doge
3
+ class Start < BaseDoge
4
+ # This rack should run as early in the stack as possible.
5
+
6
+ def call(env)
7
+ env["RACK_IN_START"] = time_ms
8
+ status, headers, response = @app.call(env)
9
+ env["RACK_OUT_END"] = time_ms
10
+ [status, headers, response]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Doge
3
+ VERSION="0.0.1"
4
+ end
5
+ end
data/lib/rack-doge.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'doge/base_doge'
2
+ require 'doge/start'
3
+ require 'doge/end'
4
+ require 'doge/reporter'
5
+ require 'doge/railtie' if defined?(Rails)
data/rack-doge.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'doge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-doge"
8
+ spec.version = Rack::Doge::VERSION
9
+ spec.authors = ["Chad Bailey"]
10
+ spec.email = ["chad@heroku.com"]
11
+ spec.description = %q{Analyze timing and process info from your Rack stack.}
12
+ spec.summary = %q{Analyze timing and process info from your Rack stack.}
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-doge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chad Bailey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Analyze timing and process info from your Rack stack.
42
+ email:
43
+ - chad@heroku.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .DS_Store
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - doge.rb
55
+ - doge/version.rb
56
+ - lib/.DS_Store
57
+ - lib/doge/base_doge.rb
58
+ - lib/doge/end.rb
59
+ - lib/doge/notify.rb
60
+ - lib/doge/railtie.rb
61
+ - lib/doge/reporter.rb
62
+ - lib/doge/start.rb
63
+ - lib/doge/version.rb
64
+ - lib/rack-doge.rb
65
+ - rack-doge.gemspec
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.14
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Analyze timing and process info from your Rack stack.
90
+ test_files: []