Merge lp:~ev/oops-repository/whoopsie-daisy into lp:oops-repository

Proposed by Evan
Status: Merged
Merged at revision: 11
Proposed branch: lp:~ev/oops-repository/whoopsie-daisy
Merge into: lp:oops-repository
Diff against target: 77 lines (+22/-8)
2 files modified
oopsrepository/config.py (+2/-1)
oopsrepository/oopses.py (+20/-7)
To merge this branch: bzr merge lp:~ev/oops-repository/whoopsie-daisy
Reviewer Review Type Date Requested Status
Robert Collins Pending
Review via email: mp+88035@code.launchpad.net
To post a comment you must log in.
13. By Evan

Make OOPS_HOST an envar for consistency.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'oopsrepository/config.py'
--- oopsrepository/config.py 2011-02-26 09:30:53 +0000
+++ oopsrepository/config.py 2012-01-10 11:43:23 +0000
@@ -10,7 +10,8 @@
1010
11def get_config():11def get_config():
12 """Get a dict of the config variables controlling oopsrepository."""12 """Get a dict of the config variables controlling oopsrepository."""
13 result = dict(keyspace=os.environ.get('OOPS_KEYSPACE'))13 result = dict(keyspace=os.environ.get('OOPS_KEYSPACE'),
14 host=os.environ.get('OOPS_HOST'))
14 if not result['keyspace']:15 if not result['keyspace']:
15 raise Exception('No keyspace set - set via OOPS_KEYSPACE')16 raise Exception('No keyspace set - set via OOPS_KEYSPACE')
16 return result17 return result
1718
=== modified file 'oopsrepository/oopses.py'
--- oopsrepository/oopses.py 2011-04-03 11:14:12 +0000
+++ oopsrepository/oopses.py 2012-01-10 11:43:23 +0000
@@ -7,6 +7,7 @@
7"""basic operations on oopses in the db."""7"""basic operations on oopses in the db."""
88
9import json9import json
10import bson
10import time11import time
11import uuid12import uuid
1213
@@ -19,7 +20,7 @@
1920
20def prune(config):21def prune(config):
21 """Remove OOPSES that are over 30 days old."""22 """Remove OOPSES that are over 30 days old."""
22 pool = pycassa.connect(config['keyspace'])23 pool = pycassa.connect(config['keyspace'], config['host'])
23 dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')24 dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')
24 oops_cf = pycassa.ColumnFamily(pool, 'OOPS')25 oops_cf = pycassa.ColumnFamily(pool, 'OOPS')
25 # Find days to prune26 # Find days to prune
@@ -53,17 +54,11 @@
53 map(batch.remove, days)54 map(batch.remove, days)
54 batch.send()55 batch.send()
5556
56
57def insert(config, oopsid, oops_json):57def insert(config, oopsid, oops_json):
58 """Insert an OOPS into the system.58 """Insert an OOPS into the system.
59 59
60 :return: The day which the oops was filed under.60 :return: The day which the oops was filed under.
61 """61 """
62 pool = pycassa.connect(config['keyspace'])
63 dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')
64 oops_cf = pycassa.ColumnFamily(pool, 'OOPS')
65 day_key = time.strftime('%Y%m%d', time.gmtime())
66 now_uuid = uuid.uuid1()
67 # make sure the oops report is a json dict, and break out each key to a62 # make sure the oops report is a json dict, and break out each key to a
68 # separate column. For now, rather than worrying about typed column values63 # separate column. For now, rather than worrying about typed column values
69 # we just coerce them all to strings.64 # we just coerce them all to strings.
@@ -72,6 +67,24 @@
72 insert_dict = {}67 insert_dict = {}
73 for key, value in oops_dict.items():68 for key, value in oops_dict.items():
74 insert_dict[key] = json.dumps(value)69 insert_dict[key] = json.dumps(value)
70 return _insert(config, oopsid, insert_dict)
71
72def insert_bson(config, oopsid, oops_bson):
73 """Insert an OOPS into the system.
74
75 :return: The day which the oops was filed under.
76 """
77 oops_dict = bson.BSON(oops_bson)
78 insert_dict = oops_dict.to_dict()
79 return _insert(config, oopsid, insert_dict)
80
81def _insert(config, oopsid, insert_dict):
82 pool = pycassa.connect(config['keyspace'], config['host'])
83 dayoops_cf = pycassa.ColumnFamily(pool, 'DayOOPS')
84 oops_cf = pycassa.ColumnFamily(pool, 'OOPS')
85 day_key = time.strftime('%Y%m%d', time.gmtime())
86 now_uuid = uuid.uuid1()
87
75 oops_cf.insert(oopsid, insert_dict)88 oops_cf.insert(oopsid, insert_dict)
76 dayoops_cf.insert(day_key, {now_uuid:oopsid})89 dayoops_cf.insert(day_key, {now_uuid:oopsid})
77 return day_key90 return day_key

Subscribers

People subscribed via source and target branches

to all changes: