From b36ebcdc84e6d1eff8b7c9f720d9254fa12276d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Mon, 29 Aug 2022 16:19:22 +0300 Subject: [PATCH] query: add --grpc-compression for enabling compression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new `--grpc-compression` option that enables gRPC compression. Snappy works well - I've observed barely any increase in CPU/RAM usage and the network throughput dropped. Signed-off-by: Giedrius Statkevičius --- cmd/thanos/query.go | 9 +++++++++ docs/components/query.md | 2 ++ 2 files changed, 11 insertions(+) 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