Skip to content

promtool: add --api-path flag to push metrics command - #18381

Closed
VarshaUN wants to merge 3 commits into
prometheus:mainfrom
VarshaUN:api-path
Closed

VarshaUN wants to merge 3 commits into
prometheus:mainfrom
VarshaUN:api-path

Conversation

@VarshaUN

Copy link
Copy Markdown
Contributor

Which issue(s) does the PR fix:

Fixes #18358

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[ENHANCEMENT] promtool: Add --api-path flag to `push metrics` command to allow overriding the default remote write API path (/api/v1/write). This enables pushing metrics to endpoints that use a different path, such as Mimir's /api/v1/push.

Signed-off-by : Varsha U N [email protected]

@VarshaUN
VarshaUN requested review from a team and dgl as code owners March 27, 2026 04:40
@Baarsgaard

Copy link
Copy Markdown
Contributor

Before a more in-depth review and test, would you change the cli flag to --remote-write.api-path and fix the formatting errors?

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hello from the Bug Scrub!

This looks ok, just we some last suggestions and rebase.

Comment thread cmd/promtool/main.go Resolved
Comment thread docs/command-line/promtool.md Resolved
Allow users to override the default remote write API path (/api/v1/write)
when pushing metrics. This is needed for endpoints like Mimir that use
/api/v1/push instead.

Fixes prometheus#18358

Signed-off-by: Varsha U N <[email protected]>
@dgl

dgl commented May 22, 2026

Copy link
Copy Markdown
Member

@VarshaUN it looks like the promtool tests are failing now, could you take a look at that?

Signed-off-by: Varsha U N <[email protected]>
Signed-off-by: Varsha U N <[email protected]>
@VarshaUN

VarshaUN commented May 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@VarshaUN it looks like the promtool tests are failing now, could you take a look at that?

Hey now the tests have passed , can you review it , Thanks!

@krajorama

Copy link
Copy Markdown
Member

Hello from the bug scrub!

Asking @ldufr to take a look and also gentle ping for @bwplotka . Let me know if this is ready for merge.

Comment thread cmd/promtool/main.go
pushMetricsTimeout := pushMetricsCmd.Flag("timeout", "The time to wait for pushing metrics.").Default("30s").Duration()
pushMetricsHeaders := pushMetricsCmd.Flag("header", "Prometheus remote write header.").StringMap()
pushMetricsProtoMsg := pushMetricsCmd.Flag("protobuf_message", "Protobuf message to use when writing (prometheus.WriteRequest or io.prometheus.write.v2.Request).").Default("prometheus.WriteRequest").String()
pushMetricsAPIPath := pushMetricsCmd.Flag("remote-write.api-path", "Override the default remote write API path (/api/v1/write).").Default("").String()

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.

It was previously commented by @bwplotka, but it would be good to have the correct default here. It also ends up being generated and set in the documentation.

Comment thread cmd/promtool/metrics.go
Comment on lines +50 to +52
if apiPath != "" {
apiOpts = append(apiOpts, remoteapi.WithAPIPath(apiPath))
}

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.

With the correct default set in the command line parameter, we should be safe to always call remoteapi.WithAPIPath and with that we can simplify the code here a bit.

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.

promtool: push metrics <url> always suffixes the path in the url with /api/v1/write

6 participants