Skip to content

fix: send correct time unit when writing Points#384

Open
NguyenHoangSon96 wants to merge 1 commit into
mainfrom
fix/incorrect-write-timestamp1
Open

fix: send correct time unit when writing Points#384
NguyenHoangSon96 wants to merge 1 commit into
mainfrom
fix/incorrect-write-timestamp1

Conversation

@NguyenHoangSon96
Copy link
Copy Markdown
Contributor

@NguyenHoangSon96 NguyenHoangSon96 commented May 11, 2026

Closes #382

Proposed Changes

  • When writing Points, precision in query parameters always set to nanosecond because time in Points always converted into nanoseconds by default.
  • Update test cases to respect the new changes above.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@NguyenHoangSon96 NguyenHoangSon96 self-assigned this May 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.25%. Comparing base (656e99e) to head (e180f32).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
+ Coverage   88.19%   88.25%   +0.05%     
==========================================
  Files          21       21              
  Lines        1525     1532       +7     
  Branches      275      277       +2     
==========================================
+ Hits         1345     1352       +7     
  Misses         82       82              
  Partials       98       98              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=nanosecond in write query parameters when writing Point instances.
  • Update unit tests to expect precision=nanosecond for Point writes 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 thread src/test/java/com/influxdb/v3/client/InfluxDBClientWriteTest.java Outdated
Comment thread src/test/java/com/influxdb/v3/client/InfluxDBClientWriteTest.java Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.

Comment thread src/main/java/com/influxdb/v3/client/internal/InfluxDBClientImpl.java Outdated
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java Outdated
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Comment thread src/main/java/com/influxdb/v3/client/config/ClientConfig.java Outdated
Comment thread src/main/java/com/influxdb/v3/client/config/ClientConfig.java Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/test/java/com/influxdb/v3/client/integration/E2ETest.java
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread src/test/java/com/influxdb/v3/client/integration/E2ETest.java
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/test/java/com/influxdb/v3/client/integration/E2ETest.java
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment thread src/test/java/com/influxdb/v3/client/integration/E2ETest.java
Comment thread src/test/java/com/influxdb/v3/client/integration/E2ETest.java
Comment thread src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Comment thread src/main/java/com/influxdb/v3/client/config/ClientConfig.java
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/main/java/com/influxdb/v3/client/internal/InfluxDBClientImpl.java:34

  • Unused import java.util.function.Predicate is introduced but not used anywhere in this class. This will fail the repository's Checkstyle UnusedImports rule; please remove it.
import java.util.logging.Logger;

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/test/java/com/influxdb/v3/client/InfluxDBClientWriteTest.java
@NguyenHoangSon96 NguyenHoangSon96 force-pushed the fix/incorrect-write-timestamp1 branch from 3a68973 to 434f7a9 Compare May 12, 2026 05:01
@NguyenHoangSon96 NguyenHoangSon96 force-pushed the fix/incorrect-write-timestamp1 branch from d0d491b to e180f32 Compare May 12, 2026 05:06
Copy link
Copy Markdown
Contributor

@alespour alespour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should tweak javadoc for precision args just a tiny bit, Copilot finding makes sense. And cover the logic more by unit test in addition to e2e test.


checkWriteCalled("/api/v3/write_lp", "DB", expectedPrecision, true, "true", null, true);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should improve coverage of fixed logic by unit tests.

Suggested change
@ParameterizedTest(name = "{0}")
@MethodSource("pointPrecisionIgnoredCases")
void pointWritesIgnoreWriteOptionsPrecision(
String name,
WritePrecision configuredPrecision,
boolean manyPoints) throws Exception {
mockServer.enqueue(createResponse(200));
ClientConfig cfg = new ClientConfig.Builder()
.host(baseURL)
.token("TOKEN".toCharArray())
.database("DB")
.build();
try (InfluxDBClient client = InfluxDBClient.getInstance(cfg)) {
Point point = new Point("mem");
point.setTag("tag", "one");
point.setField("value", 1.0);
WriteOptions options = new WriteOptions.Builder()
.precision(configuredPrecision)
.build();
if (manyPoints) {
client.writePoints(List.of(point), options);
} else {
client.writePoint(point, options);
}
}
checkWriteCalled("/api/v3/write_lp", "DB", "nanosecond", true, null, null, false);
}
private static Stream<Arguments> pointPrecisionIgnoredCases() {
return Stream.of(
Arguments.of("writePoint precision=S", WritePrecision.S, false),
Arguments.of("writePoint precision=MS", WritePrecision.MS, false),
Arguments.of("writePoints precision=S", WritePrecision.S, true),
Arguments.of("writePoints precision=US", WritePrecision.US, true)
);
}

* <li><code>organization</code> - organization to be used for operations</li>
* <li><code>database</code> - database to be used for InfluxDB operations</li>
* <li><code>writePrecision</code> - precision to use when writing points to InfluxDB</li>
* <li><code>writePrecision</code> - precision to use when writing points to InfluxDB.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove a word to avoid a bit confusing contradiction with the sentence that follows after it.

Suggested change
* <li><code>writePrecision</code> - precision to use when writing points to InfluxDB.
* <li><code>writePrecision</code> - precision to use when writing to InfluxDB.

@@ -548,7 +551,10 @@ public Builder database(@Nullable final String database) {
* if no precision is specified in the write API call.
*
* @param writePrecision default precision to use for the timestamp of points
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove a word to avoid a bit confusing contradiction with the sentence that follows after it.

Suggested change
* @param writePrecision default precision to use for the timestamp of points
* @param writePrecision default precision to use for the timestamp

@@ -140,6 +145,9 @@ public WriteOptions(@Nullable final String database,
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove a word to avoid a bit confusing contradiction with the sentence that follows after it.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

@@ -158,6 +166,9 @@ public WriteOptions(@Nullable final String database,
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

@@ -187,6 +198,9 @@ public WriteOptions(@Nullable final Map<String, String> headers) {
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

@@ -209,6 +223,9 @@ public WriteOptions(@Nullable final String database,
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

@@ -234,6 +251,9 @@ public WriteOptions(@Nullable final String database,
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

@@ -265,6 +285,9 @@ public WriteOptions(@Nullable final String database,
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

@@ -307,6 +330,9 @@ public WriteOptions(@Nullable final String database,
* If it is not specified then use {@link ClientConfig#getDatabase()}.
* @param precision The precision to use for the timestamp of points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param precision The precision to use for the timestamp of points.
* @param precision The precision to use for the timestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Precision not respected when sending LP

4 participants