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

Proposed by John Dickinson
Status: Merged
Approved by: Chuck Thier
Approved revision: 133
Merged at revision: 135
Proposed branch: lp:~notmyname/swift/stats_improvement
Merge into: lp:~hudson-openstack/swift/trunk
Prerequisite: lp:~notmyname/swift/end_marker
Diff against target: 109 lines (+27/-36)
2 files modified
swift/stats/log_processor.py (+18/-31)
test/unit/stats/test_log_processor.py (+9/-5)
To merge this branch: bzr merge lp:~notmyname/swift/stats_improvement
Reviewer Review Type Date Requested Status
Chuck Thier (community) Approve
clayg Approve
Review via email: mp+41199@code.launchpad.net

Commit message

improved the container listings for the stats processor

Description of the change

improved the container listings for the stats processor

This fixes the issue where the stats system wouldn't process the last hour in the lookback window

To post a comment you must log in.
132. By John Dickinson

merged with trunk

133. By John Dickinson

merged with trunk

Revision history for this message
clayg (clay-gerrard) wrote :

I like the strptime stuff - much cleaner, I'm going to approve this just to get that in ;)

review: Approve
Revision history for this message
Chuck Thier (cthier) wrote :

I agree with clayg

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'swift/stats/log_processor.py'
2--- swift/stats/log_processor.py 2010-11-12 17:01:46 +0000
3+++ swift/stats/log_processor.py 2010-11-22 23:34:25 +0000
4@@ -113,48 +113,35 @@
5 listing_filter=None):
6 '''
7 Get a container listing, filtered by start_date, end_date, and
8- listing_filter. Dates, if given, should be in YYYYMMDDHH format
9+ listing_filter. Dates, if given, must be in YYYYMMDDHH format
10 '''
11 search_key = None
12 if start_date is not None:
13- date_parts = []
14 try:
15- year, start_date = start_date[:4], start_date[4:]
16- if year:
17- date_parts.append(year)
18- month, start_date = start_date[:2], start_date[2:]
19- if month:
20- date_parts.append(month)
21- day, start_date = start_date[:2], start_date[2:]
22- if day:
23- date_parts.append(day)
24- hour, start_date = start_date[:2], start_date[2:]
25- if hour:
26- date_parts.append(hour)
27- except IndexError:
28+ parsed_date = time.strptime(start_date, '%Y%m%d%H')
29+ except ValueError:
30 pass
31 else:
32- search_key = '/'.join(date_parts)
33+ year = '%04d' % parsed_date.tm_year
34+ month = '%02d' % parsed_date.tm_mon
35+ day = '%02d' % parsed_date.tm_mday
36+ hour = '%02d' % parsed_date.tm_hour
37+ search_key = '/'.join([year, month, day, hour])
38 end_key = None
39 if end_date is not None:
40- date_parts = []
41 try:
42- year, end_date = end_date[:4], end_date[4:]
43- if year:
44- date_parts.append(year)
45- month, end_date = end_date[:2], end_date[2:]
46- if month:
47- date_parts.append(month)
48- day, end_date = end_date[:2], end_date[2:]
49- if day:
50- date_parts.append(day)
51- hour, end_date = end_date[:2], end_date[2:]
52- if hour:
53- date_parts.append(hour)
54- except IndexError:
55+ parsed_date = time.strptime(end_date, '%Y%m%d%H')
56+ except ValueError:
57 pass
58 else:
59- end_key = '/'.join(date_parts)
60+ year = '%04d' % parsed_date.tm_year
61+ month = '%02d' % parsed_date.tm_mon
62+ day = '%02d' % parsed_date.tm_mday
63+ hour = '%02d' % parsed_date.tm_hour
64+ # Since the end_marker filters by <=, we need to add something
65+ # to then end_key to make sure we get all the data under the
66+ # last hour. Adding '/\x7f' should be all inclusive.
67+ end_key = '/'.join([year, month, day, hour]) + '/\x7f'
68 container_listing = self.internal_proxy.get_container_list(
69 swift_account,
70 container_name,
71
72=== modified file 'test/unit/stats/test_log_processor.py'
73--- test/unit/stats/test_log_processor.py 2010-11-19 22:52:31 +0000
74+++ test/unit/stats/test_log_processor.py 2010-11-22 23:34:25 +0000
75@@ -37,10 +37,11 @@
76 end_marker=None):
77 n = '2010/03/14/13/obj1'
78 if marker is None or n > marker:
79- if end_marker and n <= end_marker:
80- return [{'name': n}]
81- elif end_marker:
82- return []
83+ if end_marker:
84+ if n <= end_marker:
85+ return [{'name': n}]
86+ else:
87+ return []
88 return [{'name': n}]
89 return []
90
91@@ -178,6 +179,10 @@
92 end_date='2010031412')
93 expected = []
94 self.assertEquals(result, expected)
95+ result = p.get_container_listing('a', 'foo', start_date='2010031412',
96+ end_date='2010031413')
97+ expected = ['2010/03/14/13/obj1']
98+ self.assertEquals(result, expected)
99
100 def test_get_object_data(self):
101 p = log_processor.LogProcessor(self.proxy_config, DumbLogger())
102@@ -212,7 +217,6 @@
103 p = log_processor.LogProcessor(self.proxy_config, DumbLogger())
104 result = p.generate_keylist_mapping()
105 expected = {}
106- print p.plugins
107 self.assertEquals(result, expected)
108
109 def test_generate_keylist_mapping_with_dummy_plugins(self):