higress
higress copied to clipboard
feat: implement apiToken failover mechanism
Ⅰ. Describe what this PR did
配置示例:
provider:
type: qwen
apiTokens:
- "api-token-1"
- "api-token-2"
- "api-token-3"
modelMapping:
'gpt-3': "qwen-turbo"
'gpt-4-turbo': "qwen-max"
'*': "qwen-turbo"
failover:
enabled: true
failureThreshold: 3
successThreshold: 1
healthCheckInterval: 5000
healthCheckTimeout: 5000
healthCheckModel: gpt-3
目前仅根据 HTTP 请求的响应状态码是否是 200 来判断 apiToken 是否可用,应该暂时用不到其他复杂的判断条件。
Ⅱ. Does this pull request fix one issue?
fixes https://github.com/alibaba/higress/issues/1227
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews
Question
目前还有两个问题:
-
- 由于 Envoy 会启动多个 Wasm VM,当前的故障切换和健康检测是每个 Wasm VM 分别去做的(也就是说 VM1 可能已经把某个 apiToken 移除了,但是 VM2 可能还会继续用这个 apiToken 进行请求),是否需要通过 proxywasm.SetSharedData 在多个 Wasm VM 间进行同步?如果同步的话会带来另一个问题,如果 apiToken 不可用时,多个 Wasm VM 会同时发起多个健康检测请求。
-
- 我需要发送请求到 envoy 本地监听的服务和端口来对 apiToken 做健康检测,目前我的做法是手动创建一个 cluster,指向 envoy 本地 Listen 的地址和端口,这样好像不太灵活,而且需要用户额外设置 cluster。有没有更好的方式?
healthCheckClient = wrapper.NewClusterClient(wrapper.StaticIpCluster{
ServiceName: "local_cluster",
Port: 10000,
})
- name: outbound|10000||local_cluster.static
connect_timeout: 0.25s
type: STATIC
load_assignment:
cluster_name: outbound|10000||local_cluster.static
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 10000