diff options
author | Kubi <jean.gaoliang@huawei.com> | 2017-07-06 12:14:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-07-06 12:14:34 +0000 |
commit | 2bea82e39d62246552a9d6d49c74bbc32747f018 (patch) | |
tree | 4a83bfb2b001f7ef4ab51933c91e51df4a848755 /yardstick/dispatcher/influxdb.py | |
parent | 917dea49415183eaff6d2f2fbf32ddeff64d9dfe (diff) | |
parent | 25a37b2048281c64719bd6ad67860f65f6c31546 (diff) |
Merge "move flatten dict key to common utils"
Diffstat (limited to 'yardstick/dispatcher/influxdb.py')
-rw-r--r-- | yardstick/dispatcher/influxdb.py | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/yardstick/dispatcher/influxdb.py b/yardstick/dispatcher/influxdb.py index 373aae13a..f157e91f9 100644 --- a/yardstick/dispatcher/influxdb.py +++ b/yardstick/dispatcher/influxdb.py @@ -12,10 +12,9 @@ from __future__ import absolute_import import logging import time -import collections import requests -import six +from yardstick.common import utils from third_party.influxdb.influxdb_line_protocol import make_lines from yardstick.dispatcher.base import Base as DispatchBase @@ -80,7 +79,7 @@ class InfluxdbDispatcher(DispatchBase): msg = {} point = { "measurement": case, - "fields": self._dict_key_flatten(data["data"]), + "fields": utils.flatten_dict_key(data["data"]), "time": self._get_nano_timestamp(data), "tags": self._get_extended_tags(criteria), } @@ -89,27 +88,6 @@ class InfluxdbDispatcher(DispatchBase): return make_lines(msg).encode('utf-8') - def _dict_key_flatten(self, data): - next_data = {} - - # use list, because iterable is too generic - if not [v for v in data.values() if - isinstance(v, (collections.Mapping, list))]: - return data - - for k, v in six.iteritems(data): - if isinstance(v, collections.Mapping): - for n_k, n_v in six.iteritems(v): - next_data["%s.%s" % (k, n_k)] = n_v - # use list because iterable is too generic - elif isinstance(v, list): - for index, item in enumerate(v): - next_data["%s%d" % (k, index)] = item - else: - next_data[k] = v - - return self._dict_key_flatten(next_data) - def _get_nano_timestamp(self, results): try: timestamp = results["timestamp"] |