Beispiel #1
0
    def _convert_log_to_json(log: Log) -> Dict:
        """
        Converts the given log to the JSON representation used by the InfluxDB client.
        :param log: the log to convert
        :return: the log as JSON
        """
        influxdb_log = InfluxDBLog.value_of(log)    # type: InfluxDBLog
        # InfluxDB does not handle microseconds - round to the nearest second
        if influxdb_log.timestamp.microsecond >= 500000:
            influxdb_log.timestamp = influxdb_log.timestamp + timedelta(seconds=1)
        influxdb_log.timestamp = influxdb_log.timestamp.replace(microsecond=0)

        influxdb_log_as_json = InfluxDBLogger._INFLUXDB_LOG_JSON_ENCODER.default(influxdb_log)

        return influxdb_log_as_json
Beispiel #2
0
 def test_value_of_with_influx_db_log(self):
     self.assertEqual(InfluxDBLog.value_of(self._influx_db_log), self._influx_db_log)