Skip to content

Commit 8a5b844

Browse files
committed
feat: allow more compressor overrides
Signed-off-by: Steven Kreitzer <[email protected]>
1 parent 3ba1db8 commit 8a5b844

File tree

20 files changed

+271
-116
lines changed

20 files changed

+271
-116
lines changed

api/v1alpha1/compression_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ type Compression struct {
4141
// +required
4242
Type CompressorType `json:"type"`
4343

44+
// ChooseFirst indicates whether to choose the first encoding type
45+
//
46+
// +optional
47+
ChooseFirst bool `json:"chooseFirst,omitempty"`
48+
49+
// RemoveAcceptEncodingHeader indicates whether to remove the
50+
// Accept-Encoding header from the request before forwarding it to the upstream.
51+
//
52+
// +optional
53+
RemoveAcceptEncodingHeader bool `json:"removeAcceptEncodingHeader,omitempty"`
54+
4455
// The configuration for Brotli compressor.
4556
//
4657
// +optional

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,18 @@ spec:
126126
brotli:
127127
description: The configuration for Brotli compressor.
128128
type: object
129+
chooseFirst:
130+
description: ChooseFirst indicates whether to choose the first
131+
encoding type
132+
type: boolean
129133
gzip:
130134
description: The configuration for GZIP compressor.
131135
type: object
136+
removeAcceptEncodingHeader:
137+
description: |-
138+
RemoveAcceptEncodingHeader indicates whether to remove the
139+
Accept-Encoding header from the request before forwarding it to the upstream.
140+
type: boolean
132141
type:
133142
description: CompressorType defines the compressor type to use
134143
for compression.
@@ -156,9 +165,18 @@ spec:
156165
brotli:
157166
description: The configuration for Brotli compressor.
158167
type: object
168+
chooseFirst:
169+
description: ChooseFirst indicates whether to choose the first
170+
encoding type
171+
type: boolean
159172
gzip:
160173
description: The configuration for GZIP compressor.
161174
type: object
175+
removeAcceptEncodingHeader:
176+
description: |-
177+
RemoveAcceptEncodingHeader indicates whether to remove the
178+
Accept-Encoding header from the request before forwarding it to the upstream.
179+
type: boolean
162180
type:
163181
description: CompressorType defines the compressor type to use
164182
for compression.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyproxies.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13476,9 +13476,18 @@ spec:
1347613476
brotli:
1347713477
description: The configuration for Brotli compressor.
1347813478
type: object
13479+
chooseFirst:
13480+
description: ChooseFirst indicates whether to choose
13481+
the first encoding type
13482+
type: boolean
1347913483
gzip:
1348013484
description: The configuration for GZIP compressor.
1348113485
type: object
13486+
removeAcceptEncodingHeader:
13487+
description: |-
13488+
RemoveAcceptEncodingHeader indicates whether to remove the
13489+
Accept-Encoding header from the request before forwarding it to the upstream.
13490+
type: boolean
1348213491
type:
1348313492
description: CompressorType defines the compressor
1348413493
type to use for compression.

charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,18 @@ spec:
125125
brotli:
126126
description: The configuration for Brotli compressor.
127127
type: object
128+
chooseFirst:
129+
description: ChooseFirst indicates whether to choose the first
130+
encoding type
131+
type: boolean
128132
gzip:
129133
description: The configuration for GZIP compressor.
130134
type: object
135+
removeAcceptEncodingHeader:
136+
description: |-
137+
RemoveAcceptEncodingHeader indicates whether to remove the
138+
Accept-Encoding header from the request before forwarding it to the upstream.
139+
type: boolean
131140
type:
132141
description: CompressorType defines the compressor type to use
133142
for compression.
@@ -155,9 +164,18 @@ spec:
155164
brotli:
156165
description: The configuration for Brotli compressor.
157166
type: object
167+
chooseFirst:
168+
description: ChooseFirst indicates whether to choose the first
169+
encoding type
170+
type: boolean
158171
gzip:
159172
description: The configuration for GZIP compressor.
160173
type: object
174+
removeAcceptEncodingHeader:
175+
description: |-
176+
RemoveAcceptEncodingHeader indicates whether to remove the
177+
Accept-Encoding header from the request before forwarding it to the upstream.
178+
type: boolean
161179
type:
162180
description: CompressorType defines the compressor type to use
163181
for compression.

charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13475,9 +13475,18 @@ spec:
1347513475
brotli:
1347613476
description: The configuration for Brotli compressor.
1347713477
type: object
13478+
chooseFirst:
13479+
description: ChooseFirst indicates whether to choose
13480+
the first encoding type
13481+
type: boolean
1347813482
gzip:
1347913483
description: The configuration for GZIP compressor.
1348013484
type: object
13485+
removeAcceptEncodingHeader:
13486+
description: |-
13487+
RemoveAcceptEncodingHeader indicates whether to remove the
13488+
Accept-Encoding header from the request before forwarding it to the upstream.
13489+
type: boolean
1348113490
type:
1348213491
description: CompressorType defines the compressor
1348313492
type to use for compression.

internal/gatewayapi/backendtrafficpolicy.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,16 @@ func buildCompression(compression, compressor []*egv1a1.Compression) []*ir.Compr
15291529
if (c.Type == egv1a1.GzipCompressorType && c.Gzip != nil) ||
15301530
(c.Type == egv1a1.BrotliCompressorType && c.Brotli != nil) ||
15311531
(c.Type == egv1a1.ZstdCompressorType && c.Zstd != nil) {
1532-
irCompression = append(irCompression, &ir.Compression{
1532+
compression := &ir.Compression{
15331533
Type: c.Type,
1534-
})
1534+
}
1535+
if c.ChooseFirst {
1536+
compression.ChooseFirst = true
1537+
}
1538+
if c.RemoveAcceptEncodingHeader {
1539+
compression.RemoveAcceptEncodingHeader = true
1540+
}
1541+
irCompression = append(irCompression, compression)
15351542
}
15361543
}
15371544
return irCompression
@@ -1543,9 +1550,16 @@ func buildCompression(compression, compressor []*egv1a1.Compression) []*ir.Compr
15431550
}
15441551
irCompression := make([]*ir.Compression, 0, len(compression))
15451552
for _, c := range compression {
1546-
irCompression = append(irCompression, &ir.Compression{
1553+
compression := &ir.Compression{
15471554
Type: c.Type,
1548-
})
1555+
}
1556+
if c.ChooseFirst {
1557+
compression.ChooseFirst = true
1558+
}
1559+
if c.RemoveAcceptEncodingHeader {
1560+
compression.RemoveAcceptEncodingHeader = true
1561+
}
1562+
irCompression = append(irCompression, compression)
15491563
}
15501564

15511565
return irCompression

internal/ir/xds.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ type HeaderBasedSessionPersistence struct {
884884
type Compression struct {
885885
// Type of compression to be used.
886886
Type egv1a1.CompressorType `json:"type" yaml:"type"`
887+
// If this compression should be first.
888+
ChooseFirst bool `json:"chooseFirst,omitempty" yaml:"chooseFirst,omitempty"`
889+
// RemoveAcceptEncodingHeader indicates whether to remove the Accept-Encoding header from the request.
890+
RemoveAcceptEncodingHeader bool `json:"removeAcceptEncodingHeader,omitempty" yaml:"removeAcceptEncodingHeader,omitempty"`
887891
}
888892

889893
// TrafficFeatures holds the information associated with the Backend Traffic Policy.

internal/xds/bootstrap/bootstrap.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ type bootstrapParameters struct {
8484
// PrometheusCompressionLibrary defines the HTTP compression library for metrics endpoint for prometheus.
8585
// TODO: remove this field because it is not used.
8686
PrometheusCompressionLibrary string
87+
// PrometheusCompressionChooseFirst defines whether to choose first encoding type for metrics endpoint for prometheus.
88+
PrometheusCompressionChooseFirst bool
89+
// PrometheusCompressionRemoveAcceptEncodingHeader defines whether to remove the
90+
// Accept-Encoding header from the request before forwarding it to the upstream for metrics endpoint for prometheus.
91+
PrometheusCompressionRemoveAcceptEncodingHeader bool
8792

8893
// OtelMetricSinks defines the configuration of the OpenTelemetry sinks.
8994
OtelMetricSinks []metricSink
@@ -177,11 +182,13 @@ func (b *bootstrapConfig) render() error {
177182
// GetRenderedBootstrapConfig renders the bootstrap YAML string
178183
func GetRenderedBootstrapConfig(opts *RenderBootstrapConfigOptions) (string, error) {
179184
var (
180-
enablePrometheus = true
181-
enablePrometheusCompression = false
182-
prometheusCompressionLibrary = "Gzip"
183-
metricSinks []metricSink
184-
StatsMatcher StatsMatcherParameters
185+
enablePrometheus = true
186+
enablePrometheusCompression = false
187+
prometheusCompressionLibrary = "Gzip"
188+
prometheusCompressionChooseFirst = false
189+
prometheusCompressionRemoveAcceptEncodingHeader = false
190+
metricSinks []metricSink
191+
StatsMatcher StatsMatcherParameters
185192
)
186193

187194
if opts != nil && opts.ProxyMetrics != nil {
@@ -193,6 +200,8 @@ func GetRenderedBootstrapConfig(opts *RenderBootstrapConfigOptions) (string, err
193200
if proxyMetrics.Prometheus.Compression != nil {
194201
enablePrometheusCompression = true
195202
prometheusCompressionLibrary = string(proxyMetrics.Prometheus.Compression.Type)
203+
prometheusCompressionChooseFirst = proxyMetrics.Prometheus.Compression.ChooseFirst
204+
prometheusCompressionRemoveAcceptEncodingHeader = proxyMetrics.Prometheus.Compression.RemoveAcceptEncodingHeader
196205
}
197206
}
198207

@@ -263,14 +272,16 @@ func GetRenderedBootstrapConfig(opts *RenderBootstrapConfigOptions) (string, err
263272
Address: netutils.IPv4ListenerAddress,
264273
Port: EnvoyStatsPort,
265274
},
266-
SdsCertificatePath: defaultSdsCertificatePath,
267-
SdsTrustedCAPath: defaultSdsTrustedCAPath,
268-
EnablePrometheus: enablePrometheus,
269-
EnablePrometheusCompression: enablePrometheusCompression,
270-
PrometheusCompressionLibrary: prometheusCompressionLibrary,
271-
OtelMetricSinks: metricSinks,
272-
ServiceClusterName: defaultServiceClusterName,
273-
ServiceAccountTokenPath: defaultServiceAccountTokenPath,
275+
SdsCertificatePath: defaultSdsCertificatePath,
276+
SdsTrustedCAPath: defaultSdsTrustedCAPath,
277+
EnablePrometheus: enablePrometheus,
278+
EnablePrometheusCompression: enablePrometheusCompression,
279+
PrometheusCompressionLibrary: prometheusCompressionLibrary,
280+
PrometheusCompressionChooseFirst: prometheusCompressionChooseFirst,
281+
PrometheusCompressionRemoveAcceptEncodingHeader: prometheusCompressionRemoveAcceptEncodingHeader,
282+
OtelMetricSinks: metricSinks,
283+
ServiceClusterName: defaultServiceClusterName,
284+
ServiceAccountTokenPath: defaultServiceAccountTokenPath,
274285
},
275286
}
276287

internal/xds/bootstrap/bootstrap.yaml.tpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,40 @@ static_resources:
113113
envoy.filters.http.compression:
114114
"@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.CompressorPerRoute
115115
overrides:
116+
{{- if .PrometheusCompressionRemoveAcceptEncodingHeader }}
116117
response_direction_config:
118+
remove_accept_encoding_header: true
119+
{{- else }}
120+
response_direction_config:
121+
{{- end }}
117122
{{- end }}
118123
http_filters:
119124
{{- if .EnablePrometheusCompression }}
120125
- name: envoy.filters.http.compressor
121126
typed_config:
122127
"@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
123128
{{- if eq .PrometheusCompressionLibrary "Gzip"}}
129+
{{- if .PrometheusCompressionChooseFirst }}
130+
choose_first: true
131+
{{- end }}
124132
compressor_library:
125133
name: text_optimized
126134
typed_config:
127135
"@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
128136
{{- end }}
129137
{{- if eq .PrometheusCompressionLibrary "Brotli"}}
138+
{{- if .PrometheusCompressionChooseFirst }}
139+
choose_first: true
140+
{{- end }}
130141
compressor_library:
131142
name: text_optimized
132143
typed_config:
133144
"@type": type.googleapis.com/envoy.extensions.compression.brotli.compressor.v3.Brotli
134145
{{- end }}
135146
{{- if eq .PrometheusCompressionLibrary "Zstd"}}
147+
{{- if .PrometheusCompressionChooseFirst }}
148+
choose_first: true
149+
{{- end }}
136150
compressor_library:
137151
name: text_optimized
138152
typed_config:

internal/xds/bootstrap/bootstrap_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ func TestGetRenderedBootstrapConfig(t *testing.T) {
8282
ProxyMetrics: &egv1a1.ProxyMetrics{
8383
Prometheus: &egv1a1.ProxyPrometheusProvider{
8484
Compression: &egv1a1.Compression{
85-
Type: egv1a1.ZstdCompressorType,
85+
Type: egv1a1.ZstdCompressorType,
86+
ChooseFirst: true,
87+
RemoveAcceptEncodingHeader: true,
8688
},
8789
},
8890
},

0 commit comments

Comments
 (0)