ops_routes 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -1
- data/VERSION +1 -1
- data/app/controllers/ops_controller.rb +4 -0
- data/config/routes.rb +1 -0
- data/lib/ops_routes/middleware.rb +7 -2
- data/lib/ops_routes.rb +33 -0
- data/lib/views/config.html.haml +21 -0
- data/spec/ops_routes/middleware_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ This library provides a Rails plugin and a piece of Rack middleware for monitori
|
|
8
8
|
|
9
9
|
To include it in a Rails application, install the plugin:
|
10
10
|
|
11
|
-
script/plugin install
|
11
|
+
script/plugin install git://github.com/primedia/ops_routes.git
|
12
12
|
|
13
13
|
Then add the following minimum configuration to <tt>config/initializers/ops_routes.rb</tt>:
|
14
14
|
|
@@ -47,6 +47,21 @@ Additionally, you can specify custom heartbeat monitoring pages as follows:
|
|
47
47
|
|
48
48
|
The mysql example shown above would be accessed at <tt>ops/heartbeat/mysql</tt>. The heartbeat page will return a 200 'OK' as long as the provided block does not raise an error. If an error is raised or the heartbeat does not exist, a 500 will be returned instead.
|
49
49
|
|
50
|
+
== Configuration Page
|
51
|
+
|
52
|
+
The third provided page is <tt>/ops/configuration</tt> which is designed to let you check that the environment-specific configuration variables used by your app are set to the correct values. This is especially useful if production options are set using file replacement or modification during the deploy process.
|
53
|
+
|
54
|
+
If you add any sensitive information to this page, make sure to hide it from outside access!
|
55
|
+
|
56
|
+
To add a configuration section, specify it as follows:
|
57
|
+
|
58
|
+
ops.add_configuration section :action_controller do
|
59
|
+
{ :consider_all_requests_local => Rails.configuration.consider_all_requests_local,
|
60
|
+
:perform_caching => Rails.configuration.perform_caching }
|
61
|
+
end
|
62
|
+
|
63
|
+
This example will add a section to the <tt>/ops/configuration</tt> page called `action_controiller'. Each time the configuration page is requested, the block provided for the section will be called. This means the current values for your configuration options will be shown, even if they change while the app is running. The block is expected to return a hash of key/value pairs to be displayed.
|
64
|
+
|
50
65
|
== Note on Patches/Pull Requests
|
51
66
|
|
52
67
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/config/routes.rb
CHANGED
@@ -2,4 +2,5 @@ ActionController::Routing::Routes.draw do |map|
|
|
2
2
|
map.connect '/ops/version', :controller => 'ops', :action => 'version'
|
3
3
|
map.connect '/ops/heartbeat', :controller => 'ops', :action => 'heartbeat'
|
4
4
|
map.connect '/ops/heartbeat/:name', :controller => 'ops', :action => 'heartbeat'
|
5
|
+
map.connect '/ops/configuration', :controller => 'ops', :action => 'configuration'
|
5
6
|
end
|
@@ -8,10 +8,10 @@ module OpsRoutes
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
return @app.call(env) unless env['PATH_INFO'] =~ %r{^/ops/(heartbeat
|
11
|
+
return @app.call(env) unless env['PATH_INFO'] =~ %r{^/ops/(heartbeat(?:/(\w+))?|version|configuration)/?$}
|
12
12
|
route, heartbeat_name = $1, $2
|
13
13
|
case route
|
14
|
-
when
|
14
|
+
when /^heartbeat/
|
15
15
|
heartbeat_result = OpsRoutes.check_heartbeat(heartbeat_name)
|
16
16
|
headers = { 'Content-Type' => 'text/plain',
|
17
17
|
'Content-Length' => heartbeat_result[:text].length.to_s }
|
@@ -21,6 +21,11 @@ module OpsRoutes
|
|
21
21
|
headers = { 'Content-Type' => 'text/html',
|
22
22
|
'Content-Length' => version_result.length.to_s }
|
23
23
|
[ 200, headers, [version_result] ]
|
24
|
+
when 'configuration'
|
25
|
+
configuration_result = OpsRoutes.check_configuration
|
26
|
+
headers = { 'Content-Type' => 'text/html',
|
27
|
+
'Content-Length' => configuration_result.length.to_s }
|
28
|
+
[ 200, headers, [configuration_result] ]
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
data/lib/ops_routes.rb
CHANGED
@@ -130,6 +130,39 @@ module OpsRoutes
|
|
130
130
|
"https://github.com/primedia/#{app_name}/commit/#{commit}" unless commit =~ /^Unknown/
|
131
131
|
end
|
132
132
|
|
133
|
+
# Configuration page
|
134
|
+
|
135
|
+
def add_configuration_section(name, &block)
|
136
|
+
@configuration ||= {}
|
137
|
+
@configuration[name] = block
|
138
|
+
end
|
139
|
+
|
140
|
+
def current_config
|
141
|
+
@configuration.inject({}) do |current, (section, block)|
|
142
|
+
current[section] = block.call
|
143
|
+
current
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def check_configuration
|
148
|
+
config_template = File.join(File.dirname(__FILE__), 'views', 'config.html.haml')
|
149
|
+
Haml::Engine.new(File.read(config_template)).render(self)
|
150
|
+
end
|
151
|
+
|
152
|
+
def print_detail( object, indent = 0 )
|
153
|
+
output = ""
|
154
|
+
if object.kind_of? Hash
|
155
|
+
output << "{\n"
|
156
|
+
output << object.collect { |key, value|
|
157
|
+
" " * indent + " #{print_detail key} => #{print_detail value, indent+1}"
|
158
|
+
}.join(",\n") << "\n"
|
159
|
+
output << " " * indent + "}"
|
160
|
+
else
|
161
|
+
output << object.inspect
|
162
|
+
end
|
163
|
+
output
|
164
|
+
end
|
165
|
+
|
133
166
|
end
|
134
167
|
|
135
168
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title= app_name
|
5
|
+
:css
|
6
|
+
td {padding: 0 5px; vertical-align: top;}
|
7
|
+
pre {margin: 0}
|
8
|
+
tr.even {background: #dddddd;}
|
9
|
+
%body
|
10
|
+
-# %pre&= @configuration.inspect
|
11
|
+
-# %pre&= current_config.inspect
|
12
|
+
- current_config.each do |section, settings|
|
13
|
+
%h2= section
|
14
|
+
%table
|
15
|
+
- settings.each_with_index do |(setting, value), i|
|
16
|
+
%tr{ :class => i%2==0 ? 'even' : nil }
|
17
|
+
%td= setting
|
18
|
+
%td
|
19
|
+
%pre&= print_detail(value)
|
20
|
+
|
21
|
+
|
@@ -69,6 +69,20 @@ describe OpsRoutes::Middleware do
|
|
69
69
|
|
70
70
|
end
|
71
71
|
|
72
|
+
context "configuration" do
|
73
|
+
it 'should call check_configuration' do
|
74
|
+
OpsRoutes.should_receive(:check_configuration).and_return('The configuration page')
|
75
|
+
get '/ops/configuration'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should call the configuration block' do
|
79
|
+
config_block = lambda{}
|
80
|
+
OpsRoutes.add_configuration_section(:test, &config_block)
|
81
|
+
config_block.should_receive(:call).and_return( :key => 'value' )
|
82
|
+
get '/ops/configuration'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
72
86
|
end
|
73
87
|
|
74
88
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app', 'controllers'))
|
4
|
+
require 'rubygems'
|
4
5
|
require 'ops_routes'
|
5
6
|
require 'ops_routes/middleware'
|
6
7
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Primedia Team
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-02 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/ops_routes.rb
|
105
105
|
- lib/ops_routes/middleware.rb
|
106
106
|
- lib/tasks/ops_routes.rake
|
107
|
+
- lib/views/config.html.haml
|
107
108
|
- lib/views/version.html.haml
|
108
109
|
- spec/app/controllers/ops_controller_spec.rb
|
109
110
|
- spec/ops_routes/middleware_spec.rb
|