From ac6b24fb219ae66f27d80b75693ac008a7494d88 Mon Sep 17 00:00:00 2001 From: Hitanshu Mehta Date: Tue, 16 Nov 2021 12:34:28 +0530 Subject: [PATCH 1/3] add `--endpoint-strict` flag to add statically configured endpoints Signed-off-by: Hitanshu Mehta --- cmd/thanos/query.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 3f632db52e..22cfa83aa9 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -121,9 +121,12 @@ func registerQuery(app *extkingpin.App) { targetEndpoints := cmd.Flag("target", "Deprecation Warning - This flag is deprecated and replaced with `endpoint`. Experimental: Addresses of statically configured target API servers (repeatable). The scheme may be prefixed with 'dns+' or 'dnssrv+' to detect target API servers through respective DNS lookups."). Hidden().PlaceHolder("").Strings() - strictStores := cmd.Flag("store-strict", "Addresses of only statically configured store API servers that are always used, even if the health check fails. Useful if you have a caching layer on top."). + strictStores := cmd.Flag("store-strict", "Deprecation Warning - This flag is deprecated and replaced with `endpoint-strict`. Addresses of only statically configured store API servers that are always used, even if the health check fails. Useful if you have a caching layer on top."). PlaceHolder("").Strings() + strictEndpoints := cmd.Flag("endpoint-strict", "Addresses of only statically configured Thanos API servers that are always used, even if the health check fails. Useful if you have a caching layer on top."). + PlaceHolder("").Strings() + fileSDFiles := cmd.Flag("store.sd-files", "Path to files that contain addresses of store API servers. The path can be a glob pattern (repeatable)."). PlaceHolder("").Strings() @@ -288,6 +291,7 @@ func registerQuery(app *extkingpin.App) { time.Duration(*instantDefaultMaxSourceResolution), *defaultMetadataTimeRange, *strictStores, + *strictEndpoints, *webDisableCORS, enableAtModifier, enableNegativeOffset, @@ -355,6 +359,7 @@ func runQuery( instantDefaultMaxSourceResolution time.Duration, defaultMetadataTimeRange time.Duration, strictStores []string, + strictEndpoints []string, disableCORS bool, enableAtModifier bool, enableNegativeOffset bool, @@ -398,6 +403,12 @@ func runQuery( dns.ResolverType(dnsSDResolver), ) + for _, endpoint := range strictEndpoints { + if dns.IsDynamicNode(endpoint) { + return errors.Errorf("%s is a dynamically specified endpoint i.e. it uses SD and that is not permitted under strict mode. Use --endpoint for this", endpoint) + } + } + dnsRuleProvider := dns.NewProvider( logger, extprom.WrapRegistererWithPrefix("thanos_query_rule_apis_", reg), @@ -432,6 +443,10 @@ func runQuery( specs = append(specs, query.NewGRPCEndpointSpec(addr, true)) } + for _, addr := range strictEndpoints { + specs = append(specs, query.NewGRPCEndpointSpec(addr, true)) + } + for _, dnsProvider := range []*dns.Provider{ dnsStoreProvider, dnsRuleProvider, From ca6bbac0f66de351b600b8b98fbf2fdc89ce82c8 Mon Sep 17 00:00:00 2001 From: Hitanshu Mehta Date: Tue, 16 Nov 2021 19:00:48 +0530 Subject: [PATCH 2/3] make docs Signed-off-by: Hitanshu Mehta --- docs/components/query.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/components/query.md b/docs/components/query.md index 72d4308041..cbef1938d6 100644 --- a/docs/components/query.md +++ b/docs/components/query.md @@ -263,6 +263,11 @@ Flags: prefixed with 'dns+' or 'dnssrv+' to detect Thanos API servers through respective DNS lookups. + --endpoint-strict= ... + Addresses of only statically configured Thanos + API servers that are always used, even if the + health check fails. Useful if you have a + caching layer on top. --grpc-address="0.0.0.0:10901" Listen ip:port address for gRPC endpoints (StoreAPI). Make sure this address is routable @@ -382,10 +387,12 @@ Flags: 'dns+' or 'dnssrv+' to detect store API servers through respective DNS lookups. --store-strict= ... - Addresses of only statically configured store - API servers that are always used, even if the - health check fails. Useful if you have a - caching layer on top. + Deprecation Warning - This flag is deprecated + and replaced with `endpoint-strict`. Addresses + of only statically configured store API servers + that are always used, even if the health check + fails. Useful if you have a caching layer on + top. --store.response-timeout=0ms If a Store doesn't send any data in this specified duration then a Store will be ignored From 7815fc5169bde209d3835265419fdaa1070b168e Mon Sep 17 00:00:00 2001 From: Hitanshu Mehta Date: Tue, 16 Nov 2021 21:25:01 +0530 Subject: [PATCH 3/3] Add CHANGELOG entry and fix nit Signed-off-by: Hitanshu Mehta --- CHANGELOG.md | 1 + cmd/thanos/query.go | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64b877fb02..a45cc6df00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#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. +- [#4874](https://github.com/thanos-io/thanos/pull/4874) Query: Add `--endpoint-strict` flag to statically configure Thanos API server endpoints. It is similar to `--store-strict` but supports passing any Thanos gRPC APIs: StoreAPI, MetadataAPI, RulesAPI, TargetsAPI and ExemplarsAPI. ### Fixed diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 22cfa83aa9..a12382c3df 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -397,18 +397,18 @@ func runQuery( } } - dnsEndpointProvider := dns.NewProvider( - logger, - extprom.WrapRegistererWithPrefix("thanos_query_endpoints_", reg), - dns.ResolverType(dnsSDResolver), - ) - for _, endpoint := range strictEndpoints { if dns.IsDynamicNode(endpoint) { return errors.Errorf("%s is a dynamically specified endpoint i.e. it uses SD and that is not permitted under strict mode. Use --endpoint for this", endpoint) } } + dnsEndpointProvider := dns.NewProvider( + logger, + extprom.WrapRegistererWithPrefix("thanos_query_endpoints_", reg), + dns.ResolverType(dnsSDResolver), + ) + dnsRuleProvider := dns.NewProvider( logger, extprom.WrapRegistererWithPrefix("thanos_query_rule_apis_", reg),