Return message_id in POSTed samples
Change-Id: I93e33158ad9933bcdfc263f9f59146524d8b6824 Fixes: bug #1202696
This commit is contained in:
parent
6a07abf288
commit
3e1ef16fcb
@ -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
|
||||
|
@ -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
|
||||
|
@ -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__)
|
||||
|
@ -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']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user