Skip to content

Commit

Permalink
query: add --grpc-compression for enabling compression
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
GiedriusS committed Aug 29, 2022
1 parent 544d67a commit e74fa3a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -239,6 +243,7 @@ func registerQuery(app *extkingpin.App) {
*grpcKey,
*grpcClientCA,
*grpcMaxConnAge,
*grpcCompression,
*secure,
*skipVerify,
*cert,
Expand Down Expand Up @@ -308,6 +313,7 @@ func runQuery(
grpcKey string,
grpcClientCA string,
grpcMaxConnAge time.Duration,
grpcCompression string,
secure bool,
skipVerify bool,
cert string,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e74fa3a

Please sign in to comment.