通过 Envoy 代理生成 UUID

Generate UUID via Envoy Proxy

我正在尝试使用以下 envoy 扩展在 x-request-id HTTP header

中关联一个 uuid
type.googleapis.com/envoy.extensions.request_id.uuid.v3.UuidRequestIdConfig

这是我的工作 yaml,只有一个 api 我通过 envoy

公开了
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        address: 0.0.0.0
        port_value: 10001
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: edge
          http_filters:
          - name: envoy.filters.http.router
          route_config:
            virtual_hosts:
            - name: direct_response_service
              domains: ["*"]
              routes:
              - match:
                  prefix: "/v1/hello"
                route:
                  cluster: cluster1        
  clusters:
  - name: cluster1
    connect_timeout: 5s
    load_assignment:
      cluster_name: cluster1
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 127.0.0.1
                port_value: 8080

我的问题是在上面的yaml中在哪里添加uuid生成的扩展

        typed_config:
          "@type": type.googleapis.com/envoy.extensions.request_id.uuid.v3.UuidRequestIdConfig
          pack_trace_reason: false

您必须将此扩展程序放入 HttpConnectionManager 配置中(在 request_id_extension 下):

static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 8080
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          codec_type: AUTO
          stat_prefix: ingress_http
          request_id_extension:
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.request_id.uuid.v3.UuidRequestIdConfig
              pack_trace_reason: false
...

我在此处的文档中找到了信息:https://www.envoyproxy.io/docs/envoy/v1.21.0/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto#extensions-filters-network-http-connection-manager-v3-httpconnectionmanager(在页面中搜索 request_id_extension)。

此属性在此处的原型文件中定义:https://github.com/envoyproxy/envoy/blob/v1.21.0/api/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto#L626-L642