Skip to content

Commit dd443fb

Browse files
author
DanTan
committed
feat: ability to configure the min size for response compression
1 parent 3f4dea6 commit dd443fb

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

router/core/graph_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func newGraphServer(ctx context.Context, r *Router, routerConfig *nodev1.RouterC
283283
}
284284

285285
wrapper, err := gzhttp.NewWrapper(
286-
gzhttp.MinSize(1024*4), // 4KB
286+
gzhttp.MinSize(int(s.routerTrafficConfig.ResponseCompressionMinSize)),
287287
gzhttp.CompressionLevel(gzip.DefaultCompression),
288288
gzhttp.ContentTypes(CompressibleContentTypes),
289289
)

router/pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ type RouterTrafficConfiguration struct {
181181
MaxHeaderBytes BytesString `yaml:"max_header_bytes" envDefault:"0MiB" env:"MAX_HEADER_BYTES"`
182182
// DecompressionEnabled is the configuration for request compression
183183
DecompressionEnabled bool `yaml:"decompression_enabled" envDefault:"true"`
184+
// ResponseCompressionMinSize is the minimum size of the response body in bytes to enable response compression
185+
ResponseCompressionMinSize BytesString `yaml:"response_compression_min_size" envDefault:"4KB"`
184186
}
185187

186188
type GlobalSubgraphRequestRule struct {

router/pkg/config/config.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,12 @@
14681468
"type": "boolean",
14691469
"description": "When enabled, the router will check incoming requests for a 'Content-Encoding' header and decompress the body accordingly. Currently only gzip is supported",
14701470
"default": true
1471+
},
1472+
"response_compression_min_size": {
1473+
"type": "string",
1474+
"description": "The minimum size of the response body in bytes to enable response compression. The size is specified as a string with a number and a unit, e.g. 10KB, 1MB, 1GB. The supported units are 'KB', 'MB', 'GB'.",
1475+
"default": "4KB",
1476+
"bytes": {}
14711477
}
14721478
}
14731479
},

router/pkg/config/fixtures/full.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ traffic_shaping:
198198
max_request_body_size: 5MB
199199
max_header_bytes: 4MiB
200200
decompression_enabled: false
201+
response_compression_min_size: 4KB
201202
all: # Rules are applied to all subgraph requests.
202203
# Subgraphs transport options
203204
request_timeout: 60s

0 commit comments

Comments
 (0)