fix: send correct time unit when writing Points#384
Open
NguyenHoangSon96 wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #384 +/- ##
==========================================
+ Coverage 88.19% 88.21% +0.01%
==========================================
Files 21 21
Lines 1525 1527 +2
Branches 275 276 +1
==========================================
+ Hits 1345 1347 +2
Misses 82 82
Partials 98 98 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses a write precision mismatch when writing Point objects to InfluxDB v3: the line protocol payload is serialized with nanosecond timestamps, so the request’s precision query parameter must match to avoid server-side “timestamp out of range for precision” errors (issue #382).
Changes:
- Force
precision=nanosecondin write query parameters when writingPointinstances. - Update unit tests to expect
precision=nanosecondforPointwrites even when client config sets another precision. - Add an end-to-end integration test covering writing points with timestamps provided in different input units.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/main/java/com/influxdb/v3/client/internal/InfluxDBClientImpl.java | Changes precision selection logic for write requests when writing Points. |
| src/test/java/com/influxdb/v3/client/InfluxDBClientWriteTest.java | Updates expected precision in write request assertions for point writes. |
| src/test/java/com/influxdb/v3/client/integration/E2ETest.java | Adds an integration test that writes multiple points with mixed timestamp input units. |
| CHANGELOG.md | Documents the bug fix in the unreleased section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+307
to
+314
| WritePrecision precision; | ||
|
|
||
| if (data.stream().anyMatch(Point.class::isInstance)) { | ||
| // When writing Point(s), the timestamp is always converted to nanoseconds. | ||
| precision = WritePrecision.NS; | ||
| } else { | ||
| precision = options.precisionSafe(config); | ||
| } |
e58adf7 to
7cebe1b
Compare
Comment on lines
+307
to
+313
| WritePrecision precision; | ||
|
|
||
| if (data.stream().anyMatch(Point.class::isInstance)) { | ||
| // When writing Point(s), the timestamp is always converted to nanoseconds. | ||
| precision = WritePrecision.NS; | ||
| } else { | ||
| precision = options.precisionSafe(config); |
Comment on lines
+600
to
+603
| @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") | ||
| @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") | ||
| @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") | ||
| @Test |
Comment on lines
+612
to
+627
| List<Point> points = List.of( | ||
| Point.measurement(measurement) | ||
| .setTag("type", "test") | ||
| .setFloatField("rads", 3.14) | ||
| .setIntegerField("life", 42) | ||
| .setTimestamp(Instant.now().toEpochMilli(), WritePrecision.MS), | ||
| Point.measurement(measurement) | ||
| .setTag("type", "test") | ||
| .setFloatField("rads", 3.14) | ||
| .setIntegerField("life", 12) | ||
| .setTimestamp(Instant.now().plusSeconds(1).toEpochMilli() / 1000, WritePrecision.S), | ||
| Point.measurement(measurement) | ||
| .setTag("type", "test") | ||
| .setFloatField("rads", 3.14) | ||
| .setIntegerField("life", 432) | ||
| .setTimestamp(Instant.now().plusSeconds(2).toEpochMilli() * 1000, WritePrecision.US) |
Comment on lines
124
to
+131
| * | ||
| * @param database The database to be used for InfluxDB operations. | ||
| * If it is not specified then use {@link ClientConfig#getDatabase()}. | ||
| * @param precision The precision to use for the timestamp of points. | ||
| * If it is not specified then use {@link ClientConfig#getWritePrecision()}. | ||
| * This setting is ignored when writing {@link com.influxdb.v3.client.Point}; | ||
| * for those writes, the client always sends {@link WritePrecision#NS} | ||
| * precision to the server. |
Comment on lines
548
to
+557
|
|
||
| /** | ||
| * Sets the default precision to use for the timestamp of points | ||
| * if no precision is specified in the write API call. | ||
| * | ||
| * @param writePrecision default precision to use for the timestamp of points | ||
| * if no precision is specified in the write API call | ||
| * if no precision is specified in the write API call. | ||
| * This setting is ignored when writing {@link com.influxdb.v3.client.Point}; | ||
| * for those writes, the client always sends {@link WritePrecision#NS} | ||
| * precision to the server. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #382
Proposed Changes
precisionin query parameters always set tonanosecondbecause time in Points always converted intonanosecondsby default.Checklist