Add functionality for counting events

Similar to the existing streams functionality, this patch adds
the ability to get just a count of filtered events rather than
the full list of events.

There are corresponding changes in quince, quincy, and klugman.

Change-Id: Ic14845db48170a8481c764f5f2468f137758bd19
This commit is contained in:
Eddie Sheffield 2015-03-20 14:43:02 +00:00
parent 8b653622a7
commit e08924f1f8
3 changed files with 10 additions and 2 deletions

View File

@ -1,7 +1,7 @@
[metadata]
description-file = README.md
name = winchester
version = 0.4
version = 0.5
author = Monsyne Dragon
author_email = mdragon@rackspace.com
summary = An OpenStack notification event processing library.

View File

@ -486,6 +486,10 @@ class TestDB(unittest.TestCase):
for event in events:
self.assertTrue(event['message_id'] in self.events)
def test_find_event_count(self):
count = self.db.find_events(count=True)
self.assertEqual([{'count': 4}], count)
def test_find_events_date_filter(self):
_from = datetime.datetime(2014,8,1,10)
_to = datetime.datetime(2014,8,1,16)

View File

@ -130,7 +130,7 @@ class DBInterface(object):
@sessioned
def find_events(self, from_datetime=None, to_datetime=None,
event_name=None, traits=None, mark=None, limit=None,
session=None):
session=None, count=False):
order_desc = True
@ -161,6 +161,10 @@ class DBInterface(object):
models.Trait.name == name,
models.Trait.value == val)))
if count:
q = q.count()
return [{"count": q}]
if order_desc:
q = q.order_by(models.Event.id.desc())
mark_fmt = '%x'