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

Adds support for configuration of different types of compression, including none #6546

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
98225fc
add some servecontext tests
Nov 25, 2024
661b552
add some parameters tests
Nov 25, 2024
75f8b7b
Update internal/featuretests/v3/compression_test.go
geomacy Nov 26, 2024
351a820
Update changelogs/unreleased/6546-chaosbox-small.md
geomacy Nov 26, 2024
89060c0
Merge branch 'main' into pr-6546-review-comments
Nov 26, 2024
95d38af
remove command flag
Nov 26, 2024
366f48d
treat empty string as valid CompressionAlgorithm
Nov 26, 2024
1a6465f
update configuration docs per new types
Nov 26, 2024
43f6598
lint
Nov 27, 2024
2f5e157
rename builder method for clarity
Dec 5, 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)
}
}

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("foo").Validate())

require.NoError(t, contour_v1alpha1.CompressionAlgorithm("").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 @@
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`.
2 changes: 2 additions & 0 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext)

return nil
}

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

serve.Flag("config-path", "Path to base configuration.").Short('c').PlaceHolder("/path/to/file").Action(parseConfig).ExistingFileVar(&configFile)
Expand Down Expand Up @@ -447,6 +448,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.Algorithm != "" {
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
Loading