Merge lp:~sasimpson/swift/lp_746068_fix_for_proxy_logging into lp:~hudson-openstack/swift/trunk

Proposed by Scott Simpson
Status: Merged
Approved by: gholt
Approved revision: 262
Merged at revision: 276
Proposed branch: lp:~sasimpson/swift/lp_746068_fix_for_proxy_logging
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 52 lines (+31/-0)
2 files modified
swift/proxy/server.py (+2/-0)
test/unit/proxy/test_server.py (+29/-0)
To merge this branch: bzr merge lp:~sasimpson/swift/lp_746068_fix_for_proxy_logging
Reviewer Review Type Date Requested Status
John Dickinson Approve
Review via email: mp+55949@code.launchpad.net

Description of the change

made client ip fill in, in the absence of a load balancer in the client field in the access logs.

To post a comment you must log in.
Revision history for this message
John Dickinson (notmyname) wrote :

looks good

review: Approve
Revision history for this message
gholt (gholt) wrote :

Don't approve until after Cactus.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'swift/proxy/server.py'
2--- swift/proxy/server.py 2011-03-18 15:04:09 +0000
3+++ swift/proxy/server.py 2011-04-01 15:14:35 +0000
4@@ -1551,6 +1551,8 @@
5 if not client and 'x-forwarded-for' in req.headers:
6 # remote user for other lbs
7 client = req.headers['x-forwarded-for'].split(',')[0].strip()
8+ if not client:
9+ client = req.remote_addr
10 logged_headers = None
11 if self.log_headers:
12 logged_headers = '\n'.join('%s: %s' % (k, v)
13
14=== modified file 'test/unit/proxy/test_server.py'
15--- test/unit/proxy/test_server.py 2011-03-10 16:52:03 +0000
16+++ test/unit/proxy/test_server.py 2011-04-01 15:14:35 +0000
17@@ -1925,6 +1925,35 @@
18 self.assertEquals(headers[:len(exp)], exp)
19 self.assert_('\r\nContent-Length: 0\r\n' in headers)
20
21+ def test_client_ip_logging(self):
22+ # test that the client ip field in the log gets populated with the
23+ # ip instead of being blank
24+ (prosrv, acc1srv, acc2srv, con2srv, con2srv, obj1srv, obj2srv) = \
25+ _test_servers
26+ (prolis, acc1lis, acc2lis, con2lis, con2lis, obj1lis, obj2lis) = \
27+ _test_sockets
28+
29+ class Logger(object):
30+
31+ def info(self, msg):
32+ self.msg = msg
33+
34+ orig_logger, orig_access_logger = prosrv.logger, prosrv.access_logger
35+ prosrv.logger = prosrv.access_logger = Logger()
36+ sock = connect_tcp(('localhost', prolis.getsockname()[1]))
37+ fd = sock.makefile()
38+ fd.write(
39+ 'GET /v1/a?format=json HTTP/1.1\r\nHost: localhost\r\n'
40+ 'Connection: close\r\nX-Auth-Token: t\r\n'
41+ 'Content-Length: 0\r\n'
42+ '\r\n')
43+ fd.flush()
44+ headers = readuntil2crlfs(fd)
45+ exp = 'HTTP/1.1 200'
46+ self.assertEquals(headers[:len(exp)], exp)
47+ exp = '127.0.0.1 127.0.0.1'
48+ self.assert_(exp in prosrv.logger.msg)
49+
50 def test_chunked_put_logging(self):
51 # GET account with a query string to test that
52 # Application.log_request logs the query string. Also, throws