Skip to content

Commit ea771e0

Browse files
committed
Add support for --web.route-prefix
Fixes #636
1 parent 2f7d565 commit ea771e0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd/promxy/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type cliOpts struct {
9090
ProxyHeaders []string `long:"proxy-headers" env:"PROXY_HEADERS" description:"a list of headers to proxy to downstream servergroups."`
9191

9292
ExternalURL string `long:"web.external-url" description:"The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically."`
93+
RoutePrefix string `long:"web.route-prefix" description:"Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url."`
9394
EnableLifecycle bool `long:"web.enable-lifecycle" description:"Enable shutdown and reload via HTTP request."`
9495

9596
QueryTimeout time.Duration `long:"query.timeout" description:"Maximum time a query may take before being aborted." default:"2m"`
@@ -389,7 +390,7 @@ func main() {
389390
EnableLifecycle: opts.EnableLifecycle,
390391

391392
Flags: opts.ToFlags(),
392-
RoutePrefix: "/",
393+
RoutePrefix: opts.RoutePrefix,
393394
ExternalURL: externalUrl,
394395
Version: &web.PrometheusVersion{
395396
Version: version.Version,
@@ -406,9 +407,12 @@ func main() {
406407
logrus.Fatalf("Error parsing CORS regex: %v", err)
407408
}
408409

409-
if externalUrl != nil && externalUrl.Path != "" {
410+
// Default -web.route-prefix to path of -web.external-url.
411+
if webOptions.RoutePrefix == "" {
410412
webOptions.RoutePrefix = externalUrl.Path
411413
}
414+
// RoutePrefix must always be at least '/'.
415+
webOptions.RoutePrefix = "/" + strings.Trim(webOptions.RoutePrefix, "/")
412416

413417
webHandler := web.New(logger, webOptions)
414418
reloadables = append(reloadables, proxyconfig.WrapPromReloadable(webHandler))

0 commit comments

Comments
 (0)