Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging Production Service Oriented Systems

Debugging Production Service Oriented Systems

Presented at Cascadia Ruby Conference in Seattle.

Andy Delcambre

August 03, 2012
Tweet

More Decks by Andy Delcambre

Other Decks in Programming

Transcript

  1. class RequestId::Middleware def initialize(app) @app = app end def call(e)

    Thread.current["req_id"] = e["HTTP_X_REQ_ID"] || UUID.generate @app.call(e).tap do |stat, head, body| headers["X-Req-Id"] = Thread.current["req_id"] end end end
  2. class RequestId::Middleware def initialize(app) @app = app end def call(e)

    Thread.current["req_id"] = e["HTTP_X_REQ_ID"] || UUID.generate @app.call(e).tap do |stat, head, body| headers["X-Req-Id"] = Thread.current["req_id"] end end end
  3. class RequestId::Middleware def initialize(app) @app = app end def call(e)

    Thread.current["req_id"] = e["HTTP_X_REQ_ID"] || UUID.generate @app.call(e).tap do |stat, head, body| headers["X-Req-Id"] = Thread.current["req_id"] end end end
  4. class RequestId::Middleware def initialize(app) @app = app end def call(e)

    Thread.current["req_id"] = e["HTTP_X_REQ_ID"] || UUID.generate @app.call(e).tap do |stat, head, body| headers["X-Req-Id"] = Thread.current["req_id"] end end end
  5. class RequestIdLogger def call(e) begin start = Time.now @app.call(e) ensure

    req_id = Thread.current["req_id"] client.post( "/requests", {}, env.merge(:req_id => req_id :start => start, :end => Time.now).to_json) end end end
  6. class RequestIdLogger def call(e) begin start = Time.now @app.call(e) ensure

    req_id = Thread.current["req_id"] client.post( "/requests", {}, env.merge(:req_id => req_id :start => start, :end => Time.now).to_json) end end end
  7. class RequestIdLogger def call(e) begin start = Time.now @app.call(e) ensure

    req_id = Thread.current["req_id"] client.post( "/requests", {}, env.merge(:req_id => req_id :start => start, :end => Time.now).to_json) end end end
  8. class RequestIdLogger def call(e) begin start = Time.now @app.call(e) ensure

    req_id = Thread.current["req_id"] client.post( "/requests", {}, env.merge(:req_id => req_id :start => start, :end => Time.now).to_json) end end end
  9. class RequestIdLogger def call(e) begin start = Time.now @app.call(e) ensure

    req_id = Thread.current["req_id"] client.post( "/requests", {}, env.merge(:req_id => req_id :start => start, :end => Time.now).to_json) end end end
  10. class ExceptionLogger def call(env) begin @app.call(env) rescue => e req_id

    = Thread.current["req_id"] client.post("/errors", {}, {:request => env.to_hash, :exception => e.to_hash, :ruby_env => ENV.to_hash, :request_id => req_id }.to_json) raise end end end
  11. class ExceptionLogger def call(env) begin @app.call(env) rescue => e req_id

    = Thread.current["req_id"] client.post("/errors", {}, {:request => env.to_hash, :exception => e.to_hash, :ruby_env => ENV.to_hash, :request_id => req_id }.to_json) raise end end end
  12. module RequestID def around_perform_req_id(req_id, *args) begin start = Time.now yield

    ensure client.post("/requests", {}, {:req_id => req_id :start => start, :end => Time.now, :args => args, :type => "job"}.to_json) end end end
  13. module RequestID def around_perform_req_id(req_id, *args) begin start = Time.now yield

    ensure client.post("/requests", {}, {:req_id => req_id :start => start, :end => Time.now, :args => args, :type => "job"}.to_json) end end end
  14. module RequestID def around_perform_req_id(req_id, *args) begin start = Time.now yield

    ensure client.post("/requests", {}, {:req_id => req_id :start => start, :end => Time.now, :args => args, :type => "job"}.to_json) end end end
  15. module RequestID def around_perform_req_id(req_id, *args) begin start = Time.now yield

    ensure client.post("/requests", {}, {:req_id => req_id :start => start, :end => Time.now, :args => args, :type => "job"}.to_json) end end end
  16. module RequestID def around_perform_track(req_id, *args) begin yield rescue => e

    req_id = Thread.current["req_id"] client.post("/errors", {}, {:args => args, :exception => e.to_hash, :ruby_env => ENV.to_hash, :request_id => req_id, :type => "job" }.to_json) end end end
  17. module RequestID def around_perform_track(req_id, *args) begin yield rescue => e

    req_id = Thread.current["req_id"] client.post("/errors", {}, {:args => args, :exception => e.to_hash, :ruby_env => ENV.to_hash, :request_id => req_id, :type => "job" }.to_json) end end end
  18. module RequestID def around_perform_track(req_id, *args) begin yield rescue => e

    req_id = Thread.current["req_id"] client.post("/errors", {}, {:args => args, :exception => e.to_hash, :ruby_env => ENV.to_hash, :request_id => req_id, :type => "job" }.to_json) end end end
  19. class ClientMiddleware def initialize(app) @app = app end def call(env)

    req_id = Thread.current["req_id"] @app.call( env.merge( "HTTP_X_REQ_ID" => req_id)) end end Rack::Client::Simple.use ClientMiddleware
  20. class ClientMiddleware def initialize(app) @app = app end def call(env)

    req_id = Thread.current["req_id"] @app.call( env.merge( "HTTP_X_REQ_ID" => req_id)) end end Rack::Client::Simple.use ClientMiddleware
  21. class ClientMiddleware def initialize(app) @app = app end def call(env)

    req_id = Thread.current["req_id"] @app.call( env.merge( "HTTP_X_REQ_ID" => req_id)) end end Rack::Client::Simple.use ClientMiddleware
  22. class ClientMiddleware def initialize(app) @app = app end def call(env)

    req_id = Thread.current["req_id"] @app.call( env.merge( "HTTP_X_REQ_ID" => req_id)) end end Rack::Client::Simple.use ClientMiddleware
  23. class ClientMiddleware def initialize(app) @app = app end def call(env)

    req_id = Thread.current["req_id"] @app.call( env.merge( "HTTP_X_REQ_ID" => req_id)) end end Rack::Client::Simple.use ClientMiddleware
  24. class RequestId::Middleware def initialize(app) @app = app end def call(e)

    Thread.current["req_id"] = e["HTTP_X_REQ_ID"] || UUID.generate @app.call(e).tap do |stat, head, body| headers["X-Req-Id"] = Thread.current["req_id"] end end end
  25. $ curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{ "user": "kimchy", "post_date": "2009-11-15T14:12:12",

    "message": "You know, for Search" }' $ curl -XGET http://localhost:9200/twitter/tweet/_search? q=user:kimchy
  26. $ curl -XGET http://localhost:9200/twitter/_search -d '{ "query" : { "range"

    : { "post_date" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:30:00" } } } }'
  27. WIP