Add API endpoint for listing raw event data
This change adds some of the endpoints for listing raw event data from the database. It does not yet support listing events by project id. It also fixes a problem with the MongoDB driver returning Mongo's ObjectId instances in the results of the event query, which makes them impossible to serialize via JSON. Change-Id: I08d122ecd2f726fb1b2880bc22e28113f6a3aeb1 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
"""MongoDB storage backend
|
||||
"""
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
|
||||
from ceilometer.openstack.common import log
|
||||
@@ -240,8 +241,11 @@ class Connection(base.Connection):
|
||||
upsert=True,
|
||||
)
|
||||
|
||||
# Record the raw data for the event
|
||||
self.db.meter.insert(data)
|
||||
# Record the raw data for the event. Use a copy so we do not
|
||||
# modify a data structure owned by our caller (the driver adds
|
||||
# a new key '_id').
|
||||
record = copy.copy(data)
|
||||
self.db.meter.insert(record)
|
||||
return
|
||||
|
||||
def get_users(self, source=None):
|
||||
@@ -293,6 +297,8 @@ class Connection(base.Connection):
|
||||
for resource in self.db.resource.find(q):
|
||||
r = {}
|
||||
r.update(resource)
|
||||
# Replace the '_id' key with 'resource_id' to meet the
|
||||
# caller's expectations.
|
||||
r['resource_id'] = r['_id']
|
||||
del r['_id']
|
||||
yield r
|
||||
@@ -302,7 +308,12 @@ class Connection(base.Connection):
|
||||
"""
|
||||
q = make_query_from_filter(event_filter, require_meter=False)
|
||||
events = self.db.meter.find(q)
|
||||
return events
|
||||
for e in events:
|
||||
# Remove the ObjectId generated by the database when
|
||||
# the event was inserted. It is an implementation
|
||||
# detail that should not leak outside of the driver.
|
||||
del e['_id']
|
||||
yield e
|
||||
|
||||
def get_volume_sum(self, event_filter):
|
||||
"""Return the sum of the volume field for the events
|
||||
|
||||
Reference in New Issue
Block a user