From e188aba7e6bd533b2382a23acf7e642ce61ddfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Tue, 30 Aug 2022 19:36:21 +0300 Subject: [PATCH] query: add --grpc-compression for enabling compression (#5654) Signed-off-by: Prakul Jain --- CHANGELOG.md | 1 + cmd/thanos/query.go | 9 +++++++++ docs/components/query.md | 2 ++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 655ee73571..fd8388605b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#5655](https://github.com/thanos-io/thanos/pull/5655) Receive: Fix recreating already pruned tenants. ### Added +* [#5654](https://github.com/thanos-io/thanos/pull/5654) Query: add `--grpc-compression` flag that controls the compression used in gRPC client. With the flag it is now possible to compress the traffic between Query and StoreAPI nodes - you get lower network usage in exchange for a bit higher CPU/RAM usage. ### Changed diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 1820381064..64e9e64bcc 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -25,6 +25,7 @@ import ( "github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" + "google.golang.org/grpc" apiv1 "github.com/thanos-io/thanos/pkg/api/query" "github.com/thanos-io/thanos/pkg/compact/downsample" @@ -33,6 +34,7 @@ import ( "github.com/thanos-io/thanos/pkg/discovery/dns" "github.com/thanos-io/thanos/pkg/exemplars" "github.com/thanos-io/thanos/pkg/extgrpc" + "github.com/thanos-io/thanos/pkg/extgrpc/snappy" "github.com/thanos-io/thanos/pkg/extkingpin" "github.com/thanos-io/thanos/pkg/extprom" extpromhttp "github.com/thanos-io/thanos/pkg/extprom/http" @@ -74,6 +76,8 @@ func registerQuery(app *extkingpin.App) { key := cmd.Flag("grpc-client-tls-key", "TLS Key for the client's certificate").Default("").String() caCert := cmd.Flag("grpc-client-tls-ca", "TLS CA Certificates to use to verify gRPC servers").Default("").String() serverName := cmd.Flag("grpc-client-server-name", "Server name to verify the hostname on the returned gRPC certificates. See https://tools.ietf.org/html/rfc4366#section-3.1").Default("").String() + compressionOptions := strings.Join([]string{snappy.Name, compressionNone}, ", ") + grpcCompression := cmd.Flag("grpc-compression", "Compression algorithm to use for gRPC requests to other clients. Must be one of: "+compressionOptions).Default(compressionNone).Enum(snappy.Name, compressionNone) webRoutePrefix := cmd.Flag("web.route-prefix", "Prefix for API and UI endpoints. This allows thanos UI to be served on a sub-path. Defaults to the value of --web.external-prefix. This option is analogous to --web.route-prefix of Prometheus.").Default("").String() webExternalPrefix := cmd.Flag("web.external-prefix", "Static prefix for all HTML links and redirect URLs in the UI query web interface. Actual endpoints are still served on / or the web.route-prefix. This allows thanos UI to be served behind a reverse proxy that strips a URL sub-path.").Default("").String() @@ -239,6 +243,7 @@ func registerQuery(app *extkingpin.App) { *grpcKey, *grpcClientCA, *grpcMaxConnAge, + *grpcCompression, *secure, *skipVerify, *cert, @@ -308,6 +313,7 @@ func runQuery( grpcKey string, grpcClientCA string, grpcMaxConnAge time.Duration, + grpcCompression string, secure bool, skipVerify bool, cert string, @@ -375,6 +381,9 @@ func runQuery( if err != nil { return errors.Wrap(err, "building gRPC client") } + if grpcCompression != compressionNone { + dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(grpcCompression))) + } fileSDCache := cache.New() dnsStoreProvider := dns.NewProvider( diff --git a/docs/components/query.md b/docs/components/query.md index 80422a62aa..72e3d6e1ab 100644 --- a/docs/components/query.md +++ b/docs/components/query.md @@ -292,6 +292,8 @@ Flags: --grpc-client-tls-skip-verify Disable TLS certificate verification i.e self signed, signed by fake CA + --grpc-compression=none Compression algorithm to use for gRPC requests + to other clients. Must be one of: snappy, none --grpc-grace-period=2m Time to wait after an interrupt received for GRPC Server. --grpc-server-max-connection-age=60m