Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/v1alpha1/compression_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ type Compression struct {
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern="^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$"
MinContentLength *resource.Quantity `json:"minContentLength,omitempty"`

// ContentTypes defines the set of response Content-Types that will trigger compression.
// When set, only responses whose Content-Type matches one of these values are compressed.
// If not specified, Envoy's default content types are used:
// application/javascript, application/json, application/xhtml+xml, image/svg+xml,
// text/css, text/html, text/plain, text/xml.
//
// +optional
ContentTypes []string `json:"contentTypes,omitempty"`
Comment thread
FAUST-BENCHOU marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep contentTypes out of metrics compression unless supported

Adding contentTypes to the shared Compression type also exposes it under EnvoyProxy.spec.telemetry.metrics.prometheus.compression because that field reuses this type, but the bootstrap renderer for Prometheus compression only reads Compression.Type and ignores the new list. EnvoyProxy users can now set an accepted/documented contentTypes value that has no effect; either wire it into internal/xds/bootstrap or avoid exposing this BackendTrafficPolicy-specific option through the shared type.

Useful? React with 👍 / 👎.

}
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ spec:
brotli:
description: The configuration for Brotli compressor.
type: object
contentTypes:
Comment thread
FAUST-BENCHOU marked this conversation as resolved.
description: |-
ContentTypes defines the set of response Content-Types that will trigger compression.
When set, only responses whose Content-Type matches one of these values are compressed.
If not specified, Envoy's default content types are used:
application/javascript, application/json, application/xhtml+xml, image/svg+xml,
text/css, text/html, text/plain, text/xml.
items:
type: string
type: array
gzip:
description: The configuration for GZIP compressor.
type: object
Expand Down Expand Up @@ -414,6 +424,16 @@ spec:
brotli:
description: The configuration for Brotli compressor.
type: object
contentTypes:
description: |-
ContentTypes defines the set of response Content-Types that will trigger compression.
When set, only responses whose Content-Type matches one of these values are compressed.
If not specified, Envoy's default content types are used:
application/javascript, application/json, application/xhtml+xml, image/svg+xml,
text/css, text/html, text/plain, text/xml.
items:
type: string
type: array
gzip:
description: The configuration for GZIP compressor.
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14692,6 +14692,16 @@ spec:
brotli:
description: The configuration for Brotli compressor.
type: object
contentTypes:
description: |-
ContentTypes defines the set of response Content-Types that will trigger compression.
When set, only responses whose Content-Type matches one of these values are compressed.
If not specified, Envoy's default content types are used:
application/javascript, application/json, application/xhtml+xml, image/svg+xml,
text/css, text/html, text/plain, text/xml.
items:
type: string
type: array
gzip:
description: The configuration for GZIP compressor.
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ spec:
brotli:
description: The configuration for Brotli compressor.
type: object
contentTypes:
description: |-
ContentTypes defines the set of response Content-Types that will trigger compression.
When set, only responses whose Content-Type matches one of these values are compressed.
If not specified, Envoy's default content types are used:
application/javascript, application/json, application/xhtml+xml, image/svg+xml,
text/css, text/html, text/plain, text/xml.
items:
type: string
type: array
gzip:
description: The configuration for GZIP compressor.
type: object
Expand Down Expand Up @@ -413,6 +423,16 @@ spec:
brotli:
description: The configuration for Brotli compressor.
type: object
contentTypes:
description: |-
ContentTypes defines the set of response Content-Types that will trigger compression.
When set, only responses whose Content-Type matches one of these values are compressed.
If not specified, Envoy's default content types are used:
application/javascript, application/json, application/xhtml+xml, image/svg+xml,
text/css, text/html, text/plain, text/xml.
items:
type: string
type: array
gzip:
description: The configuration for GZIP compressor.
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14691,6 +14691,16 @@ spec:
brotli:
description: The configuration for Brotli compressor.
type: object
contentTypes:
description: |-
ContentTypes defines the set of response Content-Types that will trigger compression.
When set, only responses whose Content-Type matches one of these values are compressed.
If not specified, Envoy's default content types are used:
application/javascript, application/json, application/xhtml+xml, image/svg+xml,
text/css, text/html, text/plain, text/xml.
items:
type: string
type: array
gzip:
description: The configuration for GZIP compressor.
type: object
Expand Down
41 changes: 19 additions & 22 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2092,17 +2092,7 @@ func buildCompression(compression, compressor []*egv1a1.Compression) []*ir.Compr
if (c.Type == egv1a1.GzipCompressorType && c.Gzip != nil) ||
(c.Type == egv1a1.BrotliCompressorType && c.Brotli != nil) ||
(c.Type == egv1a1.ZstdCompressorType && c.Zstd != nil) {
irCompression := ir.Compression{
Type: c.Type,
ChooseFirst: i == 0, // only the first compressor is marked as ChooseFirst
}
if c.MinContentLength != nil {
minContentLength, ok := c.MinContentLength.AsInt64()
if ok {
irCompression.MinContentLength = new(uint32(minContentLength))
}
}
result = append(result, &irCompression)
result = append(result, buildIRCompression(c, i == 0))
}
}
return result
Expand All @@ -2114,22 +2104,29 @@ func buildCompression(compression, compressor []*egv1a1.Compression) []*ir.Compr
}
result := make([]*ir.Compression, 0, len(compression))
for i, c := range compression {
irCompression := ir.Compression{
Type: c.Type,
ChooseFirst: i == 0, // only the first compressor is marked as ChooseFirst
}
if c.MinContentLength != nil {
minContentLength, ok := c.MinContentLength.AsInt64()
if ok {
irCompression.MinContentLength = new(uint32(minContentLength))
}
}
result = append(result, &irCompression)
result = append(result, buildIRCompression(c, i == 0))
}

return result
}

func buildIRCompression(c *egv1a1.Compression, chooseFirst bool) *ir.Compression {
irCompression := &ir.Compression{
Type: c.Type,
ChooseFirst: chooseFirst, // only the first compressor is marked as ChooseFirst
}
if c.MinContentLength != nil {
minContentLength, ok := c.MinContentLength.AsInt64()
if ok {
irCompression.MinContentLength = new(uint32(minContentLength))
}
}
if len(c.ContentTypes) > 0 {
irCompression.ContentTypes = append([]string{}, c.ContentTypes...)
}
return irCompression
}

func buildHTTPProtocolUpgradeConfig(cfgs []*egv1a1.ProtocolUpgradeConfig) []ir.HTTPUpgradeConfig {
if len(cfgs) == 0 {
return nil
Expand Down
46 changes: 41 additions & 5 deletions internal/gatewayapi/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,23 @@ func TestBuildCompression(t *testing.T) {
},
},
},
{
name: "compressor with contentTypes",
compressor: []*egv1a1.Compression{
{
Type: egv1a1.GzipCompressorType,
Gzip: &egv1a1.GzipCompressor{},
ContentTypes: []string{"application/json", "text/html"},
},
},
expected: []*ir.Compression{
{
Type: egv1a1.GzipCompressorType,
ChooseFirst: true,
ContentTypes: []string{"application/json", "text/html"},
},
},
},
{
name: "multiple compressors with different minContentLength",
compressor: []*egv1a1.Compression{
Expand Down Expand Up @@ -424,21 +441,40 @@ func TestBuildCompression(t *testing.T) {
},
},
{
name: "compressor takes priority over compression",
compression: []*egv1a1.Compression{
name: "compressor with minContentLength and contentTypes",
compressor: []*egv1a1.Compression{
{
Type: egv1a1.GzipCompressorType,
Gzip: &egv1a1.GzipCompressor{},
MinContentLength: new(resource.MustParse("100")),
Type: egv1a1.BrotliCompressorType,
Brotli: &egv1a1.BrotliCompressor{},
MinContentLength: new(resource.MustParse("200")),
ContentTypes: []string{"application/json"},
},
},
expected: []*ir.Compression{
{
Type: egv1a1.BrotliCompressorType,
ChooseFirst: true,
MinContentLength: new(uint32(200)),
ContentTypes: []string{"application/json"},
},
},
},
{
name: "compressor takes priority over compression",
compressor: []*egv1a1.Compression{
{
Type: egv1a1.BrotliCompressorType,
Brotli: &egv1a1.BrotliCompressor{},
MinContentLength: new(resource.MustParse("200")),
},
},
compression: []*egv1a1.Compression{
{
Type: egv1a1.GzipCompressorType,
Gzip: &egv1a1.GzipCompressor{},
MinContentLength: new(resource.MustParse("100")),
},
},
expected: []*ir.Compression{
{
Type: egv1a1.BrotliCompressorType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
backendTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: default
name: policy-for-route
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: httproute-1
compressor:
- type: Brotli
brotli: {}
minContentLength: 100
contentTypes:
- application/json
- text/html
- type: Gzip
gzip: {}
contentTypes:
- application/json
Loading
Loading