envoy源代码分析(四)--xDS配置API
概述
envoy配置分三种方式
文件,xDS,restful
xDS
分两个维度,四种组合
全量或者增量更新,单流或者多流更新。
在1.34.0里,只支持v3 API, v2已经废弃了。
全量发现请求
service.discovery.v3.DiscoveryRequest
全量发现响应
service.discovery.v3.DiscoveryResponse
增量发现请求
service.discovery.v3.DeltaDiscoveryRequest
增量发现响应
service.discovery.v3.DeltaDiscoveryResponse
配置参数校验
https://github.com/bufbuild/protoc-gen-validate
GRPC版本选择
通过阅读代码发现

有ENVOY-GRPC与GOOGLE-GRPC两种选择,官方文档推荐 envoy-grpc,
对应的配置API文档:https://www.envoyproxy.io/docs/envoy/v1.34.0/api-v3/config/core/v3/grpc_service.proto
官方文档针对版本选择的讨论:
https://www.envoyproxy.io/docs/envoy/v1.34.0/intro/arch_overview/other_protocols/grpc#arch-overview-grpc-services
对应的配置文件,这样写:

杂项
1 等待第一次初始化完成的超时时间
initial_fetch_timeout
默认15秒,0可以设成一直等下去。
2 listener更新
关键属性的更新会导致listener现有连接进入darining,超时时间有个选项--drain-time-s
https://www.envoyproxy.io/docs/envoy/v1.34.0/configuration/listeners/lds#config-listeners-lds
3 设置 SO_REUSEPORT 可以让UDP在多worker间通宿同源
In practice, UDP listeners are configured with the SO_REUSEPORT kernel option which will cause the kernel
to consistently hash each UDP 4-tuple to the same worker. This allows a UDP listener filter to be “session”
oriented if it so desires.
4 配置文件里的特殊语法 @type
见配置示例

这是一种泛型编程方法,是protobuf3中定义的。不过还是感觉示例中的写法有点多余。见:
https://protobuf.dev/programming-guides/proto3/#any
https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/any.proto
代码实现:
类型字符串是注册工厂类时候的名字, 见函数

见父类的定义,有个名字name和类型category

定义工厂的时候,进行赋值


又比如,default_local_address_selector的名字

其他
参考阅读:https://www.envoyproxy.io/docs/envoy/v1.34.0/api-docs/xds_protocol
浙公网安备 33010602011771号