Skip to content

Commit

Permalink
Return message_id in POSTed samples
Browse files Browse the repository at this point in the history
Change-Id: I93e33158ad9933bcdfc263f9f59146524d8b6824
Fixes: bug #1202696
  • Loading branch information
jd committed Aug 5, 2013
1 parent 6a07abf commit 3e1ef16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ceilometer/api/controllers/v2.py
Expand Up @@ -528,9 +528,9 @@ def get_consistent_source():
s.timestamp = now
s.source = '%s:%s' % (s.project_id, source)

with pecan.request.pipeline_manager.publisher(
context.get_admin_context()) as publisher:
publisher([sample.Sample(
published_samples = []
for s in samples:
published_sample = sample.Sample(
name=s.counter_name,
type=s.counter_type,
unit=s.counter_unit,
Expand All @@ -540,7 +540,13 @@ def get_consistent_source():
resource_id=s.resource_id,
timestamp=s.timestamp.isoformat(),
resource_metadata=s.resource_metadata,
source=source) for s in samples])
source=source)
s.message_id = published_sample.id
published_samples.append(published_sample)

with pecan.request.pipeline_manager.publisher(
context.get_admin_context()) as publisher:
publisher(published_samples)

# TODO(asalkeld) this is not ideal, it would be nice if the publisher
# returned the created sample message with message id (or at least the
Expand Down
3 changes: 1 addition & 2 deletions ceilometer/publisher/rpc.py
Expand Up @@ -22,7 +22,6 @@
import hmac
import itertools
import operator
import uuid
import urlparse

from oslo.config import cfg
Expand Down Expand Up @@ -101,7 +100,7 @@ def meter_message_from_counter(counter, secret):
'resource_id': counter.resource_id,
'timestamp': counter.timestamp,
'resource_metadata': counter.resource_metadata,
'message_id': str(uuid.uuid1()),
'message_id': counter.id,
}
msg['message_signature'] = compute_signature(msg, secret)
return msg
Expand Down
2 changes: 2 additions & 0 deletions ceilometer/sample.py
Expand Up @@ -25,6 +25,7 @@
"""

import copy
import uuid

from oslo.config import cfg

Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self, name, type, unit, volume, user_id, project_id,
self.timestamp = timestamp
self.resource_metadata = resource_metadata
self.source = source or cfg.CONF.sample_source
self.id = str(uuid.uuid1())

def as_dict(self):
return copy.copy(self.__dict__)
Expand Down
2 changes: 2 additions & 0 deletions tests/api/v2/test_post_samples_scenarios.py
Expand Up @@ -60,6 +60,8 @@ def test_one(self):

# timestamp not given so it is generated.
s1[0]['timestamp'] = data.json[0]['timestamp']
# Ignore message id that is randomly generated
s1[0]['message_id'] = data.json[0]['message_id']
# source is generated if not provided.
s1[0]['source'] = '%s:openstack' % s1[0]['project_id']

Expand Down

0 comments on commit 3e1ef16

Please sign in to comment.