def test_make_lines(self):
        data = {
            "tags": {
                "empty_tag": "",
                "none_tag": None,
                "integer_tag": 2,
                "string_tag": "hello"
            },
            "points": [
                {
                    "measurement": "test",
                    "fields": {
                        "string_val": "hello!",
                        "int_val": 1,
                        "float_val": 1.1,
                        "none_field": None,
                        "bool_val": True,
                    }
                }
            ]
        }

        self.assertEqual(
            make_lines(data),
            'test,integer_tag=2,string_tag=hello '
            'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n'
        )
Ejemplo n.º 2
0
    def test_make_lines(self):
        data = {
            "tags": {
                "empty_tag": "",
                "none_tag": None,
                "integer_tag": 2,
                "string_tag": "hello"
            },
            "points": [
                {
                    "measurement": "test",
                    "fields": {
                        "string_val": "hello!",
                        "int_val": 1,
                        "float_val": 1.1,
                        "none_field": None,
                        "bool_val": True,
                    }
                }
            ]
        }

        self.assertEqual(
            make_lines(data),
            'test,integer_tag=2,string_tag=hello '
            'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n'
        )
Ejemplo n.º 3
0
def write_data_influx(task_id, timestamp, status, error=''):
    msg = {}
    point = {}
    point['measurement'] = 'tasklist'
    point['fields'] = {'status': status, 'error': error}
    point['time'] = timestamp
    point['tags'] = {'task_id': task_id}
    msg['points'] = [point]
    msg['tags'] = {}
    line = make_lines(msg).encode('utf-8')
    requests.post(write_url, data=line)
Ejemplo n.º 4
0
    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)
        msg["points"] = [point]
        msg["tags"] = self.static_tags

        return make_lines(msg).encode('utf-8')
Ejemplo n.º 5
0
    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)
        msg["points"] = [point]
        msg["tags"] = self.static_tags

        return make_lines(msg).encode('utf-8')
Ejemplo n.º 6
0
    def test_string_val_newline(self):
        data = {
            "points": [{
                "measurement": "m1",
                "fields": {
                    "multi_line": "line1\nline1\nline3"
                }
            }]
        }

        self.assertEqual(make_lines(data),
                         'm1 multi_line="line1\\nline1\\nline3"\n')
    def test_string_val_newline(self):
        data = {
            "points": [
                {
                    "measurement": "m1",
                    "fields": {
                        "multi_line": "line1\nline1\nline3"
                    }
                }
            ]
        }

        self.assertEqual(
            make_lines(data),
            'm1 multi_line="line1\\nline1\\nline3"\n'
        )
Ejemplo n.º 8
0
                'deploy_scenario': os.environ.get('DEPLOY_SCENARIO',
                                                  'unknown'),
                'installer': os.environ.get('INSTALLER_TYPE', 'unknown'),
                'pod_name': os.environ.get('NODE_NAME', 'unknown'),
                'version': os.environ.get('YARDSTICK_BRANCH', 'unknown')
            }

        point = {
            "measurement": case,
            "fields": utils.flatten_dict_key(data["data"]),
            "time": self._get_nano_timestamp(data),
            "tags": self._get_extended_tags(criteria),
        }
        msg["points"] = [point]
        msg["tags"] = self.tags

        return make_lines(msg).encode('utf-8')

    def _get_nano_timestamp(self, results):
        try:
            timestamp = results["timestamp"]
        except KeyError:
            timestamp = time.time()

        return str(int(float(timestamp) * 1000000000))

    def _get_extended_tags(self, criteria):
        tags = {"task_id": self.task_id, "criteria": criteria}

        return tags