made account stats log processing more robust and added tests
This commit is contained in:
parent
c9e43e0510
commit
4cb4f57f7c
@ -34,15 +34,15 @@ class StatsLogProcessor(object):
|
||||
(account,
|
||||
container_count,
|
||||
object_count,
|
||||
bytes_used) = line.split(',')
|
||||
bytes_used) = line.split(',')[:4]
|
||||
account = account.strip('"')
|
||||
container_count = int(container_count.strip('"'))
|
||||
object_count = int(object_count.strip('"'))
|
||||
bytes_used = int(bytes_used.strip('"'))
|
||||
except (IndexError, ValueError):
|
||||
# bad line data
|
||||
self.logger.debug(_('Bad line data: %s') % repr(line))
|
||||
continue
|
||||
account = account.strip('"')
|
||||
container_count = int(container_count.strip('"'))
|
||||
object_count = int(object_count.strip('"'))
|
||||
bytes_used = int(bytes_used.strip('"'))
|
||||
aggr_key = (account, year, month, day, hour)
|
||||
d = account_totals.get(aggr_key, {})
|
||||
d['replica_count'] = d.setdefault('replica_count', 0) + 1
|
||||
|
@ -13,16 +13,38 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# TODO: Tests
|
||||
|
||||
import unittest
|
||||
from slogging import stats_processor
|
||||
|
||||
|
||||
class TestStatsProcessor(unittest.TestCase):
|
||||
|
||||
def test_placeholder(self):
|
||||
pass
|
||||
def test_process(self):
|
||||
p = stats_processor.StatsLogProcessor({})
|
||||
test_obj_stream = ['a, 1, 1, 1', 'a, 1, 1, 1']
|
||||
res = p.process(test_obj_stream, 'foo', 'bar', '2011/03/14/12/baz')
|
||||
expected = {('a', '2011', '03', '14', '12'):
|
||||
{'object_count': 2, 'container_count': 2,
|
||||
'replica_count': 2, 'bytes_used': 2}}
|
||||
self.assertEquals(res, expected)
|
||||
|
||||
def test_process_extra_columns(self):
|
||||
p = stats_processor.StatsLogProcessor({})
|
||||
test_obj_stream = ['a, 1, 1, 1, extra']
|
||||
res = p.process(test_obj_stream, 'foo', 'bar', '2011/03/14/12/baz')
|
||||
expected = {('a', '2011', '03', '14', '12'):
|
||||
{'object_count': 1, 'container_count': 1,
|
||||
'replica_count': 1, 'bytes_used': 1}}
|
||||
self.assertEquals(res, expected)
|
||||
|
||||
def test_process_bad_line(self):
|
||||
p = stats_processor.StatsLogProcessor({})
|
||||
test_obj_stream = ['a, 1, 1, 1, extra', '', 'some bad line']
|
||||
res = p.process(test_obj_stream, 'foo', 'bar', '2011/03/14/12/baz')
|
||||
expected = {('a', '2011', '03', '14', '12'):
|
||||
{'object_count': 1, 'container_count': 1,
|
||||
'replica_count': 1, 'bytes_used': 1}}
|
||||
self.assertEquals(res, expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user