How to modify headers

Installing the demo program

If you haven’t installed the demo program yet, Please refer to Quick Start to install Aeraki, Istio, and the demo.

After installation, you can see that the following two NSs have been added to the cluster, and the Dubbo and Thrift demo applications are installed in these two NSs. You can choose either of them to test.

  1. ~ kubectl get ns|grep meta
  2. meta-dubbo Active 16m
  3. meta-thrift Active 16m

Modify the request header

Aeraki supports header mutation. For example, we can use the following MetaRouter to modify the request message header.

Note: Aeraki and MetaProtocol framework support header mutation. Whether a certain application protocol supports header mutation depends on the implementation of the codec of that protocol. To support header modification, the codec implementation needs to get out the key/value pairs in the mutation structure and wrriten them into the outgoing message during the encoding phase.

Create a MetaRouter rule and add two message headers foo/bar, foo1/bar1 in the requestMutation part:

  1. kubectl apply -f- <<EOF
  2. apiVersion: metaprotocol.aeraki.io/v1alpha1
  3. kind: MetaRouter
  4. metadata:
  5. name: test-metaprotocol-thrift-route
  6. namespace: meta-thrift
  7. spec:
  8. hosts:
  9. - thrift-sample-server.meta-thrift.svc.cluster.local
  10. routes:
  11. - name: header-mutation
  12. route:
  13. - destination:
  14. host: thrift-sample-server.meta-thrift.svc.cluster.local
  15. requestMutation:
  16. - key: foo
  17. value: bar
  18. - key: foo1
  19. value: bar1
  20. EOF

Use the aerakictl command to view the client-side log, you can see the added header:

  1. ~ aerakictl_sidecar_enable_debug client meta-thrift
  2. ~ aerakictl_sidecar_log client meta-thrift --tail 0 -f|grep mutation
  3. 2022-03-10T06:42:25.605305Z info envoy filter thrift: codec mutation foo : bar
  4. 2022-03-10T06:42:25.605316Z info envoy filter thrift: codec mutation foo1 : bar1

Understand what happened

In the configuration delivered to the Sidecar Proxy, Aeraki sets the MetaProtocol Proxy in the FilterChain of the Outbound Listener corresponding to the service, and specifies Aeraki as the RDS server in the MetaProtocol Proxy configuration.

Aeraki will translate the routing rules configured in MetaRouter into the routing rules of MetaProtocol Proxy, and send them to MetaProtocol Proxy through Aeraki’s built-in RDS server.

You can view the configuration of the sidecar proxy with the following command:

  1. aerakictl_sidecar_config client meta-thrift |fx

The MetaProtocol Proxy configuration in the Outbound Listener of the Thrift service is as follows:

  1. {
  2. "name": "envoy.filters.network.meta_protocol_proxy",
  3. "typed_config": {
  4. "@type": "type.googleapis.com/udpa.type.v1.TypedStruct",
  5. "type_url": "type.googleapis.com/aeraki.meta_protocol_proxy.v1alpha.MetaProtocolProxy",
  6. "value": {
  7. "stat_prefix": "outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local",
  8. "application_protocol": "thrift",
  9. "rds": {
  10. "config_source": {
  11. "api_config_source": {
  12. "api_type": "GRPC",
  13. "grpc_services": [
  14. {
  15. "envoy_grpc": {
  16. "cluster_name": "aeraki-xds"
  17. }
  18. }
  19. ],
  20. "transport_api_version": "V3"
  21. },
  22. "resource_api_version": "V3"
  23. },
  24. "route_config_name": "thrift-sample-server.meta-thrift.svc.cluster.local_9090"
  25. },
  26. "codec": {
  27. "name": "aeraki.meta_protocol.codec.thrift"
  28. },
  29. "meta_protocol_filters": [
  30. {
  31. "name": "aeraki.meta_protocol.filters.router"
  32. }
  33. ]
  34. }
  35. }
  36. }

You can also view the RDS routing information that is currently in effect in the Proxy in the exported file, and you can catch sight of that the corresponding header is added to the routing, as shown below:

  1. {
  2. @type": "type.googleapis.com/aeraki.meta_protocol_proxy.admin.v1alpha.RoutesConfigDump",
  3. dynamic_route_configs": [
  4. {
  5. "version_info": "1641896797",
  6. "route_config": {
  7. "@type": "type.googleapis.com/aeraki.meta_protocol_proxy.config.route.v1alpha.RouteConfiguration",
  8. "name": "thrift-sample-server.meta-thrift.svc.cluster.local_9090",
  9. "routes": [
  10. {
  11. "name": "header-mutation",
  12. "route": {
  13. "cluster": "outbound|9090||thrift-sample-server.meta-thrift.svc.cluster.local"
  14. },
  15. "request_mutation": [
  16. {
  17. "key": "foo",
  18. "value": "bar"
  19. },
  20. {
  21. "key": "foo1",
  22. "value": "bar1"
  23. }
  24. ]
  25. }
  26. ]
  27. },
  28. "last_updated": "2022-03-10T06:26:24.083Z"
  29. }
  30. ]
  31. },
  32. "last_updated": "2022-01-11T10:26:37.357Z"
  33. }

Last modified May 23, 2022: 增加 v1.1 文档目录 (431bf1a)