Merge "Detect missing metric_id before passing through bytearray()"
This commit is contained in:
commit
c40bdb252f
|
@ -277,6 +277,15 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
||||||
pair = d.split('\t')
|
pair = d.split('\t')
|
||||||
dim_map[pair[0]] = pair[1]
|
dim_map[pair[0]] = pair[1]
|
||||||
|
|
||||||
|
if row.metric_id is None:
|
||||||
|
LOG.error(
|
||||||
|
'Metric is missing metric_id, using metric_id=None'
|
||||||
|
' name: {}, dimensions: {}'.format(
|
||||||
|
row.metric_name, row.dimensions))
|
||||||
|
return {'id': None,
|
||||||
|
'name': row.metric_name,
|
||||||
|
'dimensions': dim_map}
|
||||||
|
|
||||||
metric = {'id': binascii.hexlify(bytearray(row.metric_id)),
|
metric = {'id': binascii.hexlify(bytearray(row.metric_id)),
|
||||||
'name': row.metric_name,
|
'name': row.metric_name,
|
||||||
'dimensions': dim_map}
|
'dimensions': dim_map}
|
||||||
|
|
|
@ -335,6 +335,51 @@ class TestRepoMetricsCassandra(base.BaseTestCase):
|
||||||
u'hosttype': u'native'
|
u'hosttype': u'native'
|
||||||
}}], result)
|
}}], result)
|
||||||
|
|
||||||
|
# As Cassandra allows sparse data, it is possible to have a missing metric_id
|
||||||
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
|
"metrics_repository.Cluster.connect")
|
||||||
|
def test_list_metrics_empty_metric_id(self, cassandra_connect_mock):
|
||||||
|
cassandra_session_mock = cassandra_connect_mock.return_value
|
||||||
|
cassandra_future_mock = cassandra_session_mock.execute_async.return_value
|
||||||
|
|
||||||
|
Metric = namedtuple('Metric', 'metric_id metric_name dimensions')
|
||||||
|
|
||||||
|
cassandra_future_mock.result.return_value = [
|
||||||
|
Metric(
|
||||||
|
metric_id=None,
|
||||||
|
metric_name='disk.space_used_perc',
|
||||||
|
dimensions=[
|
||||||
|
'device\trootfs',
|
||||||
|
'hostname\thost0',
|
||||||
|
'hosttype\tnative',
|
||||||
|
'mount_point\t/']
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
repo = cassandra_repo.MetricsRepository()
|
||||||
|
|
||||||
|
result = repo.list_metrics(
|
||||||
|
"0b5e7d8c43f74430add94fba09ffd66e",
|
||||||
|
"region",
|
||||||
|
name="disk.space_user_perc",
|
||||||
|
dimensions={
|
||||||
|
"hostname": "host0",
|
||||||
|
"hosttype": "native",
|
||||||
|
"mount_point": "/",
|
||||||
|
"device": "rootfs"},
|
||||||
|
offset=None,
|
||||||
|
limit=1)
|
||||||
|
|
||||||
|
self.assertEqual([{
|
||||||
|
u'id': None,
|
||||||
|
u'name': u'disk.space_used_perc',
|
||||||
|
u'dimensions': {
|
||||||
|
u'device': u'rootfs',
|
||||||
|
u'hostname': u'host0',
|
||||||
|
u'mount_point': u'/',
|
||||||
|
u'hosttype': u'native'
|
||||||
|
}}], result)
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.cassandra."
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
"metrics_repository.Cluster.connect")
|
"metrics_repository.Cluster.connect")
|
||||||
def test_list_metric_names(self, cassandra_connect_mock):
|
def test_list_metric_names(self, cassandra_connect_mock):
|
||||||
|
|
Loading…
Reference in New Issue