aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-01-25 16:39:59 -0800
committerRoss Brattain <ross.b.brattain@intel.com>2017-03-08 08:45:41 -0800
commit8b8d99ac86d62e1816353b1eccf0811aed965d7f (patch)
tree248cfad3e2cb3dd50a70e8c658ede85422b06dbc
parent501175fbb095a771f5f1b9fb80dcf729192214d2 (diff)
fixes: use isinstance, fix logging, use dict literal
isinstance allows for matching with list and dict subclasses as well and list and dict themselves Use collections.Mapping for dict We still have to use list, because iterable is too generic, strings are iterable for example. use dict literal for point fix logging to use deferred interpolation Change-Id: I4c9b27fd07b57139e86315e39f58d54cc18e402d Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
-rw-r--r--yardstick/dispatcher/influxdb.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/yardstick/dispatcher/influxdb.py b/yardstick/dispatcher/influxdb.py
index d388d28a1..5a5af003b 100644
--- a/yardstick/dispatcher/influxdb.py
+++ b/yardstick/dispatcher/influxdb.py
@@ -13,6 +13,7 @@ import logging
import os
import time
+import collections
import requests
import six
from oslo_config import cfg
@@ -79,15 +80,17 @@ class InfluxdbDispatcher(DispatchBase):
def _dict_key_flatten(self, data):
next_data = {}
- if not [v for v in data.values()
- if type(v) == dict or type(v) == list]:
+ # 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 type(v) == dict:
+ if isinstance(v, collections.Mapping):
for n_k, n_v in six.iteritems(v):
next_data["%s.%s" % (k, n_k)] = n_v
- elif type(v) == list:
+ # 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:
@@ -119,11 +122,12 @@ class InfluxdbDispatcher(DispatchBase):
def _data_to_line_protocol(self, data):
msg = {}
- point = {}
- point["measurement"] = self.tc
- point["fields"] = self._dict_key_flatten(data["benchmark"]["data"])
- point["time"] = self._get_nano_timestamp(data)
- point["tags"] = self._get_extended_tags(data)
+ point = {
+ "measurement": self.tc,
+ "fields": self._dict_key_flatten(data["benchmark"]["data"]),
+ "time": self._get_nano_timestamp(data),
+ "tags": self._get_extended_tags(data),
+ }
msg["points"] = [point]
msg["tags"] = self.static_tags