Merge "Return message_id in POSTed samples"
This commit is contained in:
commit
aad2ce771d
@ -528,9 +528,9 @@ class MeterController(rest.RestController):
|
|||||||
s.timestamp = now
|
s.timestamp = now
|
||||||
s.source = '%s:%s' % (s.project_id, source)
|
s.source = '%s:%s' % (s.project_id, source)
|
||||||
|
|
||||||
with pecan.request.pipeline_manager.publisher(
|
published_samples = []
|
||||||
context.get_admin_context()) as publisher:
|
for s in samples:
|
||||||
publisher([sample.Sample(
|
published_sample = sample.Sample(
|
||||||
name=s.counter_name,
|
name=s.counter_name,
|
||||||
type=s.counter_type,
|
type=s.counter_type,
|
||||||
unit=s.counter_unit,
|
unit=s.counter_unit,
|
||||||
@ -540,7 +540,13 @@ class MeterController(rest.RestController):
|
|||||||
resource_id=s.resource_id,
|
resource_id=s.resource_id,
|
||||||
timestamp=s.timestamp.isoformat(),
|
timestamp=s.timestamp.isoformat(),
|
||||||
resource_metadata=s.resource_metadata,
|
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
|
# 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
|
# returned the created sample message with message id (or at least the
|
||||||
|
@ -22,7 +22,6 @@ import hashlib
|
|||||||
import hmac
|
import hmac
|
||||||
import itertools
|
import itertools
|
||||||
import operator
|
import operator
|
||||||
import uuid
|
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
@ -101,7 +100,7 @@ def meter_message_from_counter(counter, secret):
|
|||||||
'resource_id': counter.resource_id,
|
'resource_id': counter.resource_id,
|
||||||
'timestamp': counter.timestamp,
|
'timestamp': counter.timestamp,
|
||||||
'resource_metadata': counter.resource_metadata,
|
'resource_metadata': counter.resource_metadata,
|
||||||
'message_id': str(uuid.uuid1()),
|
'message_id': counter.id,
|
||||||
}
|
}
|
||||||
msg['message_signature'] = compute_signature(msg, secret)
|
msg['message_signature'] = compute_signature(msg, secret)
|
||||||
return msg
|
return msg
|
||||||
|
@ -25,6 +25,7 @@ in by the plugins that create them.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import uuid
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ class Sample(object):
|
|||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.resource_metadata = resource_metadata
|
self.resource_metadata = resource_metadata
|
||||||
self.source = source or cfg.CONF.sample_source
|
self.source = source or cfg.CONF.sample_source
|
||||||
|
self.id = str(uuid.uuid1())
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return copy.copy(self.__dict__)
|
return copy.copy(self.__dict__)
|
||||||
|
@ -60,6 +60,8 @@ class TestPostSamples(FunctionalTest,
|
|||||||
|
|
||||||
# timestamp not given so it is generated.
|
# timestamp not given so it is generated.
|
||||||
s1[0]['timestamp'] = data.json[0]['timestamp']
|
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.
|
# source is generated if not provided.
|
||||||
s1[0]['source'] = '%s:openstack' % s1[0]['project_id']
|
s1[0]['source'] = '%s:openstack' % s1[0]['project_id']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user