seomoz-e20_ops_middleware 2.1.3
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.
- data/.gitignore +3 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +29 -0
- data/History.txt +5 -0
- data/README.md +144 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/ci.rb +7 -0
- data/e20_ops_middleware.gemspec +68 -0
- data/lib/e20/ops/hostname.rb +11 -0
- data/lib/e20/ops/middleware.rb +12 -0
- data/lib/e20/ops/middleware/hostname_middleware.rb +24 -0
- data/lib/e20/ops/middleware/revision_middleware.rb +29 -0
- data/lib/e20/ops/middleware/transaction_id_middleware.rb +34 -0
- data/lib/e20/ops/revision.rb +33 -0
- data/spec/ops/hostname_spec.rb +9 -0
- data/spec/ops/middleware/hostname_middleware_spec.rb +27 -0
- data/spec/ops/middleware/revision_middleware_spec.rb +37 -0
- data/spec/ops/middleware/transaction_id_middleware_spec.rb +37 -0
- data/spec/ops/revision_spec.rb +28 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +2 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
gemcutter (0.6.1)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.4.0)
|
7
|
+
gemcutter (>= 0.1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rubyforge (>= 2.0.0)
|
10
|
+
json_pure (1.4.3)
|
11
|
+
macaddr (1.6.1)
|
12
|
+
systemu (~> 2.5.0)
|
13
|
+
rake (0.8.7)
|
14
|
+
rspec (1.3.0)
|
15
|
+
rubyforge (2.0.4)
|
16
|
+
json_pure (>= 1.1.7)
|
17
|
+
systemu (2.5.2)
|
18
|
+
uuid (2.3.5)
|
19
|
+
macaddr (~> 1.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
jeweler (~> 1.4.0)
|
26
|
+
json_pure (= 1.4.3)
|
27
|
+
rake (~> 0.8.7)
|
28
|
+
rspec (~> 1.3.0)
|
29
|
+
uuid
|
data/History.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
Efficiency 2.0 Ops Middleware
|
2
|
+
=============================
|
3
|
+
|
4
|
+
A collection of useful middleware for exposing information about deployed Rack
|
5
|
+
applications. Efficiency 2.0 uses this to track distributed transactions
|
6
|
+
across its Ruby-based service oriented architecture.
|
7
|
+
|
8
|
+
Features
|
9
|
+
--------
|
10
|
+
|
11
|
+
* Adds a `X-Served-By` header with the hostname of the server that processed
|
12
|
+
the request.
|
13
|
+
* Adds a `X-Transaction` header with a unique ID for the web request.
|
14
|
+
* Adds a `X-Revision` header with the running Git revision.
|
15
|
+
* Adds an endpoint of `/system/revision` for easily checking the running
|
16
|
+
revision. This can be leveraged in a post-deployment sanity check to ensure
|
17
|
+
the application servers restarted properly.
|
18
|
+
|
19
|
+
Install
|
20
|
+
-------
|
21
|
+
|
22
|
+
### Rails ###
|
23
|
+
|
24
|
+
Add to your `Gemfile`:
|
25
|
+
|
26
|
+
gem "e20_ops_middleware", :require => "e20/ops/middleware"
|
27
|
+
|
28
|
+
Install the gem:
|
29
|
+
|
30
|
+
$ bundle install
|
31
|
+
|
32
|
+
Create a `config/initializers/ops_middleware.rb` with the following:
|
33
|
+
|
34
|
+
Rails.application.middleware.with_options :logger => Rails.logger do |m|
|
35
|
+
m.use E20::Ops::Middleware::RevisionMiddleware
|
36
|
+
m.use E20::Ops::Middleware::HostnameMiddleware
|
37
|
+
m.use E20::Ops::Middleware::TransactionIdMiddleware
|
38
|
+
end
|
39
|
+
|
40
|
+
### Rack ###
|
41
|
+
|
42
|
+
In `config.ru`, add:
|
43
|
+
|
44
|
+
use E20::Ops::Middleware::RevisionMiddleware
|
45
|
+
use E20::Ops::Middleware::HostnameMiddleware
|
46
|
+
use E20::Ops::Middleware::TransactionIdMiddleware
|
47
|
+
|
48
|
+
Usage
|
49
|
+
-----
|
50
|
+
|
51
|
+
The information exposed by the middleware can be viewed manually with `curl`
|
52
|
+
and will also be logged to the provided logger (or STDOUT). Additionally,
|
53
|
+
we've found it useful to log this information when receiving responses from
|
54
|
+
REST web services.
|
55
|
+
|
56
|
+
### Revision Middleware ###
|
57
|
+
|
58
|
+
Revisions can be queried directly by using the `/system/revision` endpoint:
|
59
|
+
|
60
|
+
$ curl http://instance/system/revision
|
61
|
+
fe09f24b4a927b6eab5db66b6a89fe960e2ff03b
|
62
|
+
|
63
|
+
The current revision will be passed as an HTTP header for other requests:
|
64
|
+
|
65
|
+
$ curl -I http://instance/
|
66
|
+
HTTP/1.1 200 OK
|
67
|
+
Content-Type: text/html; charset=utf-8
|
68
|
+
Content-Length: 3304
|
69
|
+
X-Revision: fe09f24b4a927b6eab5db66b6a89fe960e2ff03b
|
70
|
+
|
71
|
+
The current revision will also be logged upon application start:
|
72
|
+
|
73
|
+
$ grep RevisionMiddleware log/production.log
|
74
|
+
[E20::Ops::Middleware::RevisionMiddleware] Running: fe09f24b4a927b6eab5db66b6a89fe960e2ff03b
|
75
|
+
|
76
|
+
### Hostname Middleware ###
|
77
|
+
|
78
|
+
The hostname of the system that processed the request will be passed as an
|
79
|
+
HTTP header:
|
80
|
+
|
81
|
+
$ curl -I http://instance/
|
82
|
+
HTTP/1.1 200 OK
|
83
|
+
Content-Type: text/html; charset=utf-8
|
84
|
+
Content-Length: 3304
|
85
|
+
X-Served-By: fulton
|
86
|
+
|
87
|
+
The hostname will also be logged upon application start:
|
88
|
+
|
89
|
+
$ grep HostnameMiddleware log/production.log
|
90
|
+
[E20::Ops::Middleware::HostnameMiddleware] Running on: fulton
|
91
|
+
|
92
|
+
### Transaction ID Middleware ###
|
93
|
+
|
94
|
+
A transaction ID will be logged for each incoming request:
|
95
|
+
|
96
|
+
$ grep TransactionIdMiddleware log/production.log
|
97
|
+
[E20::Ops::Middleware::TransactionIdMiddleware] Transaction ID: 111d3180-91f4-012d-ce1a-549a20d01d99
|
98
|
+
|
99
|
+
The transaction ID will also be passed as an HTTP header:
|
100
|
+
|
101
|
+
$ curl -I http://instance/
|
102
|
+
HTTP/1.1 200 OK
|
103
|
+
Content-Type: text/html; charset=utf-8
|
104
|
+
Content-Length: 3304
|
105
|
+
X-Transaction: 111d3180-91f4-012d-ce1a-549a20d01d99
|
106
|
+
|
107
|
+
Thanks
|
108
|
+
------
|
109
|
+
|
110
|
+
Thanks to Efficiency 2.0 ([http://efficiency20.com](http://efficiency20.com))
|
111
|
+
for sponsoring development of this gem.
|
112
|
+
|
113
|
+
Development
|
114
|
+
-----------
|
115
|
+
|
116
|
+
To run the tests:
|
117
|
+
|
118
|
+
$ bundle install
|
119
|
+
$ rake
|
120
|
+
|
121
|
+
License
|
122
|
+
-------
|
123
|
+
|
124
|
+
(The MIT License)
|
125
|
+
|
126
|
+
Copyright © 2010 Efficiency 2.0, LLC
|
127
|
+
|
128
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
129
|
+
of this software and associated documentation files (the ‘Software’), to deal
|
130
|
+
in the Software without restriction, including without limitation the rights
|
131
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
132
|
+
copies of the Software, and to permit persons to whom the Software is
|
133
|
+
furnished to do so, subject to the following conditions:
|
134
|
+
|
135
|
+
The above copyright notice and this permission notice shall be included in all
|
136
|
+
copies or substantial portions of the Software.
|
137
|
+
|
138
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
139
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
140
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
141
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
142
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
143
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
144
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require 'jeweler'
|
6
|
+
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "seomoz-e20_ops_middleware"
|
9
|
+
gem.summary = "Collection of useful middleware for exposing information about deployed Rack applications"
|
10
|
+
gem.email = "tech@efficiency20.com"
|
11
|
+
gem.homepage = "http://github.com/efficiency20/ops_middleware"
|
12
|
+
gem.description = "Adds middleware for debugging purposes"
|
13
|
+
gem.authors = ["Efficiency 2.0"]
|
14
|
+
gem.add_development_dependency "rspec", "~> 1.3.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
require "spec/rake/spectask"
|
18
|
+
|
19
|
+
desc "Run all specs"
|
20
|
+
Spec::Rake::SpecTask.new("spec") do |t|
|
21
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.3
|
data/ci.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{e20_ops_middleware}
|
8
|
+
s.version = "2.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Efficiency 2.0}]
|
12
|
+
s.date = %q{2012-09-19}
|
13
|
+
s.description = %q{Adds middleware for debugging purposes}
|
14
|
+
s.email = %q{tech@efficiency20.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"History.txt",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"ci.rb",
|
27
|
+
"e20_ops_middleware.gemspec",
|
28
|
+
"lib/e20/ops/hostname.rb",
|
29
|
+
"lib/e20/ops/middleware.rb",
|
30
|
+
"lib/e20/ops/middleware/hostname_middleware.rb",
|
31
|
+
"lib/e20/ops/middleware/revision_middleware.rb",
|
32
|
+
"lib/e20/ops/middleware/transaction_id_middleware.rb",
|
33
|
+
"lib/e20/ops/revision.rb",
|
34
|
+
"spec/ops/hostname_spec.rb",
|
35
|
+
"spec/ops/middleware/hostname_middleware_spec.rb",
|
36
|
+
"spec/ops/middleware/revision_middleware_spec.rb",
|
37
|
+
"spec/ops/middleware/transaction_id_middleware_spec.rb",
|
38
|
+
"spec/ops/revision_spec.rb",
|
39
|
+
"spec/spec.opts",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/efficiency20/ops_middleware}
|
43
|
+
s.rdoc_options = [%q{--charset=UTF-8}]
|
44
|
+
s.require_paths = [%q{lib}]
|
45
|
+
s.rubygems_version = %q{1.8.6}
|
46
|
+
s.summary = %q{Collection of useful middleware for exposing information about deployed Rack applications}
|
47
|
+
s.test_files = [
|
48
|
+
"spec/ops/hostname_spec.rb",
|
49
|
+
"spec/ops/middleware/hostname_middleware_spec.rb",
|
50
|
+
"spec/ops/middleware/revision_middleware_spec.rb",
|
51
|
+
"spec/ops/middleware/transaction_id_middleware_spec.rb",
|
52
|
+
"spec/ops/revision_spec.rb",
|
53
|
+
"spec/spec_helper.rb"
|
54
|
+
]
|
55
|
+
|
56
|
+
if s.respond_to? :specification_version then
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module E20
|
2
|
+
module Ops
|
3
|
+
autoload :Revision, "e20/ops/revision"
|
4
|
+
autoload :Hostname, "e20/ops/hostname"
|
5
|
+
|
6
|
+
module Middleware
|
7
|
+
autoload :HostnameMiddleware, "e20/ops/middleware/hostname_middleware"
|
8
|
+
autoload :RevisionMiddleware, "e20/ops/middleware/revision_middleware"
|
9
|
+
autoload :TransactionIdMiddleware, "e20/ops/middleware/transaction_id_middleware"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module E20
|
2
|
+
module Ops
|
3
|
+
module Middleware
|
4
|
+
class HostnameMiddleware
|
5
|
+
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@hostname = options[:hostname] || Hostname.new
|
9
|
+
|
10
|
+
if (logger = options[:logger])
|
11
|
+
logger.info "[#{self.class.name}] Running on: #{@hostname}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
status, headers, body = @app.call(env)
|
17
|
+
headers["X-Served-By"] = @hostname.to_s
|
18
|
+
[status, headers, body]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module E20
|
2
|
+
module Ops
|
3
|
+
module Middleware
|
4
|
+
class RevisionMiddleware
|
5
|
+
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@revision = options[:revision] || Revision.new
|
9
|
+
|
10
|
+
if (logger = options[:logger])
|
11
|
+
logger.info "[#{self.class.name}] Running: #{@revision}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if env["PATH_INFO"] == "/system/revision"
|
17
|
+
body = "#{@revision}\n"
|
18
|
+
[200, { "Content-Type" => "text/plain", "Content-Length" => body.size.to_s }, [body]]
|
19
|
+
else
|
20
|
+
status, headers, body = @app.call(env)
|
21
|
+
headers["X-Revision"] = @revision.to_s
|
22
|
+
[status, headers, body]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
module E20
|
4
|
+
module Ops
|
5
|
+
module Middleware
|
6
|
+
class TransactionIdMiddleware
|
7
|
+
|
8
|
+
def initialize(app, options = {})
|
9
|
+
@app = app
|
10
|
+
@uuid_generator = options[:uuid_generator] || find_uuid_generator
|
11
|
+
@logger = options[:logger] || Logger.new(STDOUT)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
uuid = @uuid_generator.call.to_s
|
16
|
+
@logger.info "[#{self.class.name}] Transaction ID: #{uuid}"
|
17
|
+
|
18
|
+
status, headers, body = @app.call(env)
|
19
|
+
headers["X-Transaction"] = uuid
|
20
|
+
[status, headers, body]
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_uuid_generator
|
24
|
+
require 'securerandom'
|
25
|
+
return SecureRandom.method(:uuid) if SecureRandom.respond_to?(:uuid)
|
26
|
+
|
27
|
+
require 'uuid'
|
28
|
+
UUID.method(:generate)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module E20
|
2
|
+
module Ops
|
3
|
+
class Revision
|
4
|
+
|
5
|
+
def initialize(root = Pathname.new(Dir.pwd))
|
6
|
+
@root = root
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
@revision ||= begin
|
11
|
+
if revision_file.exist?
|
12
|
+
revision_file.read.strip
|
13
|
+
elsif revision_from_git == ''
|
14
|
+
"unknown"
|
15
|
+
else
|
16
|
+
revision_from_git
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def revision_from_git
|
24
|
+
@revision_from_git ||= `git rev-parse HEAD`.strip
|
25
|
+
end
|
26
|
+
|
27
|
+
def revision_file
|
28
|
+
@root.join("REVISION")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe E20::Ops::Middleware::HostnameMiddleware do
|
4
|
+
let(:app) { Proc.new { |env| [200, {}, "OK!"] } }
|
5
|
+
|
6
|
+
it "is initialized with an app" do
|
7
|
+
E20::Ops::Middleware::HostnameMiddleware.new(app)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "delegates to the app" do
|
11
|
+
middleware = E20::Ops::Middleware::HostnameMiddleware.new(app)
|
12
|
+
status, headers, body = middleware.call({})
|
13
|
+
body.should == "OK!"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "logs the hostname when initialized" do
|
17
|
+
log_io = StringIO.new
|
18
|
+
E20::Ops::Middleware::HostnameMiddleware.new(app, :logger => Logger.new(log_io))
|
19
|
+
log_io.string.should include("[E20::Ops::Middleware::HostnameMiddleware] Running on: ")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sets an X-Served-By header" do
|
23
|
+
middleware = E20::Ops::Middleware::HostnameMiddleware.new(app, :hostname => "Computer.local")
|
24
|
+
status, headers, body = middleware.call({})
|
25
|
+
headers["X-Served-By"].should == "Computer.local"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe E20::Ops::Middleware::RevisionMiddleware do
|
4
|
+
let(:app) { Proc.new { |env| [200, {}, "OK!"] } }
|
5
|
+
|
6
|
+
it "is initialized with an app" do
|
7
|
+
E20::Ops::Middleware::RevisionMiddleware.new(app)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "/system/revision" do
|
11
|
+
it "returns the current running revision" do
|
12
|
+
middleware = E20::Ops::Middleware::RevisionMiddleware.new(app, :revision => "rev")
|
13
|
+
status, headers, body = middleware.call({"PATH_INFO" => "/system/revision"})
|
14
|
+
body.should == ["rev\n"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "any other endpoint" do
|
19
|
+
it "delegates to the app" do
|
20
|
+
middleware = E20::Ops::Middleware::RevisionMiddleware.new(app)
|
21
|
+
status, headers, body = middleware.call({})
|
22
|
+
body.should == "OK!"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "logs the running revision when initialized" do
|
26
|
+
log_io = StringIO.new
|
27
|
+
E20::Ops::Middleware::RevisionMiddleware.new(app, :revision => "rev", :logger => Logger.new(log_io))
|
28
|
+
log_io.string.should include("[E20::Ops::Middleware::RevisionMiddleware] Running: rev")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets an X-Revision header" do
|
32
|
+
middleware = E20::Ops::Middleware::RevisionMiddleware.new(app, :revision => "the_revision", :logger => nil)
|
33
|
+
status, headers, body = middleware.call({})
|
34
|
+
headers["X-Revision"].should == "the_revision"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe E20::Ops::Middleware::TransactionIdMiddleware do
|
4
|
+
let(:app) { Proc.new { |env| [200, {}, "OK!"] } }
|
5
|
+
let(:uuid) { stub(:call => "abc123") }
|
6
|
+
let(:logger) { Logger.new(StringIO.new) }
|
7
|
+
|
8
|
+
it "is initialized with an app" do
|
9
|
+
E20::Ops::Middleware::TransactionIdMiddleware.new(app)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "delegates to the app" do
|
13
|
+
middleware = E20::Ops::Middleware::TransactionIdMiddleware.new(app, :logger => logger)
|
14
|
+
status, headers, body = middleware.call({})
|
15
|
+
body.should == "OK!"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "defaults to a 36 character transaction id with dashes" do
|
19
|
+
middleware = E20::Ops::Middleware::TransactionIdMiddleware.new(app, :logger => logger)
|
20
|
+
status, headers, body = middleware.call({})
|
21
|
+
headers["X-Transaction"].size.should == 36
|
22
|
+
headers["X-Transaction"].should include('-')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets an X-Transaction header" do
|
26
|
+
middleware = E20::Ops::Middleware::TransactionIdMiddleware.new(app, :uuid_generator => uuid, :logger => logger)
|
27
|
+
status, headers, body = middleware.call({})
|
28
|
+
headers["X-Transaction"].should == "abc123"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "logs a line for each request" do
|
32
|
+
log_io = StringIO.new
|
33
|
+
middleware = E20::Ops::Middleware::TransactionIdMiddleware.new(app, :uuid_generator => uuid, :logger => Logger.new(log_io))
|
34
|
+
middleware.call({})
|
35
|
+
log_io.string.should include("[E20::Ops::Middleware::TransactionIdMiddleware] Transaction ID: abc123")
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "tmpdir"
|
3
|
+
|
4
|
+
describe E20::Ops::Revision do
|
5
|
+
context "when a REVISION file is present" do
|
6
|
+
it "adds a X-Revision header with the REVISION" do
|
7
|
+
tmp_path = Pathname.new(Dir.tmpdir)
|
8
|
+
tmp_path.join("REVISION").open("w") { |f| f.write "hello\n" }
|
9
|
+
E20::Ops::Revision.new(tmp_path).to_s.should == "hello"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when a REVISION file is not present" do
|
14
|
+
it "adds a X-Revision header with the git rev-parse HEAD" do
|
15
|
+
revision = E20::Ops::Revision.new
|
16
|
+
revision.should_receive(:`).with("git rev-parse HEAD").and_return("abc123")
|
17
|
+
revision.to_s.should == "abc123"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when neither a REVISION file or a git revision are available" do
|
22
|
+
it "adds a X-Revision header of 'unknown'" do
|
23
|
+
revision = E20::Ops::Revision.new
|
24
|
+
revision.stub(:` => "")
|
25
|
+
revision.to_s.should == "unknown"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seomoz-e20_ops_middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Efficiency 2.0
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
description: Adds middleware for debugging purposes
|
31
|
+
email: tech@efficiency20.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README.md
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- History.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- VERSION
|
44
|
+
- ci.rb
|
45
|
+
- e20_ops_middleware.gemspec
|
46
|
+
- lib/e20/ops/hostname.rb
|
47
|
+
- lib/e20/ops/middleware.rb
|
48
|
+
- lib/e20/ops/middleware/hostname_middleware.rb
|
49
|
+
- lib/e20/ops/middleware/revision_middleware.rb
|
50
|
+
- lib/e20/ops/middleware/transaction_id_middleware.rb
|
51
|
+
- lib/e20/ops/revision.rb
|
52
|
+
- spec/ops/hostname_spec.rb
|
53
|
+
- spec/ops/middleware/hostname_middleware_spec.rb
|
54
|
+
- spec/ops/middleware/revision_middleware_spec.rb
|
55
|
+
- spec/ops/middleware/transaction_id_middleware_spec.rb
|
56
|
+
- spec/ops/revision_spec.rb
|
57
|
+
- spec/spec.opts
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: http://github.com/efficiency20/ops_middleware
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
hash: -603876141971769400
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Collection of useful middleware for exposing information about deployed Rack
|
87
|
+
applications
|
88
|
+
test_files:
|
89
|
+
- spec/ops/hostname_spec.rb
|
90
|
+
- spec/ops/middleware/hostname_middleware_spec.rb
|
91
|
+
- spec/ops/middleware/revision_middleware_spec.rb
|
92
|
+
- spec/ops/middleware/transaction_id_middleware_spec.rb
|
93
|
+
- spec/ops/revision_spec.rb
|
94
|
+
- spec/spec_helper.rb
|