Conversation
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
There was a problem hiding this comment.
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
-v3is 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.
| fmt.Println("ERROR: Need to provide a token in order to write into InfluxDB 2 or 3") | ||
| return err |
There was a problem hiding this comment.
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.
| 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") |
| 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) |
There was a problem hiding this comment.
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.
| 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)) | |
| } |
| @@ -183,6 +186,10 @@ func (s *Simulator) Validate() error { | |||
| el = append(el, fmt.Errorf("invalid precision: %s", s.Precision)) | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
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.
| // 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")) | |
| } |
| 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 == "" { |
There was a problem hiding this comment.
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).
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.