From 3e1ef16fcbdcbc0a29476867213a997063825d52 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 1 Aug 2013 14:15:59 +0200 Subject: [PATCH] Return message_id in POSTed samples Change-Id: I93e33158ad9933bcdfc263f9f59146524d8b6824 Fixes: bug #1202696 --- ceilometer/api/controllers/v2.py | 14 ++++++++++---- ceilometer/publisher/rpc.py | 3 +-- ceilometer/sample.py | 2 ++ tests/api/v2/test_post_samples_scenarios.py | 2 ++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index a96025003..2daf38d03 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -528,9 +528,9 @@ class MeterController(rest.RestController): 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, @@ -540,7 +540,13 @@ class MeterController(rest.RestController): 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 diff --git a/ceilometer/publisher/rpc.py b/ceilometer/publisher/rpc.py index c6baebec4..a5734ccaf 100644 --- a/ceilometer/publisher/rpc.py +++ b/ceilometer/publisher/rpc.py @@ -22,7 +22,6 @@ import hashlib import hmac import itertools import operator -import uuid import urlparse from oslo.config import cfg @@ -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 diff --git a/ceilometer/sample.py b/ceilometer/sample.py index 7309468c7..7c1c3c470 100644 --- a/ceilometer/sample.py +++ b/ceilometer/sample.py @@ -25,6 +25,7 @@ in by the plugins that create them. """ import copy +import uuid from oslo.config import cfg @@ -68,6 +69,7 @@ class Sample(object): 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__) diff --git a/tests/api/v2/test_post_samples_scenarios.py b/tests/api/v2/test_post_samples_scenarios.py index 78d5396bb..a7a80bc97 100644 --- a/tests/api/v2/test_post_samples_scenarios.py +++ b/tests/api/v2/test_post_samples_scenarios.py @@ -60,6 +60,8 @@ class TestPostSamples(FunctionalTest, # 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']