Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

make_lines does not provide timestamps in the resultant line protocol string #788

Closed
shantanoo-desai opened this issue Feb 24, 2020 · 2 comments

Comments

@shantanoo-desai
Copy link
Contributor

  • InfluxDB version: e.g. 1.7.7 (output of the influx version command)
    InfluxDB v.1.6.1

  • InfluxDB-python version: e.g. 5.2.2 (output of the python -c "from __future__ import print_function; import influxdb; print(influxdb.__version__)" command)
    5.2.3

  • Python version: e.g. 3.7.4 (output of the python --version command)
    3.6.1

  • Operating system version: e.g. Windows 10, Ubuntu 18.04, macOS 10.14.5
    Windows 10

Behavior

Assuming I wish to convert the following valid JSON structure:

measurement = {
    'tags': {
          'source': 'gps'
     }, 
     'points': [
          {
           'measurement': 'location', 
           'fields': {
                  'lat': 53.11203666666667
           }
      }
     ],
     'time': '1582562852'
}

I use the following code:

from influxdb import line_protocol
measurement = {
    'tags': {
          'source': 'gps'
     }, 
     'points': [
          {
           'measurement': 'location', 
           'fields': {
                  'lat': 53.11203666666667
           }
      }
     ],
     'time': '1582562852'
}

print(line_protocol.make_lines(measurement, precision='s'))

Only provides the following output without the timestamp:

'location,source=gps lat=53.11203666666667\n'

There is timestamp that is added to the line protocol result.

Irrespective if time is a string or not the resultant line protocol does not add timestamps to it.

@shantanoo-desai
Copy link
Contributor Author

shantanoo-desai commented Feb 24, 2020

Upon looking into tests it seems that the the time value should be within the points array. The following works:

from influxdb import line_protocol
measurement = {
    'tags': {
          'source': 'gps'
     }, 
     'points': [
          {
           'measurement': 'location',
           'time': 1582562852,
           'fields': {
                  'lat': 53.11203666666667
           }
      }
     ]
}

print(line_protocol.make_lines(measurement, precision='s'))

Output:

'location,source=gps lat=53.11203666666667 1582562852\n'

This implies there is an error in the documentation for UDP that I previously wrote. There the time key value pair should be within each point.

@sebito91 which is the correct JSON structure for the time parameter here? Should it be outside the points or should it be within each point?

@shantanoo-desai
Copy link
Contributor Author

Case 1: HTTP

the write_points uses a private method _write_points which in turn uses write to insert data within the database. The write uses make_lines function from line_protocol.py.
Within the make_lines function the iteration occurs for each values within the array of points. The time key is checked for each point and not within the passed dictionary.

Case 2: UDP

UDP data also relies on make_lines and the same iteration occurs for points array where time is checked for each value of the array and not the dict.

This implies that time should be part each data point.

shantanoo-desai pushed a commit to shantanoo-desai/influxdb-python that referenced this issue Apr 8, 2020
- `time` key should be within each datapoint

- This PR addresses influxdata#788 regarding the structure of the data when
inserting via UDP.
- The original documentation contributed by me took the structure of
the `tutorial.py` as base. However, upon testing, the timestamp in the
example are not written (2020 is written as opposed to 2009).

- Tested for `influxdb-python` v5.2.3 and InfluxDB v1.6.1
sebito91 pushed a commit that referenced this issue Apr 10, 2020
- `time` key should be within each datapoint

- This PR addresses #788 regarding the structure of the data when
inserting via UDP.
- The original documentation contributed by me took the structure of
the `tutorial.py` as base. However, upon testing, the timestamp in the
example are not written (2020 is written as opposed to 2009).

- Tested for `influxdb-python` v5.2.3 and InfluxDB v1.6.1
ocworld pushed a commit to AhnLab-OSS/influxdb-python that referenced this issue Apr 13, 2020
- `time` key should be within each datapoint

- This PR addresses influxdata#788 regarding the structure of the data when
inserting via UDP.
- The original documentation contributed by me took the structure of
the `tutorial.py` as base. However, upon testing, the timestamp in the
example are not written (2020 is written as opposed to 2009).

- Tested for `influxdb-python` v5.2.3 and InfluxDB v1.6.1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant