Envoy Header-To-Metadata Filter

  • v2 API reference
  • This filter should be configured with the name envoy.filters.http.header_to_metadata.

This filter is configured with rules that will be matched against requests and responses. Each rule has a header and can be triggered either when the header is present or missing. When a rule is triggered, dynamic metadata will be added based on the configuration of the rule. The metadata can then be used for load balancing decisions, consumed from logs, etc.

A typical use case for this filter is to dynamically match requests with load balancer subsets. For this, a given header’s value would be extracted and attached to the request as dynamic metadata which would then be used to match a subset of endpoints.

Example

A sample filter configuration to route traffic to endpoints based on the presence or absence of a version header could be:

  1. http_filters:
  2. - name: envoy.filters.http.header_to_metadata
  3. config:
  4. request_rules:
  5. - header: x-version
  6. on_header_present:
  7. metadata_namespace: envoy.lb
  8. key: version
  9. type: STRING
  10. on_header_missing:
  11. metadata_namespace: envoy.lb
  12. key: default
  13. value: 'true'
  14. type: STRING
  15. remove: false

A corresponding upstream cluster configuration could be:

  1. clusters:
  2. - name: versioned-cluster
  3. type: EDS
  4. lb_policy: ROUND_ROBIN
  5. lb_subset_config:
  6. fallback_policy: ANY_ENDPOINT
  7. subset_selectors:
  8. - keys:
  9. - default
  10. - keys:
  11. - version

This would then allow requests with the x-version header set to be matched against endpoints with the corresponding version. Whereas requests with that header missing would be matched with the default endpoints.

Statistics

Currently, this filter generates no statistics.