From e5710fb9af60c699457f506e01842dc49cbe3a4f Mon Sep 17 00:00:00 2001 From: QiLiang Date: Wed, 30 Dec 2015 14:58:53 +0000 Subject: [PATCH] InfluxDB dispatcher add more tags - add runner_id tag - add test case name tag - add task_id tag JIRA: YARDSTICK-212 Change-Id: I75c27e23942a6e2189019e94bfe8026a5fd67621 Signed-off-by: QiLiang Conflicts: yardstick/dispatcher/influxdb.py (cherry picked from commit 65e32e513544392ce84c190434d23281b5c1afd2) Change-Id: Idcd582f96f2813e04d80a8c0677d9124b373fb48 --- tests/unit/dispatcher/test_influxdb.py | 4 +++- yardstick/cmd/commands/task.py | 14 ++++++++++++-- yardstick/dispatcher/influxdb.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/unit/dispatcher/test_influxdb.py b/tests/unit/dispatcher/test_influxdb.py index 3989f5889..5553c86a9 100644 --- a/tests/unit/dispatcher/test_influxdb.py +++ b/tests/unit/dispatcher/test_influxdb.py @@ -47,7 +47,9 @@ class InfluxdbDispatcherTestCase(unittest.TestCase): "sla": { "action": "monitor", "max_rtt": 10 - } + }, + "tc": "ping", + "task_id": "ea958583-c91e-461a-af14-2a7f9d7f79e7" } } self.data2 = { diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py index fbbca29ad..17e8f4c42 100755 --- a/yardstick/cmd/commands/task.py +++ b/yardstick/cmd/commands/task.py @@ -16,7 +16,9 @@ import atexit import ipaddress import time import logging +import uuid from itertools import ifilter + from yardstick.benchmark.contexts.base import Context from yardstick.benchmark.runners import base as base_runner from yardstick.common.task_template import TaskTemplate @@ -81,7 +83,9 @@ class TaskCommands(object): for i in range(0, len(task_files)): one_task_start_time = time.time() parser.path = task_files[i] - scenarios, run_in_parallel = parser.parse_task(task_args[i], + task_name = os.path.splitext(os.path.basename(task_files[i]))[0] + scenarios, run_in_parallel = parser.parse_task(task_name, + task_args[i], task_args_fnames[i]) self._run(scenarios, run_in_parallel, args.output_file) @@ -199,7 +203,7 @@ class TaskParser(object): return suite_params - def parse_task(self, task_args=None, task_args_file=None): + def parse_task(self, task_name, task_args=None, task_args_file=None): '''parses the task file and return an context and scenario instances''' print "Parsing task config:", self.path @@ -250,6 +254,12 @@ class TaskParser(object): run_in_parallel = cfg.get("run_in_parallel", False) + # add tc and task id for influxdb extended tags + task_id = str(uuid.uuid4()) + for scenario in cfg["scenarios"]: + scenario["tc"] = task_name + scenario["task_id"] = task_id + # TODO we need something better here, a class that represent the file return cfg["scenarios"], run_in_parallel diff --git a/yardstick/dispatcher/influxdb.py b/yardstick/dispatcher/influxdb.py index c58054167..2f3ff089f 100644 --- a/yardstick/dispatcher/influxdb.py +++ b/yardstick/dispatcher/influxdb.py @@ -53,6 +53,8 @@ class InfluxdbDispatcher(DispatchBase): self.influxdb_url = "%s/write?db=%s" % (self.target, self.db_name) self.raw_result = [] self.case_name = "" + self.tc = "" + self.task_id = -1 self.static_tags = { "pod_name": os.environ.get('POD_NAME', 'unknown'), "installer": os.environ.get('INSTALLER_TYPE', 'unknown'), @@ -86,12 +88,22 @@ class InfluxdbDispatcher(DispatchBase): return str(int(float(timestamp) * 1000000000)) + def _get_extended_tags(self, data): + tags = { + "runner_id": data["runner_id"], + "tc": self.tc, + "task_id": self.task_id + } + + return tags + def _data_to_line_protocol(self, data): msg = {} point = {} point["measurement"] = self.case_name point["fields"] = self._dict_key_flatten(data["benchmark"]["data"]) point["time"] = self._get_nano_timestamp(data) + point["tags"] = self._get_extended_tags(data) msg["points"] = [point] msg["tags"] = self.static_tags @@ -108,6 +120,8 @@ class InfluxdbDispatcher(DispatchBase): if isinstance(data, dict) and "scenario_cfg" in data: self.case_name = data["scenario_cfg"]["type"] + self.tc = data["scenario_cfg"]["tc"] + self.task_id = data["scenario_cfg"]["task_id"] return 0 if self.case_name == "": -- 2.16.6