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.21%. Comparing base (656e99e) to head (7cebe1b).

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.
📢 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 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);
}
Comment thread src/test/java/com/influxdb/v3/client/integration/E2ETest.java
@NguyenHoangSon96 NguyenHoangSon96 force-pushed the fix/incorrect-write-timestamp1 branch from e58adf7 to 7cebe1b Compare May 11, 2026 12:24
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 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.
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

2 participants