From a84c5a32ae00182f443d271a9d61053d41e9ec43 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Sat, 6 Aug 2022 09:11:34 +0200 Subject: [PATCH] Add support for snappy compression receivers Distributing series between receivers is currently done by sending uncompressed payloads which can lead to high inter-zone egress costs. This commit adds support for using snappy compression for sending data from one receiver to another. Signed-off-by: Filip Petkovski --- CHANGELOG.md | 3 ++- cmd/thanos/receive.go | 12 ++++++++++++ docs/components/receive.md | 4 ++++ docs/components/tools.md | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b5d91cbeae..82349db28f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#5470](https://github.com/thanos-io/thanos/pull/5470) Receive: Implement exposing TSDB stats for all tenants - [#5493](https://github.com/thanos-io/thanos/pull/5493) Compact: Added `--compact.blocks-fetch-concurrency` allowing to configure number of go routines for download blocks during compactions. - [#5527](https://github.com/thanos-io/thanos/pull/5527) Receive: Add per request limits for remote write. -- [#5520](https://github.com/thanos-io/thanos/pull/5520) Receive: Meta-monitoring based active series limiting +- [#5520](https://github.com/thanos-io/thanos/pull/5520) Receive: Meta-monitoring based active series limiting. +- [#5575](https://github.com/thanos-io/thanos/pull/5575) Receive: Add support for gRPC compression. ### Changed diff --git a/cmd/thanos/receive.go b/cmd/thanos/receive.go index a8a5ddeb396..000c167c1a6 100644 --- a/cmd/thanos/receive.go +++ b/cmd/thanos/receive.go @@ -11,6 +11,8 @@ import ( "strings" "time" + "google.golang.org/grpc" + extflag "github.com/efficientgo/tools/extkingpin" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -29,6 +31,7 @@ import ( "github.com/thanos-io/objstore/client" "gopkg.in/yaml.v2" + "github.com/thanos-io/thanos/internal/cortex/util/grpcencoding/snappy" "github.com/thanos-io/thanos/pkg/block/metadata" "github.com/thanos-io/thanos/pkg/component" "github.com/thanos-io/thanos/pkg/exemplars" @@ -48,6 +51,8 @@ import ( "github.com/thanos-io/thanos/pkg/tls" ) +const compressionNone = "none" + func registerReceive(app *extkingpin.App) { cmd := app.Command(component.Receive.String(), "Accept Prometheus remote write API requests and write to local tsdb.") @@ -139,6 +144,9 @@ func runReceive( if err != nil { return err } + if conf.compression != compressionNone { + dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(conf.compression))) + } var bkt objstore.Bucket confContentYaml, err := conf.objStoreConfig.Content() @@ -782,6 +790,7 @@ type receiveConfig struct { replicaHeader string replicationFactor uint64 forwardTimeout *model.Duration + compression string tsdbMinBlockDuration *model.Duration tsdbMaxBlockDuration *model.Duration @@ -859,6 +868,9 @@ func (rc *receiveConfig) registerFlag(cmd extkingpin.FlagClause) { cmd.Flag("receive.replica-header", "HTTP header specifying the replica number of a write request.").Default(receive.DefaultReplicaHeader).StringVar(&rc.replicaHeader) + compressionOptions := strings.Join([]string{compressionNone, snappy.Name}, ", ") + cmd.Flag("receive.grpc-compression", "Compression algorithm to use for gRPC requests to other receivers. Must be one of: "+compressionOptions).Default(compressionNone).EnumVar(&rc.compression, compressionNone, snappy.Name) + cmd.Flag("receive.replication-factor", "How many times to replicate incoming write requests.").Default("1").Uint64Var(&rc.replicationFactor) cmd.Flag("receive.tenant-limits.max-head-series", "The total number of active (head) series that a tenant is allowed to have within a Receive topology. For more details refer: https://thanos.io/tip/components/receive.md/#limiting").Hidden().Uint64Var(&rc.maxPerTenantLimit) diff --git a/docs/components/receive.md b/docs/components/receive.md index c3c96d13e75..ee5a6005d1f 100644 --- a/docs/components/receive.md +++ b/docs/components/receive.md @@ -192,6 +192,10 @@ Flags: --receive.default-tenant-id="default-tenant" Default tenant ID to use when none is provided via a header. + --receive.grpc-compression=none + Compression algorithm to use for gRPC requests + to other receivers. Must be one of: none, + snappy --receive.hashrings= Alternative to 'receive.hashrings-file' flag (lower priority). Content of file that contains diff --git a/docs/components/tools.md b/docs/components/tools.md index 776164aeb00..66c400b5533 100644 --- a/docs/components/tools.md +++ b/docs/components/tools.md @@ -814,7 +814,7 @@ Flags: --rewrite.to-relabel-config-file= Path to YAML file that contains relabel configs that will be applied to blocks - --tmp.dir="/tmp/thanos-rewrite" + --tmp.dir="/var/folders/0b/r42s6hv96hs2w84ycr2yf7qh0000gn/T/thanos-rewrite" Working directory for temporary files --tracing.config= Alternative to 'tracing.config-file' flag