Envoy HTTP路由配置框架

route_config所在配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto#extension-envoy-filters-network-http-connection-manager

static_resources:
  listeners: 
    name: ...
    address: {...}
    additional_addresses: []
    stat_prefix: ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: 
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            codec_type: ...
            stat_prefix: ...
            rds: {...}
            route_config: {...}   # route配置段
            scoped_routes: {...}
            http_filters: []
            add_user_agent: {...}
            tracing: {...}
            common_http_protocol_options: {...}
            http_protocol_options: {...}
            http2_protocol_options: {...}
            server_name: ...
            server_header_transformation: ...
            scheme_header_transformation: {...}
            max_request_headers_kb: {...}
            stream_idle_timeout: {...}
            request_timeout: {...}
            request_headers_timeout: {...}
            drain_timeout: {...}
            delayed_close_timeout: {...}
            access_log: []
            use_remote_address: {...}
            xff_num_trusted_hops: ...
            original_ip_detection_extensions: []
            internal_address_config: {...}
            skip_xff_append: ...
            via: ...
            generate_request_id: {...}
            preserve_external_request_id: ...
            always_set_request_id_in_response: ...
            forward_client_cert_details: ...
            set_current_client_cert_details: {...}
            proxy_100_continue: ...
            upgrade_configs: []
            normalize_path: {...}
            merge_slashes: ...
            path_with_escaped_slashes_action: ...
            request_id_extension: {...}
            local_reply_config: {...}
            strip_matching_host_port: ...
            strip_any_host_port: ...
            stream_error_on_invalid_http_message: {...}
            strip_trailing_host_dot: ...
            proxy_status_config: {...}

route_config配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route.proto#envoy-v3-api-msg-config-route-v3-routeconfiguration

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts: []
              vhds: {...}
              internal_only_headers: []
              response_headers_to_add: []
              response_headers_to_remove: []
              request_headers_to_add: []
              request_headers_to_remove: []
              most_specific_header_mutations_wins: ...
              validate_clusters: {...}
              max_direct_response_body_size_bytes: {...}
              cluster_specifier_plugins: []
              request_mirror_policies: []
              ignore_port_in_host_matching: ...
              ignore_path_parameters_in_path_matching: ...
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

virtual_hosts配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-virtualhost

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...                           # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []                         # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes: []                          # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                matcher: {...}
                require_tls: ...                    # 指定虚拟主机期望的 TLS 强制类型。如果未指定此选项,则虚拟主机没有 TLS 要求。
                virtual_clusters: []                # 为此虚拟主机定义的虚拟集群列表。虚拟集群用于额外的统计数据收集。
                rate_limits: []                     # 指定一组将应用于虚拟主机的速率限制配置。
                request_headers_to_add: []          # 指定应该添加到此虚拟主机处理的每个请求的 HTTP 标头列表。
                request_headers_to_remove: []       # 指定应从该虚拟主机处理的每个请求中删除的 HTTP 标头列表。
                response_headers_to_add: []         # 指定应该添加到此虚拟主机处理的每个响应的 HTTP 标头列表。
                response_headers_to_remove: []      # 指定应从该虚拟主机处理的每个响应中删除的 HTTP 标头列表。
                cors: {...}                         # 虚拟主机 CORS 策略。
                typed_per_filter_config: {...}      # per_filter_config 字段可用于为过滤器提供虚拟主机特定的配置。
                include_request_attempt_count: ...  # 决定是否应将x-envoy-attempt-count标头包含在上游请求中。设置此选项将导致它覆盖任何现有的标头值,因此在启用此选项的请求路径上有两个 Envoy 的情况下,上游将看到第二个 Envoy 感知到的尝试计数。默认为假。此标头不受 suppress_envoy_headers标志的影响。
                include_attempt_count_in_response: ...  # 决定是否应将x-envoy-attempt-count标头包含在下游响应中。设置此选项将导致路由器覆盖任何现有的标头值,因此在启用此选项的请求路径上有两个 Envoy 的情况下,下游将看到距离自身最近的上游的 Envoy 感知到的尝试计数。默认为假。此标头不受 suppress_envoy_headers标志的影响。
                retry_policy: {...}                 # 表示此虚拟主机中所有路由的重试策略。请注意,设置路由级别条目将优先于此配置,并且将被独立处理(例如:值不被继承)。
                hedge_policy: {...}                 
                per_request_buffer_limit_bytes: {...}
                request_mirror_policies: []         # 为该虚拟主机下的每条路由指定一组默认请求镜像策略。
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

routes配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-route

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...  # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: [] # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:    # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                  route: {...} # 常用内嵌字段cluster|cluster_header|weighted_clusters,基于集群、请求报文中的集群标头或加权集群(流量分割)定义路由目标;
                  redirect: {...} # 重定向请求,但不可与route或direct_response一同使用;
                  direct_response: {...} # 直接响应请求,不可与route和redirect一同使用;
                  metadata: {...}
                  decorator: {...}
                  typed_per_filter_config: {...}
                  request_headers_to_add: []
                  request_headers_to_remove: []
                  response_headers_to_add: []
                  response_headers_to_remove: []
                  tracing: {...}
                  per_request_buffer_limit_bytes: {...}
                  stat_prefix: ...
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

route配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-routeaction

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...   # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: [] # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:      # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                  route:    # 常用内嵌字段cluster|cluster_header|weighted_clusters,基于集群、请求报文中的集群标头或加权集群(流量分割)定义路由目标;
                    cluster: ...
                    cluster_header: ...
                    weighted_clusters: {...}
                    cluster_specifier_plugin: ...
                    inline_cluster_specifier_plugin: {...}
                    cluster_not_found_response_code: ...
                    metadata_match: {...} # 子集负载均衡器使用的端点元数据匹配条件;
                    prefix_rewrite: ...  # 前缀重写,即将下游请求的path转发至上游主机时重写为另一个path;
                    regex_rewrite: {...}
                    host_rewrite_literal: ...
                    auto_host_rewrite: {...} # 自动主机头重写,仅适用于strict_dns或logical_dns类型的集群;
                    host_rewrite_header: ...
                    host_rewrite_path_regex: {...}
                    append_x_forwarded_host: ...
                    timeout: {...} # 上游超时时长,默认为15s;
                    idle_timeout: {...} # 路由的空间超时时长,未指定时表示不超时;
                    early_data_policy: {...}
                    retry_policy: {...} # 重试策略,优先于虚拟主机级别的重试策略;
                    request_mirror_policies: [] # 指定一组路由请求镜像策略。
                    priority: ...  # 路由优先级;
                    rate_limits: [] # 速率限制;
                    include_vh_rate_limits: {...}
                    hash_policy: [] # 上游集群使用环哈希算法时为其指定用于环形哈希负载均衡的哈希策略表;通常哈希计算的目标 是指定的标头、cookie或者请求报文的源IP地址;
                    cors: {...}  # 跨域资源共享(Cross Origin Resource Sharing);
                    max_grpc_timeout: {...}
                    grpc_timeout_offset: {...}
                    upgrade_configs: []
                    internal_redirect_policy: {...}
                    internal_redirect_action: ...
                    max_internal_redirects: {...}
                    hedge_policy: {...}
                    max_stream_duration: {...}
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

match配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-routematch

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...    # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []  # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:    # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                    prefix: ...
                    path: ...
                    safe_regex: {...}
                    connect_matcher: {...}
                    path_separated_prefix: ...
                    case_sensitive: {...}
                    runtime_fraction: {...}
                    headers: []
                    query_parameters: []
                    grpc: {...}
                    tls_context: {...}
                    dynamic_metadata: []
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

headers配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-headermatcher

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...      # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []    # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:        # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                    ...
                    headers:
                      name: ...
                      exact_match: ...          # 精确值匹配
                      safe_regex_match: {...}   # 正则表达式模式匹配
                      range_match: {...}        # 值范围匹配,检查标头值是否在指定的范围内
                      present_match: ...        # 标头存在性匹配,检查标头存在与否
                      prefix_match: ...         # 值前缀匹配
                      suffix_match: ...         # 值后缀匹配
                      contains_match: ...       # 检测标头值是否包含此处指定的字符串
                      string_match: {...}       # 检测标头值是否匹配该处指定的字符串
                      invert_match: ...  # 是否将匹配的检测结果取反,即以不满足条件为”真”,默认为fase
                      treat_missing_header_as_empty: ...  # 如果标头匹配规则指定的标头不存在,则此标头值将被视为空,默认为fase
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

query_parameters配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-queryparametermatcher

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...      # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []   # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:   # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                    ...
                    query_parameters:
                      name: ...
                      string_match: # 参数值的字符串匹配检查,支持使用以下五种检查方式其中之一进行字符串匹配
                        exact: ...
                        prefix: ...
                        suffix: ...
                        safe_regex: {...}  
                        contains: ...
                        ignore_case: ...
                      present_match: ...
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

redirect配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-redirectaction

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...     # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []   # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes: # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  redirect:
                    https_redirect: ...
                    scheme_redirect: ...
                    host_redirect: ...
                    port_redirect: ...
                    path_redirect: ...
                    prefix_rewrite: ...
                    regex_rewrite: {...}
                    response_code: ...
                    strip_query: ...
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

direct_response配置段

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-directresponseaction

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...   # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: [] # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:  # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  direct_response:
                    status: ...
                    body: 
                      inline_bytes: ...       # 直接给出的内联字节
                      inline_string: ...      # 直接给出的内联字符串
                      environment_variable: ...  # 环境变量数据源
                      filename: ...      # 本地文件数据源。必须设置filename、inline_bytes、inline_string、environment_variable之一。
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

流量迁移

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/base.proto#envoy-v3-api-msg-config-core-v3-runtimefractionalpercent

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...    # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []  # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:    # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                    prefix: ...
                    path: ...
                    safe_regex: {...}
                    connect_matcher: {...}
                    path_separated_prefix: ...
                    case_sensitive: {...}
                    runtime_fraction: # 额外匹配指定的运行时键值,每次评估匹配路径时,它必需低于此字段指示的匹配百分比;支持渐进式修改;
                      default_value:  # 运行时键值不可用时,则使用此默认值;
                        numerator: ... # 指定分子,默认为0;
                        denominator: ... # 指定分母,小于分子时,最终百分比为1;分母可固定使用HUNDRED(默认 100)、TEN_THOUSAND(10000)和MILLION(1000000);
                      runtime_key: ...    # 指定要使用的运行时键,其值需要用户自定义
                    headers: []
                    query_parameters: []
                    grpc: {...}
                    tls_context: {...}
                    dynamic_metadata: []
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

流量分割

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-weightedcluster

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          @type: type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...   # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: [] # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:      # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                  route:    # 常用内嵌字段cluster|cluster_header|weighted_clusters,基于集群、请求报文中的集群标头或加权集群(流量分割)定义路由目标;
                    cluster: ...
                    cluster_header: ...
                    weighted_clusters: 
                      clusters:  # 与当前路由关联的一个或多个集群,必选参数;
                        name: ...  # 目标集群名称;也可以使用“cluster_header”字段来指定集群;二者互斥;
                        cluster_header: ...
                        weight: {...}  # 集群权重,取值范围为0至total_weight;
                        metadata_match: {...}  # 子集负载均衡器使用的端点元数据匹配条件,可选参数,仅用于上游集群中具有与此字段中设置的元数据匹配的元数端点以进行流量分配;
                        request_headers_to_add: []
                        request_headers_to_remove: []
                        response_headers_to_add: []
                        response_headers_to_remove: []
                        typed_per_filter_config: {...}
                        host_rewrite_literal: ...
                      total_weight: {...}  # 总权重值,默认为100;
                      runtime_key_prefix: ... # 可选参数,用于设定键前缀,从而每个集群以“runtime_key_prefix+.+cluster[i].name”为其键名,并能够以运行时键值的方式为每个集群提供权重;其中,cluster[i].name表示列表中第i个集群名称;
                      header_name: ...
                   ...
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

流量镜像

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-routeaction-requestmirrorpolicy

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          @type: type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...   # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: [] # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:      # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                  route:    # 常用内嵌字段cluster|cluster_header|weighted_clusters,基于集群、请求报文中的集群标头或加权集群(流量分割)定义路由目标;
                    ...
                    request_mirror_policies: [] # 指定一组路由请求镜像策略。
                      cluster: ...   # cluster和cluster_header二选一
                      cluster_header: ... # cluster和cluster_header二选一
                      runtime_fraction: 
                        default_value:  # 运行时键值不可用时,则使用此默认值;
                          numerator: ... # 指定分子,默认为0;
                          denominator: ... # 指定分母,小于分子时,最终百分比为1;分母可固定使用HUNDRED(默认 100)、TEN_THOUSAND(10000)和MILLION(1000000);
                        runtime_key: ...    # 指定要使用的运行时键,其值需要用户自定义
                      trace_sampled: {...}  # 是否对trace span进行采样,默认为true
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

请求重试

https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-retrypolicy

路由级别的请求重试

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...   # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: [] # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes:      # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  name: ...                                 
                  match: {...} # 常用内嵌字段 prefix|path|sate_regex|connect_matcher,用于定义基于路径前缀、路径、正则表达式或连接匹配器四者之一定义匹配条件;
                  route:    # 常用内嵌字段cluster|cluster_header|weighted_clusters,基于集群、请求报文中的集群标头或加权集群(流量分割)定义路由目标;
                    ...
                    retry_policy: {...} # 重试策略,优先于虚拟主机级别的重试策略;
                      retry_on: ...     # 重试发生的条件,其功能同x-envoy-retry-on和x-envoy-retry-grpc-on标头相同;
                      num_retries: {...}  # 重试次数,默认值为1,其功能同x-envoy-max-retries标头相同,但采用二者中配置的最大值;
                      per_try_timeout: {...} # 每次重试时同上游端点建立连接的超时时长;
                      per_try_idle_timeout: {...}  # 指定每次重试尝试(包括初始尝试)的上游空闲超时。此参数是可选的,如果不存在,则没有每次尝试空闲超时。
                      retry_priority: {...}   # 配置重试优先级策略,用于在各优先级之间分配负载;
                      retry_host_predicate: [] # 重试时使用的主机断言(predicate)列表,各断言用于拒绝主机;在选择重试主机时将参考该列表中的各断言,若存在任何谓词拒绝了该主机,则需要重新尝试选择其它主机
                      retry_options_predicates: []
                      host_selection_retry_max_attempts: ...  # 允许尝试重新选择主机的最大次数,默认为1;
                      retriable_status_codes: []  # 除了retry_on指定的条件之外,用于触发重试操作的http状态码列表;
                      retry_back_off: {...}  # 配置用于控制回退算法的参数,默认基本间隔为25ms,给定基本间隔B和重试次数N,重试的退避范围为 [0,(2^N−1)B),最大间隔默认为基本间隔(250ms)的10倍;
                      rate_limited_retry_back_off: {...}  # 定义控制重试回退策略的参数;
                      retriable_headers: []   # 触发重试的HTTP响应标头列表,上游端点的响应报文与列表中的任何标头匹配时将触发重试;
                      retriable_request_headers: [] # 必须在用于重试的请求报文中使用的HTTP标头列表;
                    ...
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

虚拟主机级别的请求重试

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                name: ...                           # 虚拟主机的逻辑名称。这在发出某些统计信息时使用,但与路由无关。
                domains: []                         # 虚拟主机的域名,路由匹配时将请求报文中的host标头值与此处列表项进行匹配检测;
                routes: []                          # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                matcher: {...}
                require_tls: ...                    # 指定虚拟主机期望的 TLS 强制类型。如果未指定此选项,则虚拟主机没有 TLS 要求。
                virtual_clusters: []                # 为此虚拟主机定义的虚拟集群列表。虚拟集群用于额外的统计数据收集。
                rate_limits: []                     # 指定一组将应用于虚拟主机的速率限制配置。
                request_headers_to_add: []          # 指定应该添加到此虚拟主机处理的每个请求的 HTTP 标头列表。
                request_headers_to_remove: []       # 指定应从该虚拟主机处理的每个请求中删除的 HTTP 标头列表。
                response_headers_to_add: []         # 指定应该添加到此虚拟主机处理的每个响应的 HTTP 标头列表。
                response_headers_to_remove: []      # 指定应从该虚拟主机处理的每个响应中删除的 HTTP 标头列表。
                cors: {...}                         # 虚拟主机 CORS 策略。
                typed_per_filter_config: {...}      # per_filter_config 字段可用于为过滤器提供虚拟主机特定的配置。
                include_request_attempt_count: ...  # 决定是否应将x-envoy-attempt-count标头包含在上游请求中。设置此选项将导致它覆盖任何现有的标头值,因此在启用此选项的请求路径上有两个 Envoy 的情况下,上游将看到第二个 Envoy 感知到的尝试计数。默认为假。此标头不受 suppress_envoy_headers标志的影响。
                include_attempt_count_in_response: ...  # 决定是否应将x-envoy-attempt-count标头包含在下游响应中。设置此选项将导致路由器覆盖任何现有的标头值,因此在启用此选项的请求路径上有两个 Envoy 的情况下,下游将看到距离自身最近的上游的 Envoy 感知到的尝试计数。默认为假。此标头不受 suppress_envoy_headers标志的影响。
                retry_policy:                 # 表示此虚拟主机中所有路由的重试策略。请注意,设置路由级别条目将优先于此配置,并且将被独立处理(例如:值不被继承)。
                  retry_on: ...     # 重试发生的条件,其功能同x-envoy-retry-on和x-envoy-retry-grpc-on标头相同;
                  num_retries: {...}  # 重试次数,默认值为1,其功能同x-envoy-max-retries标头相同,但采用二者中配置的最大值;
                  per_try_timeout: {...} # 每次重试时同上游端点建立连接的超时时长;
                  per_try_idle_timeout: {...}  # 指定每次重试尝试(包括初始尝试)的上游空闲超时。此参数是可选的,如果不存在,则没有每次尝试空闲超时。
                  retry_priority: {...}   # 配置重试优先级策略,用于在各优先级之间分配负载;
                  retry_host_predicate: [] # 重试时使用的主机断言(predicate)列表,各断言用于拒绝主机;在选择重试主机时将参考该列表中的各断言,若存在任何谓词拒绝了该主机,则需要重新尝试选择其它主机
                  retry_options_predicates: []
                  host_selection_retry_max_attempts: ...  # 允许尝试重新选择主机的最大次数,默认为1;
                  retriable_status_codes: []  # 除了retry_on指定的条件之外,用于触发重试操作的http状态码列表;
                  retry_back_off: {...}  # 配置用于控制回退算法的参数,默认基本间隔为25ms,给定基本间隔B和重试次数N,重试的退避范围为 [0,(2^N−1)B),最大间隔默认为基本间隔(250ms)的10倍;
                  rate_limited_retry_back_off: {...}  # 定义控制重试回退策略的参数;
                  retriable_headers: []   # 触发重试的HTTP响应标头列表,上游端点的响应报文与列表中的任何标头匹配时将触发重试;
                  retriable_request_headers: [] # 必须在用于重试的请求报文中使用的HTTP标头列表;                
                hedge_policy: {...}                 
                per_request_buffer_limit_bytes: {...}
                request_mirror_policies: []         # 为该虚拟主机下的每条路由指定一组默认请求镜像策略。
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

CORS配置

--
  listeners: 
    ...
    filter_chains: 
      filter_chain_match: {...}
      filters: 
        name: ...
        typed_config: ...
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
            ...
            route_config:
              name: ...
              virtual_hosts:
                ...
                cors:  # 虚拟主机 CORS 策略。
                  "allow_origin_regex": [] # 正则表达式模式表示的允许共享的资源
                  "allow_methods": "..." # 允许资源访问时使用的HTTP方法列表,内容将被序列化到access-control-allow-methods标头;
                  "allow_headers": "..." # 允许在请求资源时使用HTTP标头列表,内容将被序列化到access-control-allow-headers标头;
                  "expose_headers": "..." # 浏览器可访问的HTTP标头白名单,内容将被序列化到access-control-expose-headers标头;
                  "max_age": "..." # 请求的缓存时长,内容将被序列化到access-control-max-age标头;
                  "allow_credentials": "{...}" # 布尔型值,是否允许服务调用方法使用凭据发起实际请求;
                  "enabled": "{...}" # 布尔型值,是否启用CORS,默认为启用;此参数即将启用,并由filter_enabled取代;
                  "filter_enabled": "{...}" # 是否启用CORS过滤器,若启用,此处需要定义启用此过滤器的请求百分比,默认为100/HUNDRED;
                  default_value:
                  numerator: ...
                  denominator: ...
                  runtime_key: ...
                  "shadow_enabled": "{...}" # 是否仅在阴影模式下启用过滤器的请求的百分比,若启用,其默认值为100/HUNDRED;若启用,它将评估请求的来源以确定其是否有效,但不强制执行任何策略;若同时启用了filter_enabled和shadow_enabled,则filter_enabled标志优先;
                routes:      # 路由条目,匹配到当前虚拟主机的请求中的path匹配检测将针对各route中由match定义条件进行;
                  ...
                  route:    # 常用内嵌字段cluster|cluster_header|weighted_clusters,基于集群、请求报文中的集群标头或加权集群(流量分割)定义路由目标;
                    ...
                    cors:  # 跨域资源共享(Cross Origin Resource Sharing);
                      "allow_origin_regex": [] # 正则表达式模式表示的允许共享的资源
                      "allow_methods": "..." # 允许资源访问时使用的HTTP方法列表,内容将被序列化到access-control-allow-methods标头;
                      "allow_headers": "..." # 允许在请求资源时使用HTTP标头列表,内容将被序列化到access-control-allow-headers标头;
                      "expose_headers": "..." # 浏览器可访问的HTTP标头白名单,内容将被序列化到access-control-expose-headers标头;
                      "max_age": "..." # 请求的缓存时长,内容将被序列化到access-control-max-age标头;
                      "allow_credentials": "{...}" # 布尔型值,是否允许服务调用方法使用凭据发起实际请求;
                      "enabled": "{...}" # 布尔型值,是否启用CORS,默认为启用;此参数即将启用,并由filter_enabled取代;
                      "filter_enabled": "{...}" # 是否启用CORS过滤器,若启用,此处需要定义启用此过滤器的请求百分比,默认为100/HUNDRED;
                      default_value:
                      numerator: ...
                      denominator: ...
                      runtime_key: ...
                      "shadow_enabled": "{...}" # 是否仅在阴影模式下启用过滤器的请求的百分比,若启用,其默认值为100/HUNDRED;若启用,它将评估请求的来源以确定其是否有效,但不强制执行任何策略;若同时启用了filter_enabled和shadow_enabled,则filter_enabled标志优先;
            http_filters:
            - name: envoy.filters.http.router
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
            - name: envoy.filters.http.cors
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors

 

posted @ 2022-08-30 16:57  小吉猫  阅读(432)  评论(0编辑  收藏  举报