feat: support partial writes#269
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds partial-write support to the C# client (including structured per-line error details) and finalizes write routing behavior between InfluxDB’s V2 and V3 write endpoints for product compatibility.
Changes:
- Introduces
InfluxDBPartialWriteExceptionand JSON error parsing to surface v3 partial-write line errors. - Adds write routing/behavior controls via
WriteOptions(UseV2Api,AcceptPartial,NoSync) plus connection string/env var configuration. - Updates tests and docs to reflect default V2 routing and explicit V3 option behavior.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents partial writes and explains default V2 routing + configuration surfaces. |
| Client/Internal/RestClient.cs | Parses JSON error bodies; throws InfluxDBPartialWriteException with structured line errors on v3 partial-write responses. |
| Client/InfluxDBPartialWriteException.cs | Adds new exception type carrying per-line partial-write error details. |
| Client/InfluxDBClient.cs | Routes writes to /api/v2/write by default and applies v3-only query params (no_sync, accept_partial) when using v3. |
| Client/Config/WriteOptions.cs | Adds AcceptPartial/UseV2Api options and validates NoSync usage. |
| Client/Config/ClientConfig.cs | Adds connection string/env parsing for writeAcceptPartial and writeUseV2Api. |
| Client/Client.csproj | Adds System.Text.Json dependency for JSON parsing. |
| Client.Test/Internal/RestClientTest.cs | Adds/updates tests for partial-write error parsing and typed/untyped fallback behavior. |
| Client.Test/InfluxDBClientWriteTest.cs | Updates tests for default V2 routing, explicit V3 routing, and option validation/guidance messages. |
| Client.Test/InfluxDBClientHttpsTest.cs | Formatting-only change. |
| Client.Test/InfluxDBApiExceptionTest.cs | Formatting-only change. |
| Client.Test/Config/ClientConfigTest.cs | Extends tests to cover new connection string/env write options. |
| Client.Test.Integration/WriteTest.cs | Refactors exception check using pattern matching. |
| CHANGELOG.md | Adds unreleased feature entry for partial writes + default V2 routing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 15 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
Client/InfluxDBClient.cs:848
- This guidance error message starts with a lowercase "server" while other user-facing exceptions in the client are capitalized (e.g., "Cannot write..."). Consider capitalizing this message for consistency.
throw new InfluxDBApiException(
$"server doesn't support the V3 API endpoint (/api/v3/write_lp) " +
$"(set UseV2Api=true; write options: {{UseV2Api:false,NoSync:{writeOptions.NoSync.ToString().ToLowerInvariant()},AcceptPartial:{writeOptions.AcceptPartial.ToString().ToLowerInvariant()}}})",
ex.HttpResponseMessage!);
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Ad hoc implementation exercising new instructions in README.md works as described.
Tests pass locally.
Changes make sense.
Looks good to me. 🚴 🏁
Ad hoc checks
WriteOptions in ClientConfig passed to constructor
- Default client settings
- No partials in sample batch - OK
- Partials in sample batch (2 Partial records) -> ApiException and batch rejected - OK
useV2Api = false- OK- Partials in sample batch (2 Partial records) - OK
- Partial lines discarded - OK
- Valid lines written - OK
- PartialWriteException thrown - OK
- Exception contains invalid lines - OK
- Partials in sample batch (2 Partial records) - OK
useV2Api = falseandAcceptPartial = false- Partials in sample batch (2 Partial records)
- Full batch discarded - OK
- PartialWriteException thrown - OK
- Exception contains first partial line encountered - OK
- Partials in sample batch (2 Partial records)
useV2Api = falseandAcceptPartial = falseandNoSync = true- Partials in sample batch (2 partial records)
- Partial lines discarded - OK
- Valid linews written - OK
- PartialWriteException thrown - OK
- Exception contains invalid lines - OK
- Partials in sample batch (2 partial records)
useV2Api = trueandNoSync = trueSystem.InvalidOperationException : Invalid write options: NoSync requires UseV2Api=false- OK
WriteOptions in write method call
Note WriteOptions currently cannot be pased as an object to the client.Write... methods. See #281
Proposed Changes
This PR adds partial-write support in the C# client and finalizes write API selection behavior for product compatibility.
Feature highlights:
InfluxDBPartialWriteExceptionwith per-line details:LineNumberErrorMessageOriginalLineAcceptPartialdefaults totrue(server default behavior)accept_partial=falseis sent only when partial writes are explicitly disabledUseV2Apiroutes writes between:/api/v2/write/api/v3/write_lpDefault behavior and option semantics:
UseV2Api=true).NoSyncrequiresUseV2Api=falseand is rejected otherwise.AcceptPartialapplies only to V3 endpoint writes and is ignored on V2 endpoint writes.Configuration surfaces:
AcceptPartial,UseV2Api,NoSyncwriteAcceptPartial,writeUseV2Api,writeNoSyncINFLUX_WRITE_ACCEPT_PARTIAL,INFLUX_WRITE_USE_V2_API,INFLUX_WRITE_NO_SYNCSee Partial writes for reference.
Example (partial-write handling):
Example (enable V3 write options):
Checklist