Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Polaris go sdk to support their service governance ability. #421

Closed
jayantxie opened this issue Apr 21, 2022 · 9 comments
Closed
Assignees
Labels
enhancement New feature or request proposal A proposal need to discuss and will do implementation.

Comments

@jayantxie
Copy link
Member

jayantxie commented Apr 21, 2022

为方便Kitex用户上云,计划对接腾讯的开源服务治理平台Polaris,通过集成go sdk,满足诸如服务注册发现、熔断限流和动态路由等Polaris平台的治理能力。目前已实现的功能有服务的注册发现,contrib仓库链接 -> registry-polaris

分点描述各部分能力与Kitex集成的方案:

  1. 熔断降级:
    Polaris对熔断的实现是请求结束后,调用consumer接口上报单实例请求结果,再在选择实例时剔除故障实例,参考使用故障熔断。在registry-polaris中,已经完成了服务发现的接入,因此,只需要再添加上报ServiceCallResult的Middleware即可。

  2. 限流:
    feat: extend outside limiter implementation and fix problems of rate limiter of multiplexed server #431 中,扩展支持了外部限流器的实现,在代码中可通过WithConcurrencyLimiterWithQPSLimiter传入限流器。

注:这里之所以不用middleware,是为了尽量让限流的生效时机提前,在所以middleware执行前便触发其执行。

  1. 动态路由&负载均衡:
    gRPC接入类似,Kitex框架扩展Resolver和Balancer,在Resolver中解析出所有的服务实例。
    type Resolver interface {

    这个实现可以保留contrib仓库registry-polaris的实现。
    动态路由和负载均衡的逻辑需要嵌入到LoadBalancer的实现内。目前Kitex框架默认的weightedBalancerweightedPicker需要换成Polaris的实现。细节是:

i. 自定义polarisBalancer实现Loadbalancer接口,并把传入的discovery.Result转换为Polaris的ServiceInstances对象,写入内存缓存,并在每次Rebalance时重新赋值;
ii. 从对象池中获取polarisPicker,并填充serviceInstances字段,作为后续调用picker.Next()函数获取实例的实例池;
iii. 在Next函数内实现动态路由和负载均衡的能力,均由Polaris暴露的sdk函数提供。其中动态路由只在第一次调用Next时执行,得到结果后写入picker的缓存。
这样,在部分实例故障无法建立连接需要重试时,不会每次重新选择实例都要执行一遍路由的逻辑,可以减少计算开销。

注:Kitex服务发现Middleware代码位置:

lb, err := balancerFactory.Get(ctx, dest)

注:对接Polaris注册发现的仓库命名为registry-polaris, 如果在这上面集成治理特性似乎不太合适建议新建个仓库就叫kitex-contrib/polaris,把原本registry-polaris仓库的代码复制过去,再集成这次issue的治理特性,后续可以只维护kitex-contrib/polaris这个仓库。

@jayantxie
Copy link
Member Author

需要考虑一点:为避免冲突,需要关闭框架侧支持的熔断机制,在接入的时候避免调用WithCircuitBreaker

@jayantxie
Copy link
Member Author

另外,Polaris没有接入重试机制,可以在contrib仓库中提供基本的重试策略方便用户配置。

@YangruiEmma
Copy link
Member

限流不建议通过mw添加,可以扩展limiter接口

@andrewshan
Copy link

andrewshan commented May 4, 2022

其他都没有太大问题,路由和负载均衡这部分,我建议通过以下思路进行对接:
当前GO SDK的接口都是一体化接口,并没有像Java那样做拆分,所以和框架对接存在一定的问题,需要调用内部接口才可以解耦。
因此,北极星GO SDK也打算提供RouterAPI,用于和框架对接,计划提供2个接口:polarismesh/polaris-go#52

这2个接口,北极星这边会开发,五一后会提供

@jayantxie
Copy link
Member Author

@andrewshan 重新修改了实现,按目前的接口只需要在picker.Next()函数内同时集成动态路由和负载均衡的逻辑即可。Kitex扩展需要支持Resolver/LoadBalancer/Picker三个接口。

@andrewshan
Copy link

@jayantxie 按照你的新实现,使用哪些接口呢?

@jayantxie
Copy link
Member Author

@andrewshan 需要用到ProcessRouters和ProcessLoadBalance

@andrewshan
Copy link

routerAPI已经发起PR,可以看看@jayantxie

@debug-LiXiwen
Copy link
Contributor

Hi, I want to choose module 🙌🏻

@GuangmingLuo GuangmingLuo added proposal A proposal need to discuss and will do implementation. and removed help wanted Extra attention is needed labels Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request proposal A proposal need to discuss and will do implementation.
Development

No branches or pull requests

7 participants