influxdb-client-go icon indicating copy to clipboard operation
influxdb-client-go copied to clipboard

Automatically set time on WritePoint

Open shreyas44 opened this issue 3 years ago • 5 comments

Proposal: Automatically set the time to the current time in write.Point if the time hasn't already been set when a call to writeAPI.WritePoint is made

Current behavior: The time is assumed to be zero and writes to influxdb silently fail when SetTime isn't used

Desired behavior: Automatically set the time to the current time in write.Point if the time hasn't already been set

Alternatives considered:

  • NewPoint or NewPointWithMeasurement could automatically set the time to the current time

Use case: Make it a little less verbose to write points and stop failing silently

shreyas44 avatar Jul 14 '22 01:07 shreyas44

@shreyas44, thanks for using this client. When the timestamp is not set, a timestamp is not added to the line protocol, and the server assigns timestamps automatically. If you set the log level to Debug (3), the log will show what is exactly sent.

Why do you think write silently fails?

How are you checking data is written?

vlastahajek avatar Jul 14 '22 08:07 vlastahajek

When the timestamp is not set, a timestamp is not added to the line protocol, and the server assigns timestamps automatically.

Oh I see, didn't know that.

How are you checking data is written?

I write a bunch of points (~1000) to influxdb over a couple of seconds and count the number of results in the last few minutes using flux. The count is usually in single digits. Maybe if I don't check for points within a time period, I should see the expected 1000?

shreyas44 avatar Jul 14 '22 14:07 shreyas44

When you write a batch of points without timestamp and several points have the same tags, it can happen that the server will assign the same timestamp because the highest resolution is nanoseconds. It can lead to overwriting of points. Try assigning different timestamps.

vlastahajek avatar Jul 17 '22 08:07 vlastahajek

When you write a batch of points without timestamp and several points have the same tags, it can happen that the server will assign the same timestamp because the highest resolution is nanoseconds. It can lead to overwriting of points.

You might be right. This issue doesn't pop up when writing each point synchronously without explicitly setting the time.

shreyas44 avatar Jul 28 '22 09:07 shreyas44

I still think it'd be a good idea to automatically set the time to the current time in write.Point if the time hasn't already been set when a call to writeAPI.WritePoint is made. It seems like a better default than the current behaviour which can yield unexpected results.

shreyas44 avatar Jul 28 '22 09:07 shreyas44