Class: MissionControl::Servers::RequestTallyMiddleware
- Inherits:
-
Object
- Object
- MissionControl::Servers::RequestTallyMiddleware
- Defined in:
- lib/mission_control/servers/request_tally_middleware.rb
Constant Summary collapse
- @@tally =
Hash.new(0)
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RequestTallyMiddleware
constructor
A new instance of RequestTallyMiddleware.
Constructor Details
#initialize(app) ⇒ RequestTallyMiddleware
Returns a new instance of RequestTallyMiddleware.
6 7 8 9 10 11 12 13 |
# File 'lib/mission_control/servers/request_tally_middleware.rb', line 6 def initialize(app) @app = app @hostname = if ENV["KAMAL_VERSION"].present? Socket.gethostname.to_s.split("-").first else ENV.fetch('HOSTNAME', Socket.gethostname) end end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mission_control/servers/request_tally_middleware.rb', line 15 def call(env) req = Rack::Request.new(env) if ingress_request?(req) req.update_param('tally', @@tally.clone.merge('hostname' => @hostname)) @@tally.clear end status, headers, response = @app.call(env) if !ingress_request?(req) category = categorize_status(status) update_tally(category) end [status, headers, response] end |