Merge lp:~notmyname/swift/stats_log_lines into lp:~hudson-openstack/swift/trunk

Proposed by John Dickinson
Status: Merged
Approved by: gholt
Approved revision: 174
Merged at revision: 181
Proposed branch: lp:~notmyname/swift/stats_log_lines
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 78 lines (+46/-4)
2 files modified
swift/stats/access_processor.py (+3/-2)
test/unit/stats/test_access_processor.py (+43/-2)
To merge this branch: bzr merge lp:~notmyname/swift/stats_log_lines
Reviewer Review Type Date Requested Status
gholt (community) Approve
Review via email: mp+46514@code.launchpad.net

Description of the change

Stats system access log processor now allows for extra log fields to be at the end of the access log lines.

This allows the proxy server to freely append logged fields to log messages without breaking the stats system.

To post a comment you must log in.
Revision history for this message
gholt (gholt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'swift/stats/access_processor.py'
2--- swift/stats/access_processor.py 2011-01-14 08:45:39 +0000
3+++ swift/stats/access_processor.py 2011-01-17 18:38:51 +0000
4@@ -40,7 +40,7 @@
5 '''given a raw access log line, return a dict of the good parts'''
6 d = {}
7 try:
8- (_,
9+ (unused,
10 server,
11 client_ip,
12 lb_ip,
13@@ -57,7 +57,8 @@
14 etag,
15 trans_id,
16 headers,
17- processing_time) = (unquote(x) for x in raw_log[16:].split(' '))
18+ processing_time) = (unquote(x) for x in
19+ raw_log[16:].split(' ')[:18])
20 except ValueError:
21 self.logger.debug(_('Bad line data: %s') % repr(raw_log))
22 return {}
23
24=== modified file 'test/unit/stats/test_access_processor.py'
25--- test/unit/stats/test_access_processor.py 2011-01-04 23:34:43 +0000
26+++ test/unit/stats/test_access_processor.py 2011-01-17 18:38:51 +0000
27@@ -21,8 +21,49 @@
28
29 class TestAccessProcessor(unittest.TestCase):
30
31- def test_placeholder(self):
32- pass
33+ def test_log_line_parser_field_count(self):
34+ p = access_processor.AccessLogProcessor({})
35+ # too few fields
36+ log_line = [str(x) for x in range(17)]
37+ log_line[1] = 'proxy-server'
38+ log_line[4] = '1/Jan/3/4/5/6'
39+ log_line[6] = '/v1/a/c/o'
40+ log_line = 'x'*16 + ' '.join(log_line)
41+ res = p.log_line_parser(log_line)
42+ expected = {}
43+ self.assertEquals(res, expected)
44+ # right amount of fields
45+ log_line = [str(x) for x in range(18)]
46+ log_line[1] = 'proxy-server'
47+ log_line[4] = '1/Jan/3/4/5/6'
48+ log_line[6] = '/v1/a/c/o'
49+ log_line = 'x'*16 + ' '.join(log_line)
50+ res = p.log_line_parser(log_line)
51+ expected = {'code': 8, 'processing_time': '17', 'auth_token': '11',
52+ 'month': '01', 'second': '6', 'year': '3', 'tz': '+0000',
53+ 'http_version': '7', 'object_name': 'o', 'etag': '14',
54+ 'method': '5', 'trans_id': '15', 'client_ip': '2',
55+ 'bytes_out': 13, 'container_name': 'c', 'day': '1',
56+ 'minute': '5', 'account': 'a', 'hour': '4',
57+ 'referrer': '9', 'request': '/v1/a/c/o',
58+ 'user_agent': '10', 'bytes_in': 12, 'lb_ip': '3'}
59+ self.assertEquals(res, expected)
60+ # too many fields
61+ log_line = [str(x) for x in range(19)]
62+ log_line[1] = 'proxy-server'
63+ log_line[4] = '1/Jan/3/4/5/6'
64+ log_line[6] = '/v1/a/c/o'
65+ log_line = 'x'*16 + ' '.join(log_line)
66+ res = p.log_line_parser(log_line)
67+ expected = {'code': 8, 'processing_time': '17', 'auth_token': '11',
68+ 'month': '01', 'second': '6', 'year': '3', 'tz': '+0000',
69+ 'http_version': '7', 'object_name': 'o', 'etag': '14',
70+ 'method': '5', 'trans_id': '15', 'client_ip': '2',
71+ 'bytes_out': 13, 'container_name': 'c', 'day': '1',
72+ 'minute': '5', 'account': 'a', 'hour': '4',
73+ 'referrer': '9', 'request': '/v1/a/c/o',
74+ 'user_agent': '10', 'bytes_in': 12, 'lb_ip': '3'}
75+ self.assertEquals(res, expected)
76
77
78 if __name__ == '__main__':