1

我想在路由配置中设置一些元数据,并将它们放在访问日志中。我知道该功能是https://github.com/envoyproxy/envoy/pull/4862

但是,我无法弄清楚如何编写yaml文件,我尝试了很多次,但它不起作用。

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }

static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 0.0.0.0, port_value: 10000 }
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        config:
          tracing:
              operation_name: ingress
          use_remote_address: true
          add_user_agent: true
          generate_request_id: true
          stat_prefix: ingress_http
          codec_type: AUTO
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/trace/1" }
                route: { cluster: some_serviceA }
                metadata:
                    filter_metadata:
                        envoy.http_connection_manager.access_log:
                            test: "this is metadata"
          http_filters:
          - name: envoy.router
          access_log:
          - name: envoy.http_grpc_access_log
            config:
                common_config:
                  grpc_service:
                    envoy_grpc:
                        cluster_name: accesslog_cluster
                  log_name: accesslog
  clusters:
  - name: some_serviceA
    connect_timeout: 0.25s
    lb_policy: ROUND_ROBIN
    type: STATIC
    hosts: [{ socket_address: { address: 127.0.0.1, port_value: 5001 }}]
  - name: accesslog_cluster
    connect_timeout: 2s
    hosts:
    - socket_address:
        address: 127.0.0.1
        port_value: 18090
    http2_protocol_options: {}

但是我从通用元数据中一无所获。

是否有将元数据设置为访问日志的示例?

4

1 回答 1

0

动态元数据可以通过使用 StreamInfo API(https://github.com/envoyproxy/envoy/blob/2e8ddf3f1821816bfb6ae93352fcc5dcddbb058f/include/envoy/stream_info/stream_info.h)的过滤器设置:setDynamicMetadata。

您也可以使用 Lua 进行设置:https ://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/lua_filter#config-http-filters-lua-stream-info-dynamic-metadata-wrapper

于 2019-07-15T22:21:10.540 回答