diff --git a/CHANGELOG.md b/CHANGELOG.md index a0556f5078..ab82e74d92 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. - [#4856](https://github.com/thanos-io/thanos/pull/4856) Mixin: Add Query Frontend Grafana dashboard. ### Fixed diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 7a4a54f505..3f632db52e 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/docs/components/query.md b/docs/components/query.md index ef3ca3e3ca..72d4308041 100644 --- a/docs/components/query.md +++ b/docs/components/query.md @@ -252,6 +252,9 @@ Query node exposing PromQL enabled Query API with data retrieved from multiple store nodes. Flags: + --alert.query-url=ALERT.QUERY-URL + The external Thanos Query URL that would be set + in all alerts 'Source' field. --enable-feature= ... Comma separated experimental feature names to enable.The current list of features is promql-negative-offset and promql-at-modifier. diff --git a/pkg/ui/query.go b/pkg/ui/query.go index 1778dc5557..84187e3ae6 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)