Try to get rid of the "events" & "raw events" naming in the code.

Rather use the term "samples" as having both is confusing.
Note: this does *not* change the API, just the terminology in the code.

bug 1104492
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Change-Id: If8cf89db60b52815db8e0acbf466400d0e9238c6
This commit is contained in:
Angus Salkeld 2013-03-20 22:12:59 +11:00
parent 4abb407152
commit a7000fd1ca
10 changed files with 107 additions and 103 deletions

View File

@ -322,7 +322,7 @@ class Statistics(wtypes.Base):
# If we got valid timestamps back, compute a duration in minutes.
#
# If the min > max after clamping then we know the
# timestamps on the events fell outside of the time
# timestamps on the samples fell outside of the time
# range we care about for the query, so treat them as
# "invalid."
#
@ -365,7 +365,7 @@ class MeterController(rest.RestController):
@wsme_pecan.wsexpose([Sample], [Query])
def get_all(self, q=[]):
"""Return sample data for the meter.
"""Return samples for the meter.
:param q: Filter rules for the data to be returned.
"""
@ -373,12 +373,12 @@ class MeterController(rest.RestController):
kwargs['meter'] = self._id
f = storage.EventFilter(**kwargs)
return [Sample(**e)
for e in pecan.request.storage_conn.get_raw_events(f)
for e in pecan.request.storage_conn.get_samples(f)
]
@wsme_pecan.wsexpose([Statistics], [Query], int)
def statistics(self, q=[], period=None):
"""Computes the statistics of the meter events in the time range given.
"""Computes the statistics of the samples in the time range given.
:param q: Filter rules for the data to be returned.
:param period: Returned result will be an array of statistics for a

View File

@ -55,10 +55,10 @@
# [x] /sources/<source>/meters -- list of meters reporting for parent obj
# [x] /users/<user>/meters -- list of meters reporting for parent obj
#
# [x] /projects/<project>/meters/<meter> -- events
# [x] /resources/<resource>/meters/<meter> -- events
# [x] /sources/<source>/meters/<meter> -- events
# [x] /users/<user>/meters/<meter> -- events
# [x] /projects/<project>/meters/<meter> -- samples
# [x] /resources/<resource>/meters/<meter> -- samples
# [x] /sources/<source>/meters/<meter> -- samples
# [x] /users/<user>/meters/<meter> -- samples
#
# [ ] /projects/<project>/meters/<meter>/duration -- total time for selected
# meter
@ -380,15 +380,19 @@ def list_projects_by_source(source):
return _list_projects(source=source)
## APIs for working with events.
## APIs for working with samples.
def _list_events(meter,
project=None,
resource=None,
source=None,
user=None):
"""Return a list of raw metering events.
def _list_samples(meter,
project=None,
resource=None,
source=None,
user=None):
"""Return a list of raw samples.
Note: the API talks about "events" these are equivelent to samples.
but we still need to return the samples within the "events" dict
to maintain API compatibilty.
"""
q_ts = _get_query_timestamps(flask.request.args)
f = storage.EventFilter(
@ -401,7 +405,7 @@ def _list_events(meter,
end=q_ts['end_timestamp'],
metaquery=_get_metaquery(flask.request.args),
)
events = list(flask.request.storage_conn.get_raw_events(f))
events = list(flask.request.storage_conn.get_samples(f))
jsonified = flask.jsonify(events=events)
if request_wants_html():
return flask.templating.render_template('list_event.html',
@ -415,38 +419,38 @@ def _list_events(meter,
@blueprint.route('/projects/<project>/meters/<meter>')
def list_events_by_project(project, meter):
"""Return a list of raw metering events for the project.
def list_samples_by_project(project, meter):
"""Return a list of raw samples for the project.
:param project: The ID of the project.
:param meter: The name of the meter.
:param start_timestamp: Limits events by timestamp >= this value.
:param start_timestamp: Limits samples by timestamp >= this value.
(optional)
:type start_timestamp: ISO date in UTC
:param end_timestamp: Limits events by timestamp < this value.
:param end_timestamp: Limits samples by timestamp < this value.
(optional)
:type end_timestamp: ISO date in UTC
"""
check_authorized_project(project)
return _list_events(project=project,
meter=meter,
)
return _list_samples(project=project,
meter=meter,
)
@blueprint.route('/resources/<resource>/meters/<meter>')
def list_events_by_resource(resource, meter):
"""Return a list of raw metering events for the resource.
def list_samples_by_resource(resource, meter):
"""Return a list of raw samples for the resource.
:param resource: The ID of the resource.
:param meter: The name of the meter.
:param start_timestamp: Limits events by timestamp >= this value.
:param start_timestamp: Limits samples by timestamp >= this value.
(optional)
:type start_timestamp: ISO date in UTC
:param end_timestamp: Limits events by timestamp < this value.
:param end_timestamp: Limits samples by timestamp < this value.
(optional)
:type end_timestamp: ISO date in UTC
"""
return _list_events(
return _list_samples(
resource=resource,
meter=meter,
project=acl.get_limited_to_project(flask.request.headers),
@ -454,19 +458,19 @@ def list_events_by_resource(resource, meter):
@blueprint.route('/sources/<source>/meters/<meter>')
def list_events_by_source(source, meter):
"""Return a list of raw metering events for the source.
def list_samples_by_source(source, meter):
"""Return a list of raw samples for the source.
:param source: The ID of the reporting source.
:param meter: The name of the meter.
:param start_timestamp: Limits events by timestamp >= this value.
:param start_timestamp: Limits samples by timestamp >= this value.
(optional)
:type start_timestamp: ISO date in UTC
:param end_timestamp: Limits events by timestamp < this value.
:param end_timestamp: Limits samples by timestamp < this value.
(optional)
:type end_timestamp: ISO date in UTC
"""
return _list_events(
return _list_samples(
source=source,
meter=meter,
project=acl.get_limited_to_project(flask.request.headers),
@ -474,19 +478,19 @@ def list_events_by_source(source, meter):
@blueprint.route('/users/<user>/meters/<meter>')
def list_events_by_user(user, meter):
"""Return a list of raw metering events for the user.
def list_samples_by_user(user, meter):
"""Return a list of raw samples for the user.
:param user: The ID of the user.
:param meter: The name of the meter.
:param start_timestamp: Limits events by timestamp >= this value.
:param start_timestamp: Limits samples by timestamp >= this value.
(optional)
:type start_timestamp: ISO date in UTC
:param end_timestamp: Limits events by timestamp < this value.
:param end_timestamp: Limits samples by timestamp < this value.
(optional)
:type end_timestamp: ISO date in UTC
"""
return _list_events(
return _list_samples(
user=user,
meter=meter,
project=acl.get_limited_to_project(flask.request.headers),
@ -571,7 +575,7 @@ def compute_duration_by_resource(resource, meter):
# If we got valid timestamps back, compute a duration in minutes.
#
# If the min > max after clamping then we know the
# timestamps on the events fell outside of the time
# timestamps on the samples fell outside of the time
# range we care about for the query, so treat them as
# "invalid."
#
@ -624,7 +628,7 @@ def compute_max_resource_volume(resource, meter):
@blueprint.route('/resources/<resource>/meters/<meter>/volume/sum')
def compute_resource_volume_sum(resource, meter):
"""Return the total volume for a meter.
"""Return the sum of samples for a meter.
:param resource: The ID of the resource.
:param meter: The name of the meter.

View File

@ -120,14 +120,14 @@ class Connection(object):
"""
@abc.abstractmethod
def get_raw_events(self, event_filter):
"""Return an iterable of raw event data as created by
def get_samples(self, event_filter):
"""Return an iterable of samples as created by
:func:`ceilometer.meter.meter_message_from_counter`.
"""
@abc.abstractmethod
def get_volume_sum(self, event_filter):
"""Return the sum of the volume field for the events
"""Return the sum of the volume field for the samples
described by the query parameters.
The filter must have a meter value set.
@ -139,7 +139,7 @@ class Connection(object):
@abc.abstractmethod
def get_volume_max(self, event_filter):
"""Return the maximum of the volume field for the events
"""Return the maximum of the volume field for the samples
described by the query parameters.
The filter must have a meter value set.
@ -151,8 +151,8 @@ class Connection(object):
@abc.abstractmethod
def get_event_interval(self, event_filter):
"""Return the min and max timestamps from events,
using the event_filter to limit the events seen.
"""Return the min and max timestamps from samples,
using the event_filter to limit the samples seen.
( datetime.datetime(), datetime.datetime() )
"""

View File

@ -301,7 +301,7 @@ class Connection(base.Connection):
resource_ids = {}
if start_timestamp or end_timestamp:
# Look for resources matching the above criteria and with
# events in the time range we care about, then change the
# samples in the time range we care about, then change the
# resource query to return just those resources by id.
g = self.meter.scan(filter=q, row_start=start_row,
row_stop=end_row)
@ -381,8 +381,8 @@ class Connection(base.Connection):
}
yield m
def get_raw_events(self, event_filter):
"""Return an iterable of raw event data as created by
def get_samples(self, event_filter):
"""Return an iterable of samples as created by
:func:`ceilometer.meter.meter_message_from_counter`.
"""
q, start, stop = make_query_from_filter(event_filter,
@ -494,7 +494,7 @@ class Connection(base.Connection):
return list(results)
def get_volume_sum(self, event_filter):
"""Return the sum of the volume field for the events
"""Return the sum of the volume field for the samples
described by the query parameters.
"""
q, start, stop = make_query_from_filter(event_filter)
@ -509,7 +509,7 @@ class Connection(base.Connection):
for (k, v) in results.iteritems())
def get_volume_max(self, event_filter):
"""Return the maximum of the volume field for the events
"""Return the maximum of the volume field for the samples
described by the query parameters.
"""
@ -525,8 +525,8 @@ class Connection(base.Connection):
for (k, v) in results.iteritems())
def get_event_interval(self, event_filter):
"""Return the min and max timestamps from events,
using the event_filter to limit the events seen.
"""Return the min and max timestamps from samples,
using the event_filter to limit the samples seen.
( datetime.datetime(), datetime.datetime() )
"""

View File

@ -118,24 +118,24 @@ class Connection(base.Connection):
"""
return []
def get_raw_events(self, event_filter):
"""Return an iterable of raw event data as created by
def get_samples(self, event_filter):
"""Return an iterable of samples as created by
:func:`ceilometer.meter.meter_message_from_counter`.
"""
return []
def get_volume_sum(self, event_filter):
"""Return the sum of the volume field for the events
"""Return the sum of the volume field for the samples
described by the query parameters.
"""
def get_volume_max(self, event_filter):
"""Return the maximum of the volume field for the events
"""Return the maximum of the volume field for the samples
described by the query parameters.
"""
def get_event_interval(self, event_filter):
"""Return the min and max timestamp for events
"""Return the min and max timestamp for samples
matching the event_filter.
"""

View File

@ -116,7 +116,7 @@ def make_query_from_filter(event_filter, require_meter=True):
if event_filter.source:
q['source'] = event_filter.source
# so the events call metadata resource_metadata, so we convert
# so the samples call metadata resource_metadata, so we convert
# to that.
q.update(dict(('resource_%s' % k, v)
for (k, v) in event_filter.metaquery.iteritems()))
@ -409,7 +409,7 @@ class Connection(base.Connection):
# to put into it today.
if start_timestamp or end_timestamp:
# Look for resources matching the above criteria and with
# events in the time range we care about, then change the
# samples in the time range we care about, then change the
# resource query to return just those resources by id.
ts_range = make_timestamp_range(start_timestamp, end_timestamp)
if ts_range:
@ -469,18 +469,18 @@ class Connection(base.Connection):
m['user_id'] = r['user_id']
yield m
def get_raw_events(self, event_filter):
"""Return an iterable of raw event data as created by
def get_samples(self, event_filter):
"""Return an iterable of samples as created by
:func:`ceilometer.meter.meter_message_from_counter`.
"""
q = make_query_from_filter(event_filter, require_meter=False)
events = self.db.meter.find(q)
for e in events:
samples = self.db.meter.find(q)
for s in samples:
# 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
del s['_id']
yield s
def get_meter_statistics(self, event_filter, period=None):
"""Return a dictionary containing meter statistics.
@ -524,7 +524,7 @@ class Connection(base.Connection):
key=operator.itemgetter('period_start'))
def get_volume_sum(self, event_filter):
"""Return the sum of the volume field for the events
"""Return the sum of the volume field for the samples
described by the query parameters.
"""
q = make_query_from_filter(event_filter)
@ -537,7 +537,7 @@ class Connection(base.Connection):
for r in results['results'])
def get_volume_max(self, event_filter):
"""Return the maximum of the volume field for the events
"""Return the maximum of the volume field for the samples
described by the query parameters.
"""
q = make_query_from_filter(event_filter)
@ -578,8 +578,8 @@ class Connection(base.Connection):
return (a_min, a_max)
def get_event_interval(self, event_filter):
"""Return the min and max timestamps from events,
using the event_filter to limit the events seen.
"""Return the min and max timestamps from samples,
using the event_filter to limit the samples seen.
( datetime.datetime(), datetime.datetime() )
"""

View File

@ -328,27 +328,27 @@ class Connection(base.Connection):
m['unit'] = meter.counter_unit
yield m
def get_raw_events(self, event_filter):
"""Return an iterable of raw event data as created by
def get_samples(self, event_filter):
"""Return an iterable of samples as created by
:func:`ceilometer.meter.meter_message_from_counter`.
"""
query = model_query(Meter, session=self.session)
query = make_query_from_filter(query, event_filter,
require_meter=False)
events = query.all()
samples = query.all()
for e in events:
for s in samples:
# Remove the id generated by the database when
# the event was inserted. It is an implementation
# detail that should not leak outside of the driver.
e = row2dict(e)
del e['id']
s = row2dict(s)
del s['id']
# Replace 'sources' with 'source' to meet the caller's
# expectation, Meter.sources contains one and only one
# source in the current implementation.
e['source'] = e['sources'][0]['id']
del e['sources']
yield e
s['source'] = s['sources'][0]['id']
del s['sources']
yield s
def _make_volume_query(self, event_filter, counter_volume_func):
"""Returns complex Meter counter_volume query for max and sum."""
@ -372,8 +372,8 @@ class Connection(base.Connection):
return ({'resource_id': x, 'value': y} for x, y in results)
def get_event_interval(self, event_filter):
"""Return the min and max timestamps from events,
using the event_filter to limit the events seen.
"""Return the min and max timestamps from samples,
using the event_filter to limit the samples seen.
( datetime.datetime(), datetime.datetime() )
"""

View File

@ -40,7 +40,7 @@
collector
Software service running on the OpenStack infrastructure
monitoring notifications from other OpenStack components and
meter events from the ceilometer agent and recording the results
samples from the ceilometer agent and recording the results
in the database.
compute agent

View File

@ -327,34 +327,34 @@ class MeterTest(DBTestBase):
class RawEventTest(DBTestBase):
def test_get_raw_events_by_user(self):
def test_get_samples_by_user(self):
f = storage.EventFilter(user='user-id')
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert len(results) == 2
for meter in results:
assert meter in [self.msg1, self.msg2]
def test_get_raw_events_by_project(self):
def test_get_samples_by_project(self):
f = storage.EventFilter(project='project-id')
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert results
for meter in results:
assert meter in [self.msg1, self.msg2, self.msg3]
def test_get_raw_events_by_resource(self):
def test_get_samples_by_resource(self):
f = storage.EventFilter(user='user-id', resource='resource-id')
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert results
meter = results[0]
assert meter is not None
assert meter == self.msg1
def test_get_events_by_metaquery(self):
def test_get_samples_by_metaquery(self):
q = {'metadata.display_name': 'test-server'}
f = storage.EventFilter(metaquery=q)
got_not_imp = False
try:
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert results
for meter in results:
assert meter in self.msgs
@ -362,48 +362,48 @@ class RawEventTest(DBTestBase):
got_not_imp = True
self.assertTrue(got_not_imp)
def test_get_raw_events_by_start_time(self):
def test_get_samples_by_start_time(self):
f = storage.EventFilter(
user='user-id',
start=datetime.datetime(2012, 7, 2, 10, 41),
)
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert len(results) == 1
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 41)
def test_get_raw_events_by_end_time(self):
def test_get_samples_by_end_time(self):
f = storage.EventFilter(
user='user-id',
end=datetime.datetime(2012, 7, 2, 10, 41),
)
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
length = len(results)
assert length == 1
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 40)
def test_get_raw_events_by_both_times(self):
def test_get_samples_by_both_times(self):
f = storage.EventFilter(
start=datetime.datetime(2012, 7, 2, 10, 42),
end=datetime.datetime(2012, 7, 2, 10, 43),
)
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
length = len(results)
assert length == 1
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 42)
def test_get_raw_events_by_meter(self):
def test_get_samples_by_name(self):
f = storage.EventFilter(user='user-id', meter='no-such-meter')
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert not results
def test_get_raw_events_by_meter2(self):
def test_get_samples_by_name2(self):
f = storage.EventFilter(user='user-id', meter='instance')
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert results
def test_get_raw_events_by_source(self):
def test_get_samples_by_source(self):
f = storage.EventFilter(source='test-1')
results = list(self.conn.get_raw_events(f))
results = list(self.conn.get_samples(f))
assert results
assert len(results) == 1

View File

@ -88,7 +88,7 @@ def show_raw(db, args):
print u
for resource in db.get_resources(user=u):
print ' ', resource['resource_id']
for event in db.get_raw_events(storage.EventFilter(
for event in db.get_samples(storage.EventFilter(
user=u,
resource=resource['resource_id'],
)):