Skip to content

Commit 752df6b

Browse files
timonegkamol-verma-allen
authored andcommitted
feat(elasticsearch): add flag to enable gzip compression (jaegertracing#7072)
## Which problem is this PR solving? Currently, Jaeger sends its traces to ElasticSearch as uncompressed text. Since text is can be compressed quite well, enabling Gzip compression can significantly reduce Jaeger's network traffic. ElasticSearch has accepted compressed requests since version 5.0 and since the same version it has already sent compressed responses by default (cf. elastic/elasticsearch@0a6f40c). ## Description of the changes * 🛑 (breaking change) **Enable by default** the compression for requests to ElasticSearch * Add a new flag `--es.http-compression=true|false` that can be used to opt-out of compression . The setting is already supported by both client libraries that are used. ## How was this change tested? I tested the change running a local ElasticSearch instance and `SPAN_STORAGE_TYPE=elasticsearch ./cmd/collector/collector-linux-amd64 --es.http-compression=true`. I sent traces to Jaeger using `tracepusher` and observed the network traffic between Jaeger and ElasticSearch using `tcpdump` to verify that the traffic is indeed compressed. ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Timon Engelke <[email protected]> Signed-off-by: amol-verma-allen <[email protected]>
1 parent 3e71d01 commit 752df6b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

internal/storage/elasticsearch/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ type Configuration struct {
9999
SendGetBodyAs string `mapstructure:"send_get_body_as"`
100100
// QueryTimeout contains the timeout used for queries. A timeout of zero means no timeout.
101101
QueryTimeout time.Duration `mapstructure:"query_timeout"`
102+
// HTTPCompression can be set to false to disable gzip compression for requests to ElasticSearch
103+
HTTPCompression bool `mapstructure:"http_compression"`
102104

103105
// ---- elasticsearch client related configs ----
104106
BulkProcessing BulkProcessing `mapstructure:"bulk_processing"`
@@ -319,6 +321,7 @@ func newElasticsearchV8(c *Configuration, logger *zap.Logger) (*esV8.Client, err
319321
options.Username = c.Authentication.BasicAuthentication.Username
320322
options.Password = c.Authentication.BasicAuthentication.Password
321323
options.DiscoverNodesOnStart = c.Sniffing.Enabled
324+
options.CompressRequestBody = c.HTTPCompression
322325
transport, err := GetHTTPRoundTripper(c, logger)
323326
if err != nil {
324327
return nil, err
@@ -413,6 +416,9 @@ func (c *Configuration) ApplyDefaults(source *Configuration) {
413416
if c.SendGetBodyAs == "" {
414417
c.SendGetBodyAs = source.SendGetBodyAs
415418
}
419+
if !c.HTTPCompression {
420+
c.HTTPCompression = source.HTTPCompression
421+
}
416422
}
417423

418424
// RolloverFrequencyAsNegativeDuration returns the index rollover frequency duration for the given frequency string
@@ -486,6 +492,7 @@ func (c *Configuration) getConfigOptions(logger *zap.Logger) ([]elastic.ClientOp
486492
if c.SendGetBodyAs != "" {
487493
options = append(options, elastic.SetSendGetBodyAs(c.SendGetBodyAs))
488494
}
495+
options = append(options, elastic.SetGzip(c.HTTPCompression))
489496

490497
options, err := addLoggerOptions(options, c.LogLevel, logger)
491498
if err != nil {

internal/storage/v1/elasticsearch/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const (
5757
suffixMaxDocCount = ".max-doc-count"
5858
suffixLogLevel = ".log-level"
5959
suffixSendGetBodyAs = ".send-get-body-as"
60+
suffixHTTPCompression = ".http-compression"
6061
// default number of documents to return from a query (elasticsearch allowed limit)
6162
// see search.max_buckets and index.max_result_window
6263
defaultMaxDocCount = 10_000
@@ -268,6 +269,10 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
268269
nsConfig.namespace+suffixSendGetBodyAs,
269270
nsConfig.SendGetBodyAs,
270271
"HTTP verb for requests that contain a body [GET, POST].")
272+
flagSet.Bool(
273+
nsConfig.namespace+suffixHTTPCompression,
274+
nsConfig.HTTPCompression,
275+
"Use gzip compression for requests to ElasticSearch.")
271276
flagSet.Duration(
272277
nsConfig.namespace+suffixAdaptiveSamplingLookback,
273278
nsConfig.AdaptiveSamplingLookback,
@@ -339,6 +344,7 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
339344
cfg.Version = v.GetUint(cfg.namespace + suffixVersion)
340345
cfg.LogLevel = v.GetString(cfg.namespace + suffixLogLevel)
341346
cfg.SendGetBodyAs = v.GetString(cfg.namespace + suffixSendGetBodyAs)
347+
cfg.HTTPCompression = v.GetBool(cfg.namespace + suffixHTTPCompression)
342348

343349
cfg.MaxDocCount = v.GetInt(cfg.namespace + suffixMaxDocCount)
344350
cfg.UseILM = v.GetBool(cfg.namespace + suffixUseILM)
@@ -421,6 +427,7 @@ func DefaultConfig() config.Configuration {
421427
MaxDocCount: defaultMaxDocCount,
422428
LogLevel: "error",
423429
SendGetBodyAs: defaultSendGetBodyAs,
430+
HTTPCompression: true,
424431
Indices: config.Indices{
425432
Spans: defaultIndexOptions,
426433
Services: defaultIndexOptions,

internal/storage/v1/elasticsearch/options_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func TestOptionsWithFlags(t *testing.T) {
6363
"--es.tags-as-fields.dot-replacement=!",
6464
"--es.use-ilm=true",
6565
"--es.send-get-body-as=POST",
66+
"--es.http-compression=true",
6667
})
6768
require.NoError(t, err)
6869
opts.InitFromViper(v)
@@ -86,6 +87,7 @@ func TestOptionsWithFlags(t *testing.T) {
8687
assert.Equal(t, "20060102", primary.Indices.Services.DateLayout)
8788
assert.Equal(t, "2006010215", primary.Indices.Spans.DateLayout)
8889
assert.True(t, primary.UseILM)
90+
assert.True(t, primary.HTTPCompression)
8991
}
9092

9193
func TestEmptyRemoteReadClusters(t *testing.T) {

0 commit comments

Comments
 (0)