From cd5534c35a7755b3eef54b74ac3c8c797bdca880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Wed, 10 Nov 2021 15:16:19 +0200 Subject: [PATCH] query: pass queryURL along to the UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass `queryURL` to the UI to have proper URLs in the React UI. Without this, all URLs are set to `http://localhost:10902` i.e. the default value set in `config.ts`. Signed-off-by: Giedrius Statkevičius --- CHANGELOG.md | 1 + cmd/thanos/query.go | 13 ++++++++++++- pkg/ui/query.go | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7dacbd3164..16365cad594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#4576](https://github.com/thanos-io/thanos/pull/4576) UI: add filter compaction level to the Block UI. - [#4731](https://github.com/thanos-io/thanos/pull/4731) Rule: add stateless mode to ruler according to https://thanos.io/tip/proposals-accepted/202005-scalable-rule-storage.md/. Continue https://github.com/thanos-io/thanos/pull/4250. - [#4612](https://github.com/thanos-io/thanos/pull/4612) Sidecar: add `--prometheus.http-client` and `--prometheus.http-client-file` flag for sidecar to connect Prometheus with basic auth or TLS. +- [#4847](https://github.com/thanos-io/thanos/pull/4847) Query: add `--alert.query-url` which is used in the user interface for rules/alerts pages. By default the HTTP listen address is used for this URL. ### Fixed diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 7a4a54f5052..87eab104bde 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -167,6 +167,8 @@ func registerQuery(app *extkingpin.App) { storeResponseTimeout := extkingpin.ModelDuration(cmd.Flag("store.response-timeout", "If a Store doesn't send any data in this specified duration then a Store will be ignored and partial data will be returned if it's enabled. 0 disables timeout.").Default("0ms")) reqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd) + alertQueryURL := cmd.Flag("alert.query-url", "The external Thanos Query URL that would be set in all alerts 'Source' field").String() + cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ <-chan struct{}, _ bool) error { selectorLset, err := parseFlagLabels(*selectorLabels) if err != nil { @@ -289,6 +291,7 @@ func registerQuery(app *extkingpin.App) { *webDisableCORS, enableAtModifier, enableNegativeOffset, + *alertQueryURL, component.Query, ) }) @@ -355,8 +358,16 @@ func runQuery( disableCORS bool, enableAtModifier bool, enableNegativeOffset bool, + alertQueryURL string, comp component.Component, ) error { + if alertQueryURL == "" { + lastColon := strings.LastIndex(httpBindAddr, ":") + if lastColon != -1 { + alertQueryURL = fmt.Sprintf("http://localhost:%s", httpBindAddr[lastColon+1:]) + } + // NOTE(GiedriusS): default is set in config.ts. + } // TODO(bplotka in PR #513 review): Move arguments into struct. duplicatedStores := promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "thanos_query_duplicated_store_addresses_total", @@ -587,7 +598,7 @@ func runQuery( ins := extpromhttp.NewInstrumentationMiddleware(reg, nil) // TODO(bplotka in PR #513 review): pass all flags, not only the flags needed by prefix rewriting. - ui.NewQueryUI(logger, endpoints, webExternalPrefix, webPrefixHeaderName).Register(router, ins) + ui.NewQueryUI(logger, endpoints, webExternalPrefix, webPrefixHeaderName, alertQueryURL).Register(router, ins) api := v1.NewQueryAPI( logger, diff --git a/pkg/ui/query.go b/pkg/ui/query.go index 1778dc55571..84187e3ae62 100644 --- a/pkg/ui/query.go +++ b/pkg/ui/query.go @@ -32,9 +32,10 @@ type Query struct { now func() model.Time } -func NewQueryUI(logger log.Logger, endpointSet *query.EndpointSet, externalPrefix, prefixHeader string) *Query { +func NewQueryUI(logger log.Logger, endpointSet *query.EndpointSet, externalPrefix, prefixHeader, alertQueryURL string) *Query { tmplVariables := map[string]string{ "Component": component.Query.String(), + "queryURL": alertQueryURL, } runtimeInfo := api.GetRuntimeInfoFunc(logger)