ASMCompressor is a custom resource definition (CRD) that configures HTTP compression for service-to-service communication and gateway traffic in Service Mesh (ASM). It supports both Gzip and Brotli algorithms.
How compression works
When you apply an ASMCompressor resource, ASM injects a compressor filter into the Envoy sidecar proxy of the selected workloads. The filter inspects request and response headers to determine whether to compress the content.
Compression is applied when all of the following conditions are met:
The content type matches one of the configured MIME types.
The content length meets the minimum threshold.
No existing Content-Encoding header is present.
Response compression is enabled by default. Request compression is disabled by default and must be explicitly configured through request_direction_config.
Example
The following ASMCompressor resource enables Gzip compression on responses for workloads labeled app: httpbin, on service port 8080:
apiVersion: istio.alibabacloud.com/v1
kind: ASMCompressor
metadata:
name: httpbin-compressor
namespace: default
spec:
workloadSelector:
app: httpbin
portNumber: 8080
compressor_library:
gzip:
compression_level: DEFAULT
window_bits: 12
memory_level: 5
response_direction_config:
common_config:
min_content_length: 256
content_type:
- application/json
- text/html
- text/plain
disable_on_etag_header: true
ASMCompressor fields
| Field | Type | Required | Description | Default |
|---|
workloadSelector | map\ | Yes | Labels that select the pods where compression is applied. The label scope is restricted to the namespace of the ASMCompressor resource. For more information, see WorkloadSelector. | -- |
isGateway | bool | No | Set to true to apply this configuration to a gateway instead of sidecar proxies. | false |
portNumber | int | Yes | The service port on which compression is applied. For gateways, this is the gateway service port. | -- |
compressor_library | CompressorLibrary | No | Compression algorithm settings for Gzip or Brotli. | -- |
request_direction_config | RequestDirectionConfig | No | Compression behavior for requests. | -- |
response_direction_config | ResponseDirectionConfig | No | Compression behavior for responses. | -- |
per_route_configs | ASMCompressorPerRouteConfig | No | Route-level compression overrides. Supported since ASM V1.21. | -- |
GzipCompressor fields
| Field | Type | Required | Description | Default |
|---|
window_bits | int | No | Window size for the compression buffer. Valid values: 9 to 15. Larger values improve the compression ratio but increase memory usage. | 12 |
compression_level | string | No | Trade-off between compression ratio and speed. Valid values: BEST (highest ratio, slowest), SPEED (lowest ratio, fastest), DEFAULT (balanced). | DEFAULT |
memory_level | int | No | Memory allocated to the internal compression state. Valid values: 1 to 9. Larger values speed up compression and improve output quality but increase memory usage. | 5 |
compression_strategy | string | No | The zlib compression strategy. Choose based on the characteristics of the data being compressed. For more information, see Compression strategies. | DEFAULT_STRATEGY |
Compression strategies
| Value | Description |
|---|
DEFAULT_STRATEGY | Automatically selected by zlib based on input data characteristics. Suitable for most use cases. |
FILTERED | Optimized for data that has been pre-processed by a filter. Typically used for multi-pass compression to increase the compression ratio. |
HUFFMAN_ONLY | Uses only Huffman coding without the LZ77 algorithm. Fastest strategy with the lowest compression ratio. |
RLE | Run-length encoding. Best suited for data with long sequences of repeated bytes. |
FIXED | Uses a fixed, predefined compression dictionary. Useful when the data follows known, predictable patterns. |
BrotliCompressor fields
| Field | Type | Required | Description | Default |
|---|
window_bits | int | No | Window size for the compression buffer. Valid values: 10 to 24. Larger values improve the compression ratio but increase memory usage. | 18 |
quality | int | No | Compression quality level. Valid values: 0 to 11. Higher values produce smaller output but take longer to compress. | 3 |
RequestDirectionConfig fields
| Field | Type | Required | Description | Default |
|---|
common_config | CommonConfig | No | Filter behavior for request compression. | -- |
ResponseDirectionConfig fields
| Field | Type | Required | Description | Default |
|---|
common_config | CommonConfig | No | Filter behavior for response compression. | -- |
disable_on_etag_header | bool | No | If true, skip compression when the response includes an ETag header. This preserves the ETag for caching purposes. | false |
remove_accept_encoding_header | bool | No | If true, strip the Accept-Encoding header from the request before forwarding to the upstream service. This prevents the upstream from compressing the response, so that the Envoy filter handles compression instead. | false |
CommonConfig fields
| Field | Type | Required | Description | Default |
|---|
min_content_length | int | No | Minimum response body size in bytes to trigger compression. Very small responses may not benefit from compression. For Gzip, higher CPU cost comes with better compression ratios, so test different thresholds to balance performance and bandwidth. | -- |
content_type | string[] | No | MIME types eligible for compression. Only responses whose Content-Type matches an entry in this list are compressed. | See below |
Default content_type values:
application/javascript, application/json, application/xhtml+xml, image/svg+xml, text/css, text/html, text/plain, text/xml
ASMCompressorPerRouteConfig fields
Per-route configuration overrides the global compression settings for specific routes. For example, you can disable compression on a health-check route while keeping it enabled for all other traffic.
| Field | Type | Required | Description | Default |
|---|
route_match | RouteConfigurationMatch | Yes | Selects the route to which this override applies. | -- |
disabled | bool | Yes | Set to true to disable compression on the matched route. | false |
RouteConfigurationMatch fields
| Field | Type | Required | Description | Default |
|---|
portNumber | uint32 | No | Match a specific service port, or a specific server port in the Gateway. If omitted, all ports are matched. | -- |
portName | string | No | Match by the portName of a server in the Gateway. Only applies when the compression policy targets a gateway. | -- |
gateway | string | No | The Gateway to match, in namespace/name format. Only applies when the compression policy targets a gateway. Use with portName and portNumber to select a specific server within the Gateway. | -- |
vhost | CommonVirtualHostMatch | No | Match a specific virtual host. | -- |
name | string | No | Name of the Envoy route configuration to match. Requires familiarity with the underlying Envoy configuration. | -- |
CommonVirtualHostMatch fields
| Field | Type | Required | Description | Default |
|---|
name | string | No | The virtual host name generated by the control plane, in host:port format. The host value corresponds to the host field of the associated VirtualService or the service fully qualified domain name (FQDN) in the cluster. | -- |
route | CommonRouteMatch | No | Match a specific route within the virtual host. | -- |
CommonRouteMatch fields
| Field | Type | Required | Description | Default |
|---|
name | string | No | Route name to match. Default-generated routes are named default. If a VirtualService is configured, use the name of the HTTP route defined in the VirtualService. | -- |
action | string | No | Match routes by action type. Valid values: ROUTE, REDIRECT, DIRECT_RESPONSE, ANY. | ANY |