envoyproxy / gateway

Manages Envoy Proxy as a Standalone or Kubernetes-based Application Gateway
https://gateway.envoyproxy.io
Apache License 2.0
1.52k stars 326 forks source link

Support Compression #2451

Open arkodg opened 8 months ago

arkodg commented 8 months ago

Description: Support Payload Compression

[optional Relevant Links:]

Any extra documentation required to understand the issue.

Envoy - https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/compression/compression.html#compression

Upstream Issue - https://github.com/kubernetes-sigs/gateway-api/issues/1799

Relates to https://envoyproxy.slack.com/archives/C03E6NHLESV/p1705084783438099

arkodg commented 8 months ago

BackendTrafficPolicy seems like a good home for compression , and Envoy does have support for per route compression filters

akhenakh commented 8 months ago

For refs here is a working patch for HTTPS, (warning the path to patch is different for HTTP "/default_filter_chain/filters/0/typed_config/http_filters/0")

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyPatchPolicy
metadata:
  name: compressor-patch-policy
  namespace: envoy-gateway-system
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: Gateway
    name: eg
    namespace: envoy-gateway-system
  type: JSONPatch
  jsonPatches:
    - type: "type.googleapis.com/envoy.config.listener.v3.Listener"
      name: envoy-gateway-system/eg/https
      operation:
        op: add
        path: "/filter_chains/0/filters/0/typed_config/http_filters/0"
        value:
          name: "envoy.filters.http.compressor"
          typed_config:
            "@type": "type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor"
            compressor_library:
              name: text_optimized
              typed_config:
                "@type": "type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip"
                compression_level: BEST_SPEED
                compression_strategy: DEFAULT_STRATEGY
                memory_level: 8
                window_bits: 15
                chunk_size: 4096
            response_direction_config:
              remove_accept_encoding_header: true
              common_config:
                enabled:
                  default_value: true
                  runtime_key: response_direction_config_enabled
                content_type:
                  - "application/javascript"
                  - "application/json"
                  - "application/x-web-app-manifest+json"
                  - "application/xhtml+xml"
                  - "application/xml"
                  - "font/opentype"
                  - "image/svg+xml"
                  - "image/x-icon"
                  - "text/css"
                  - "text/html"
                  - "text/plain"
                  - "text/xml"
                min_content_length: 60
            request_direction_config:
              common_config:
                enabled:
                  default_value: false
                  runtime_key: request_direction_config_enabled

you should see a response with an content-encoding: gzip header for an HTTP/1.1 request with a Accept-Encoding: deflate, gzip header.

soulxu commented 7 months ago

@arkodg @akhenakh are you going to work on it? I'm willing to help on it, thanks!

arkodg commented 7 months ago

go for it @soulxu ! recommend starting with the API PR before implementing the logic :)

soulxu commented 7 months ago

@arkodg got it, thanks!

guydc commented 7 months ago

Interesting discussion here on compression performance and buffer sizing. Should we make per_connection_buffer_limit_bytes configurable as part of this issue?

I can also think of future use cases that include buffering filters (ext-auth with body, WAF, ext-proc, lua, buffer) that should be part of the Envoy Gateway scope and require buffer size tuning.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

robd003 commented 5 months ago

Would it be hard to add brotli compression with a fallback to gzip if the HTTP client only supports gzip?

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

arkodg commented 3 months ago

@soulxu still working on this one ?, the API is in, but the implementation is still left

jindrichpilar-kosik commented 3 months ago

Hi, we are also interested in compression support in CRDs.

Envoy supporting Brotli natively was one of the reasons we chose it as our API Gateway over Kong (which has since added Brotli support)

soulxu commented 3 months ago

@soulxu still working on this one ?, the API is in, but the implementation is still left

@arkodg I will give a try this two weeks.

arkodg commented 3 months ago

thanks for the update @soulxu ! , lets keep this in the v1.1 milestone for now

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

paulo-worry commented 1 month ago

+1

robd003 commented 1 month ago

Any updates on this @soulxu ?

arkodg commented 3 weeks ago

hey @soulxu are you still planning on working on this one ? would be great if you can, completely okay if not, will unassign so someone from the community can take this forward

soulxu commented 3 weeks ago

@arkodg sorry, I failed on get a chance working on it, please free feel to assign anyone interesting it.

arkodg commented 3 weeks ago

np thanks for the update @soulxu, unassgning