Skip to content

feat: add v3 native write endpoint support#48

Open
philjb wants to merge 1 commit intomasterfrom
pjb/46/v3-write-endpoint
Open

feat: add v3 native write endpoint support#48
philjb wants to merge 1 commit intomasterfrom
pjb/46/v3-write-endpoint

Conversation

@philjb
Copy link
Contributor

@philjb philjb commented Feb 12, 2026

Adds options to use the v3 native write endpoint for advanced control of write behavior such as the no-sync and accept-partial options. Updates token and auth handling to support v3 alongside v2.

Adds options to use the v3 native write endpoint for advanced control
of write behavior such as the no-sync and accept-partial options.
Updates token and auth handling to support v3 alongside v2.

* closes #46
Copy link

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

Adds support for InfluxDB v3’s native /api/v3/write_lp endpoint so users can control v3-specific write semantics (e.g., no_sync, accept_partial) while keeping token/auth handling compatible with existing v2 behavior.

Changes:

  • Add v3 configuration flags (V3, V3NoSync, V3AcceptPartial) and surface them in CLI parsing.
  • Update auth/token handling to apply to both v2 and v3 modes.
  • Route writes to the v3 native write endpoint when -v3 is enabled.

Reviewed changes

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

File Description
inch.go Adds v3 options, updates token handling, and switches write URL to v3 native endpoint when enabled.
cmd/inch/main.go Exposes v3 flags and updates token flag description for v2/v3 usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +235 to 236
fmt.Println("ERROR: Need to provide a token in order to write into InfluxDB 2 or 3")
return err
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

In the missing-token case, this returns err from Validate(), which is nil here, so Run() exits successfully (exit code 0) even though an error was printed. Return a real error (and consider writing the message to Stderr) so callers can detect the failure.

Suggested change
fmt.Println("ERROR: Need to provide a token in order to write into InfluxDB 2 or 3")
return err
fmt.Fprintln(os.Stderr, "ERROR: Need to provide a token in order to write into InfluxDB 2 or 3")
return errors.New("need to provide a token in order to write into InfluxDB 2 or 3")

Copilot uses AI. Check for mistakes.
fmt.Fprintf(s.Stdout, "Write Consistency: %s\n", s.Consistency)
fmt.Fprintf(s.Stdout, "Writing into InfluxDB 2.0: %t\n", s.V2)
fmt.Fprintf(s.Stdout, "InfluxDB 2.0 Authorization Token: %s\n", s.Token)
fmt.Fprintf(s.Stdout, "InfluxDB 2 or 3 Authorization Token: %s\n", s.Token)
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

This prints the full authorization token to stdout, which is likely to end up in CI logs / shell history and leak credentials. Consider printing only whether a token is set (or a redacted form) and/or gating token output behind -v.

Suggested change
fmt.Fprintf(s.Stdout, "InfluxDB 2 or 3 Authorization Token: %s\n", s.Token)
if s.Token == "" {
fmt.Fprintf(s.Stdout, "InfluxDB 2 or 3 Authorization Token: (not set)\n")
} else {
fmt.Fprintf(s.Stdout, "InfluxDB 2 or 3 Authorization Token: (set, length %d)\n", len(s.Token))
}

Copilot uses AI. Check for mistakes.
@@ -183,6 +186,10 @@ func (s *Simulator) Validate() error {
el = append(el, fmt.Errorf("invalid precision: %s", s.Precision))
}

Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Validate() doesn’t currently enforce any constraints around the new v3 flags beyond a warning. Consider making these cases hard errors: (1) -v2 and -v3 both set (ambiguous behavior), and (2) -v3 set with an empty Database (required for /api/v3/write_lp). This will fail fast instead of producing confusing runtime errors.

Suggested change
// Enforce mutually exclusive v2/v3 modes.
if s.V2 && s.V3 {
el = append(el, errors.New("invalid configuration: cannot enable both v2 and v3 write endpoints; please select exactly one"))
}
// Enforce required database when using the v3 write endpoint.
if s.V3 && strings.TrimSpace(s.Database) == "" {
el = append(el, errors.New("invalid configuration: database must be set when using the v3 write endpoint"))
}

Copilot uses AI. Check for mistakes.
Comment on lines +758 to +760
if s.V3 {
url = fmt.Sprintf("%s/api/v3/write_lp?db=%s&precision=%s&no_sync=%v&accept_partial=%v", s.Host, s.Database, s.Precision, s.V3NoSync, s.V3AcceptPartial)
} else if s.RetentionPolicy == "" {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The v3 write URL is built via string formatting without URL-escaping query parameter values. If Database/Precision contain characters that need escaping, the request can be malformed. Use net/url to build the URL + query (and reuse it for the non-v3 branches for consistency).

Copilot uses AI. Check for mistakes.
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.

update inch to support influxdb v3 core and enterprise "native" write endpoint

1 participant