influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
724 stars 187 forks source link

Discrepancies between measurement values for batched and synchronous api #629

Closed tc360950 closed 10 months ago

tc360950 commented 10 months ago

Specifications

Code sample to reproduce problem

Batch version:

from influxdb_client.client.influxdb_client import InfluxDBClient
from influxdb_client.client.write.point import Point
from influxdb_client.client.write_api import WriteOptions

INFLUX_DB_TOKEN: str = ""
INFLUX_DB_ORG: str = ""
INFLUX_DB_URL: str = ""
INFLUX_DB_BUCKET: str = ""

client = InfluxDBClient(
    url=INFLUX_DB_URL, token=INFLUX_DB_TOKEN, org=INFLUX_DB_ORG
).write_api(
    write_options=WriteOptions(batch_size=1000, flush_interval=1000),
)

for i in range(0, 10000):
    point = Point("test_metric").field("test_metric", 1)
    client.write(bucket=INFLUX_DB_BUCKET, org=INFLUX_DB_ORG, record=point)

client.close()

Synchronous version:

from influxdb_client.client.influxdb_client import InfluxDBClient
from influxdb_client.client.write.point import Point
from influxdb_client.client.write_api import SYNCHRONOUS

INFLUX_DB_TOKEN: str = ""
INFLUX_DB_ORG: str = ""
INFLUX_DB_URL: str = ""
INFLUX_DB_BUCKET: str = ""

client = InfluxDBClient(
    url=INFLUX_DB_URL, token=INFLUX_DB_TOKEN, org=INFLUX_DB_ORG
).write_api(write_options=SYNCHRONOUS)

for i in range(0, 10000):
    point = Point("test_metric").field("test_metric", 1)
    client.write(bucket=INFLUX_DB_BUCKET, org=INFLUX_DB_ORG, record=point)

client.close()

Expected behavior

After executing one of the scripts, total sum of field 'test_metric' should be equal to 10_000.

Actual behavior

After executing batched script total sum of field 'test_metric' is equal to 10, whilst synchronous API results in correct value of 10_000.

Additional info

No response

bednar commented 10 months ago

Hi @tc360950,

Thank you for using our client. To ensure that you have 10,000 unique points, each data point must have a unique timestamp. For more information, please refer to:

InfluxDB v2: Data Elements - Point Best regards