Envoy HTTP流量分割 流量镜像
来源:原创
时间:2019-11-30
作者:脚本小站
分类:云原生
流量分割:
动态调整权重来分格流量。
routes - match: {...} route: weight_clusters: {...} clusters: [] # 与当前路由关联的一个或多个集群, 必选参数; - name: ... # 集群名称; weight: ... # 集群权重, 取值范围为0至total_weight; metadata_match: {...} # 子集负载均衡器使用的端点元数据匹配条件, 可选参数, 仅用于上游集群中具有与此字段中设置的元数据匹配的元数 端点以进行流量分配; total_weight: ... # 总权重值, 默认为100; runtime_key_prefix: ... # 可选参数, 用于设定键前缀, 从而每个集群以“runtime_key_prefix+.+cluster[i].name”为其键名, 并能够以运行时 键值的方式为每个集群提供权重; 其中, cluster[i].name表示列表中第i个集群名称
示例:
admin: access_log_path: "/dev/null" address: socket_address: address: 0.0.0.0 port_value: 9901 static_resources: listeners: - address: socket_address: address: 0.0.0.0 port_value: 80 name: listener_http filter_chains: - filters: - name: envoy.http_connection_manager typed_config: "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager codec_type: auto stat_prefix: ingress_http route_config: name: local_route virtual_hosts: - name: vh_001 domains: ["*"] routes: - match: prefix: "/" route: weighted_clusters: clusters: - name: myapp-v1.5 weight: 90 - name: myapp-v1.6 weight: 10 total_weight: 100 runtime_key_prefix: routing.traffic_split http_filters: - name: envoy.router clusters: - name: myapp-v1.5 connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN http2_protocol_options: {} load_assignment: cluster_name: myapp-v1.5 endpoints: - lb_endpoints: - endpoint: address: socket_address: address: myapp-v1.5 port_value: 80 - name: myapp-v1.6 connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN http2_protocol_options: {} load_assignment: cluster_name: myapp-v1.6 endpoints: - lb_endpoints: - endpoint: address: socket_address: address: myapp-v1.6 port_value: 80
动态修改权重:
curl -XPOST 'http://172.20.0.7:9901/runtime_modify?routing.traffic_split.myapp-v1.5=0&routing.traffic_split.myapp-v1.6=100'
流量镜像:
将生产流量拷贝到测试集群或新版本集群上。
route: cluster|weighted_clusters: ... request_mirror_policy: cluster": "..." runtime_key": "..." # 快废弃的参数,使用runtime_fraction runtime_fraction": "{...}" default_value: # 运行时键值不可用时, 则使用此默认值; numerator: # 指定分子, 默认为0; denominator: # 指定分母, 小于分子时, 最终百分比为1; 分母可固定使用HUNDRED( 默认) 、 TEN_THOUSAND和MILLION; runtime_key: routing.request_mirror.KEY # 指定要使用的运行时键, 其值需要用户自定义
示例:
admin: access_log_path: "/dev/null" address: socket_address: address: 0.0.0.0 port_value: 9901 static_resources: listeners: - address: socket_address: address: 0.0.0.0 port_value: 80 name: listener_http filter_chains: - filters: - name: envoy.http_connection_manager typed_config: "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager codec_type: auto stat_prefix: ingress_http route_config: name: local_route virtual_hosts: - name: vh_001 domains: ["*"] routes: - match: prefix: "/" route: cluster: myapp-v1.5 request_mirror_policy: cluster: myapp-v1.6 runtime_fraction: default_value: numerator: 10 denominator: HUNDRED runtime_key: routing.request_mirror.myapp http_filters: - name: envoy.router clusters: - name: myapp-v1.5 connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN http2_protocol_options: {} load_assignment: cluster_name: myapp-v1.5 endpoints: - lb_endpoints: - endpoint: address: socket_address: address: myapp-v1.5 port_value: 80 - name: myapp-v1.6 connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN http2_protocol_options: {} load_assignment: cluster_name: myapp-v1.6 endpoints: - lb_endpoints: - endpoint: address: socket_address: address: myapp-v1.6 port_value: 80
修改流量比例:从前端来看依然是1.5在响应,从日志中就可以看到1.6的也在响应,说明一部分流量已近被拷贝到1.6中了。
curl -XPOST 'http://172.21.0.2:9901/runtime_modify?routing.request_mirror.myapp=50'