Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disableCompression: Expose configuration to toggle Envoy GZIP compression on the responses #6546

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b4d5b67
build(deps): bump docker/setup-buildx-action from 3.3.0 to 3.4.0 (#6543)
dependabot[bot] Jul 8, 2024
081a47c
Adds "disableCompression" as a feature to turnon/off Envoy's GZIP res…
Jul 9, 2024
818ccf0
Merge remote-tracking branch 'upstream/main'
Aug 7, 2024
7ddb6f0
This fixes linter nag parameter 'conf' seems to be unused
Aug 22, 2024
8df07e2
This fixes linter nag File is not gci-ed with ...
Aug 22, 2024
100bf40
This fixes linter nag File is not gci-ed with ...
Aug 22, 2024
56e4ee7
This fixes linter nag File is not gofumpt-ed with -extra
Aug 22, 2024
548981e
This fixes linter nag File is not gofumpt-ed with -extra
Aug 22, 2024
934ca48
Fix table borders
Aug 21, 2024
2efb693
Add disableCompression flag to configuration docs.
Aug 21, 2024
b0cfe71
add changelog file
Aug 22, 2024
72e0e9c
Merge remote-tracking branch 'upstream/main'
geomacy Sep 7, 2024
73c4b67
Merge remote-tracking branch 'upstream/main'
Sep 30, 2024
235acc3
Merge remote-tracking branch 'upstream/main'
Oct 8, 2024
7e843b7
rework as --compression flag with options gzip, brotli, zstd, disabled
geomacy Sep 7, 2024
36dbadb
Merge pull request #1 from chaosbox/compression-flag
geomacy Oct 8, 2024
f7b261b
add validation to crd compression field
Oct 19, 2024
b68f0b1
delete unnecessary output log
Oct 19, 2024
5dcdc33
define compression with a struct for API extensibility
Oct 21, 2024
3d83394
lint fixes
Oct 23, 2024
cda9c76
test fix
Oct 24, 2024
ff84c37
fix flag handling
Oct 28, 2024
5725a53
api lint
Oct 28, 2024
630541e
parameters_test
Oct 28, 2024
4610b80
update comment
Oct 28, 2024
45ea946
fix assertion arg order and bump timeout
Oct 28, 2024
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
53 changes: 53 additions & 0 deletions apis/projectcontour/v1alpha1/compression.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright Project Contour Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import "fmt"

// CompressionAlgorithm defines the type of compression algorithm applied in default HTTP listener filter chain.
// Allowable values are defined as names of well known compression algorithms (plus "disabled").
type CompressionAlgorithm string

// EnvoyCompression defines configuration related to compression in the default HTTP Listener filter chain.
type EnvoyCompression struct {
// Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
// Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
// Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
// +kubebuilder:validation:Enum="gzip";"brotli";"zstd";"disabled"
// +optional
Algorithm CompressionAlgorithm `json:"algorithm,omitempty"`
}

func (a CompressionAlgorithm) Validate() error {
switch a {
case BrotliCompression, DisabledCompression, GzipCompression, ZstdCompression:
return nil
default:
return fmt.Errorf("invalid compression type: %q", a)
}
}
Comment on lines +32 to +39
Copy link
Member

Choose a reason for hiding this comment

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

Would it be cleaner to treat an empty string as a valid value here, rather than completely bypassing validation in Parameters.Validate()? While algorithm is the only field currently, that might change.

Because +optionalstring in Go becomes an empty string when user did not set the field, it might be best to consider it as valid algorithm name in the Go side (CRD validation for the field can still reject it). It is already taken into account elsewhere in this change: inhttpConnectionManagerBuilder.DefaultFilters() you've added switch-default branch which will use gzip for empty algorithm string.


const (
// BrotliCompression specifies brotli as the default HTTP filter chain compression mechanism
BrotliCompression CompressionAlgorithm = "brotli"

// DisabledCompression specifies that there will be no compression in the default HTTP filter chain
DisabledCompression CompressionAlgorithm = "disabled"

// GzipCompression specifies gzip as the default HTTP filter chain compression mechanism
GzipCompression CompressionAlgorithm = "gzip"

// ZstdCompression specifies zstd as the default HTTP filter chain compression mechanism
ZstdCompression CompressionAlgorithm = "zstd"
)
32 changes: 32 additions & 0 deletions apis/projectcontour/v1alpha1/compression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright Project Contour Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1_test

import (
"testing"

"github.com/stretchr/testify/require"

contour_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
)

func TestValidateEnvoyCompressionAlgorithmType(t *testing.T) {
require.Error(t, contour_v1alpha1.CompressionAlgorithm("").Validate())
require.Error(t, contour_v1alpha1.CompressionAlgorithm("foo").Validate())

require.NoError(t, contour_v1alpha1.BrotliCompression.Validate())
require.NoError(t, contour_v1alpha1.DisabledCompression.Validate())
require.NoError(t, contour_v1alpha1.GzipCompression.Validate())
require.NoError(t, contour_v1alpha1.ZstdCompression.Validate())
}
4 changes: 4 additions & 0 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ type EnvoyListenerConfig struct {
// +optional
UseProxyProto *bool `json:"useProxyProtocol,omitempty"`

// Compression defines configuration related to compression in the default HTTP Listener filters.
// +optional
Compression *EnvoyCompression `json:"compression,omitempty"`

// DisableAllowChunkedLength disables the RFC-compliant Envoy behavior to
// strip the "Content-Length" header if "Transfer-Encoding: chunked" is
// also set. This is an emergency off-switch to revert back to Envoy's
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/6546-chaosbox-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add "compression" object to define settings in default HTTP filters, initially just supporting changing/disabling compression algorithm.
Copy link
Member

@tsaarni tsaarni Nov 22, 2024

Choose a reason for hiding this comment

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

We could add some pointers here for the user how to use it, possibly for example:

Suggested change
Add "compression" object to define settings in default HTTP filters, initially just supporting changing/disabling compression algorithm.
The HTTP compression algorithm can now be configured using the `compression.algorithm` field in the configuration file or the `spec.envoy.listener.compression.algorithm` field in the `ContourConfiguration` CRD. The available values are `gzip` (default), `brotli`, `zstd`, and `disabled`.

9 changes: 9 additions & 0 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext)

return nil
}

if ctx.Config.Compression == nil {
ctx.Config.Compression = &config.CompressionParameters{
Algorithm: config.CompressionDefault,
}
}

serve.Flag("accesslog-format", "Format for Envoy access logs.").PlaceHolder("<envoy|json>").StringVar((*string)(&ctx.Config.AccessLogFormat))

serve.Flag("compression", "Set or disable compression type in default Listener filters.").PlaceHolder("<gzip|brotli|zstd|disabled>").StringVar((*string)(&ctx.Config.Compression.Algorithm))
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the command line option and make configuration available only through config file and ContourConfiguration CRD.

The command line options currently are a bit of a mess, so we previously agreed to avoid introducing new options there unless absolutely necessary.

serve.Flag("config-path", "Path to base configuration.").Short('c').PlaceHolder("/path/to/file").Action(parseConfig).ExistingFileVar(&configFile)
serve.Flag("contour-cafile", "CA bundle file name for serving gRPC with TLS.").Envar("CONTOUR_CAFILE").StringVar(&ctx.caFile)
serve.Flag("contour-cert-file", "Contour certificate file name for serving gRPC over TLS.").PlaceHolder("/path/to/file").Envar("CONTOUR_CERT_FILE").StringVar(&ctx.contourCert)
Expand Down Expand Up @@ -447,6 +455,7 @@ func (s *Server) doServe() error {
}

listenerConfig := xdscache_v3.ListenerConfig{
Compression: contourConfiguration.Envoy.Listener.Compression,
UseProxyProto: *contourConfiguration.Envoy.Listener.UseProxyProto,
HTTPAccessLog: contourConfiguration.Envoy.HTTPListener.AccessLog,
HTTPSAccessLog: contourConfiguration.Envoy.HTTPSListener.AccessLog,
Expand Down
19 changes: 19 additions & 0 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,24 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_v1alpha1.Co
accessLogLevel = contour_v1alpha1.LogLevelDisabled
}

var compression *contour_v1alpha1.EnvoyCompression
if ctx.Config.Compression != nil {
var algorithm contour_v1alpha1.CompressionAlgorithm
switch ctx.Config.Compression.Algorithm {
case config.CompressionBrotli:
algorithm = contour_v1alpha1.BrotliCompression
case config.CompressionDisabled:
algorithm = contour_v1alpha1.DisabledCompression
case config.CompressionGzip:
algorithm = contour_v1alpha1.GzipCompression
case config.CompressionZstd:
algorithm = contour_v1alpha1.ZstdCompression
}
compression = &contour_v1alpha1.EnvoyCompression{
Algorithm: algorithm,
}
}

var defaultHTTPVersions []contour_v1alpha1.HTTPVersionType
for _, version := range ctx.Config.DefaultHTTPVersions {
switch version {
Expand Down Expand Up @@ -519,6 +537,7 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_v1alpha1.Co
Envoy: &contour_v1alpha1.EnvoyConfig{
Listener: &contour_v1alpha1.EnvoyListenerConfig{
UseProxyProto: &ctx.useProxyProto,
Compression: compression,
DisableAllowChunkedLength: &ctx.Config.DisableAllowChunkedLength,
DisableMergeSlashes: &ctx.Config.DisableMergeSlashes,
ServerHeaderTransformation: serverHeaderTransformation,
Expand Down
32 changes: 32 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related to
compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down Expand Up @@ -4063,6 +4079,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related
to compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down
32 changes: 32 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related to
compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down Expand Up @@ -4283,6 +4299,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related
to compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down
32 changes: 32 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related to
compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down Expand Up @@ -4074,6 +4090,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related
to compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down
32 changes: 32 additions & 0 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related to
compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down Expand Up @@ -4099,6 +4115,22 @@ spec:
description: Listener hold various configurable Envoy listener
values.
properties:
compression:
description: Compression defines configuration related
to compression in the default HTTP Listener filters.
properties:
algorithm:
description: |-
Algorithm selects the compression type applied in the compression HTTP filter of the default Listener filters.
Values: `gzip` (default), `brotli`, `zstd`, `disabled`.
Setting this to `disabled` will make Envoy skip "Accept-Encoding: gzip,deflate" request header and always return uncompressed response
enum:
- gzip
- brotli
- zstd
- disabled
type: string
type: object
connectionBalancer:
description: |-
ConnectionBalancer. If the value is exact, the listener will use the exact connection balancer
Expand Down
Loading