Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Fix router v2 bug, trace header should not be included when trace key…
Browse files Browse the repository at this point in the history
… is wrong.

Update unit test to cover this case, and modify the parameter to speed up unit test.

Change-Id: I3980ff15169c47165eadf02db1614a44a8b9a159
  • Loading branch information
anferneeg committed Feb 23, 2012
1 parent 0c6bd5f commit de09ba1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ext/nginx/uls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ function generate_stats_request()
return cjson.encode(uls_req_spec)
end

function pre_process_subrequest(ngx)
function pre_process_subrequest(ngx, trace_key)
ngx.var.timestamp = ngx.time()

if string.len(ngx.var.http_host) == 0 then
ngx.exit(ngx.HTTP_BAD_REQUEST)
end

if ngx.req.get_headers()[VCAP_TRACE_HEADER] then
if ngx.req.get_headers()[VCAP_TRACE_HEADER] == trace_key then
ngx.var.trace = "Y"
end
end
Expand Down
19 changes: 17 additions & 2 deletions spec/integration/router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

it 'should get correct statistics' do
num_apps = 10
num_requests = 1000
num_requests = 100
dea = DummyDea.new(@nats_server.uri, '1234')

apps = []
Expand Down Expand Up @@ -241,7 +241,7 @@
dea = DummyDea.new(@nats_server.uri, '1234')
dea.register_app(app, {"component" => "trace", "runtime" => "ruby"})

resp = app.get_trace_header("127.0.0.1", RouterServer.port)
resp = app.get_trace_header("127.0.0.1", RouterServer.port, TRACE_KEY)

resp.headers["X-Vcap-Backend"].should_not be_nil
h, p = resp.headers["X-Vcap-Backend"].split(":")
Expand All @@ -255,5 +255,20 @@
app.stop
end

it 'should not add vcap trace headers when trace key is wrong' do
app = TestApp.new('trace.vcap.me')
dea = DummyDea.new(@nats_server.uri, '1234')
dea.register_app(app, {"component" => "trace", "runtime" => "ruby"})

resp = app.get_trace_header("127.0.0.1", RouterServer.port, "fake_trace_key")

resp.headers["X-Vcap-Backend"].should be_nil
resp.headers["X-Vcap-Router"].should be_nil

dea.unregister_app(app)

app.stop
end


end
6 changes: 4 additions & 2 deletions spec/integration/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

STICKY_RESPONSE = "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: 242\r\nSet-Cookie: _session_id=be009e56c7be0e855d951a3b49e288c98aa36ede; path=/\r\nSet-Cookie: JSESSIONID=be009e56c7be0e855d951a3b49e288c98aa36ede; path=/\r\nConnection: keep-alive\r\nServer: thin 1.2.7 codename No Hup\r\n\r\n<h1>Hello from the Cookie Monster! via: 10.0.1.222:35267</h1><h2>session = be009e56c7be0e855d951a3b49e288c98aa36ede</h2><h4>Cookies set: _session_id, JSESSIONID<h4>Note: Trigger new sticky session cookie name via ?ss=NAME appended to URL</h4>"

TRACE_KEY = "222" # Should be consistent with dev_setup deployment configuration

def simple_http_request(host, path, http_version='1.1')
"GET #{path} HTTP/#{http_version}\r\nUser-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15\r\nHost: #{host}\r\nAccept: */*\r\nContent-Length: 11\r\n\r\nhello world"
end
Expand Down Expand Up @@ -254,8 +256,8 @@ def verify_registered(router_host, router_port)
end
end

def get_trace_header(router_host, router_port)
req = trace_request("222") # Make sure consistent with deployment config
def get_trace_header(router_host, router_port, trace_key)
req = trace_request(trace_key)
# Send out simple request and check request and response
TCPSocket.open(router_host, router_port) do |rs|
rs.send(req, 0)
Expand Down

0 comments on commit de09ba1

Please sign in to comment.