Coder Social home page Coder Social logo

polarismesh / polaris-go Goto Github PK

View Code? Open in Web Editor NEW
119.0 4.0 54.0 87.75 MB

Lightweight Go SDK used as Proxyless Service Governance

License: Other

Go 99.40% Python 0.29% Shell 0.31%
fault-tolerance health-check rate-limit authenticate traffic-control load-balance circuit-break service-register request-route service-discover

polaris-go's People

Contributors

alexwanglei avatar andrewshan avatar chuntaojun avatar daheige avatar dinofei avatar enjoyliu avatar houseme avatar huyuanxin avatar lepdou avatar liu-song avatar mason51 avatar mi-cool avatar movebean avatar onecer avatar pemako avatar qdsordinarydream avatar ranchowang avatar reallovelei avatar samshan08 avatar shichaoyuan avatar sixwaaaay avatar skyebefreeman avatar wenxuan70 avatar wtifs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

polaris-go's Issues

bug: some internal addresses has exposed will get some risk

Describe the bug
polaris-go has config some internal server addresses on code, which need to be remove

To Reproduce
NewConsumerAPI, without passing any parameters, it will auto connect to the internal server addresses

Expected behavior
if user not passing any server address, sdk will return an error

Environment

  • Version: v0.9.0
  • OS: any

Additional context
Add any other context about the problem here.

SDK中的 Configuration 的所有参数都需要做检查校验

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • Version: [e.g. v1.0.0]
  • OS: [e.g. CentOS8]

Additional context
Add any other context about the problem here.

动态路由规则远程配置匹配问题

Describe the bug
请求标签的key、value均为*时,无法匹配到机器
举例子:有env:prod, env:dev的2个实例
命名空间、服务名 配置为 *
请求标签也均配置为 *

To Reproduce

  1. 有env:prod, env:dev的2个实例
  2. 命名空间、服务名 配置为 *
    请求标签也均配置为 *
  3. req不设置目标服务的tag,也不设置sourceService的信息
  4. 在启动访问的时候无法匹配到规则
  5. 报错Polaris-1012(ErrCodeRouteRuleNotMatch): route rule not match, rule status: dstRuleFail, sourceService nil, used variables map[], dstService {service: echo, namespace: Polaris}, notMatchedSource is {"sources":[{"service":"","namespace":"","metadata":{"":{"type":"REGEX","value":""}}},{"service":"","namespace":"","metadata":{"lxw":{"value":"1"}}}]}, invalidRegexSource is {}, matchedSource is {}, notMatchedDestination is {}, invalidRegexDestination is {}, zeroWeightDestination is {}, regexCompileErrors is {}, please check your route rule of service Polaris:echo

Expected behavior
req不设置目标服务的tag,可以根据远程规则正确匹配

Environment

  • Version: v1.2.0-beta.0
  • OS: MAC

support get location in tencent cloud env

What is the feature you want to add?

Whether in CVM or Container, you can automatically obtain the geographic information of the cloud environment where the current SDK is located

Why do you want to add this feature?

Support the nearest routing function in the cloud environment

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

feat: support standalone server access

What is the feature you want to add?
sdk can use the inputed server address to do all operations, no need to relay on the polaris.discover and polaris.healthcheck

Why do you want to add this feature?
when user use sdk with the standalone server, it won't register the polaris.discover and polaris.healthcheck

How to implement this feature?
in sdk side, when user not input the service address, it won't connect to the service

Additional context
Add any other context or screenshots about the feature request here.

服务不存在时,不抛错误,只返回空实例列表

2022-09-07T09:41:20.827180Z error controller/controller.go:829 Get service instances from polaris of service [bookinfo/details] error Polaris-1006(ErrCodeServerUserError): multierrs received for GetInstances request, serviceKey: {namespace: "bookinfo", service: "details"}, cause: 1 error occurred:
* SDKError for {ServiceKey: {namespace: "bookinfo", service: "details"}, Operation: destinationInstances}, detail is Polaris-1015(ErrCodeServiceNotFound): service {namespace: "bookinfo", service: "details", event: instance} not found

太多错误,会干扰用户的判断

## 北极星SDK获取所处地理位置信息流程

  ## 北极星SDK获取所处地理位置信息流程

背景:就近路由

新的SDK获取所处地理位置信息流程,将由两个插件组成插件链:local -> remote

  • local插件:直接配置 region、zone、campus 的信息,该信息配置在 polaris.yaml 配置,支持环境变量占位符
  • remoteHttp插件:目前仅支持 http 协议进行获取,该信息配置在 polaris.yaml 中,region、zone、campus 各自配置自己的远程调用请求, 响应结果直接作为 region、zone、campus 的值
  • remoteService插件:根据北极星服务端的ReportClient接口实现一个grpc服务,用于SDK上报获取地理位置信息
#描述:全局配置项
global:
  location:
    providers:
    - name: xxx
      type: local
      region: ${REGION}
      zone: ${ZONE}
      campus: ${CAMPUS}
    - name: xxx
      type: remoteHttp
      region: http://127.0.0.1/region
      zone: http://127.0.0.1/zone
      campus: http://127.0.0.1/campus
    - name: xxx
      type: remoteService
      address: grpc://xxx

_Originally posted by @chuntaojun in https://github.com/polarismesh/polaris/discussions/655#discussioncomment-3643039_
    

support disable local cache feature

What is the feature you want to add?
use can config to disable local cache, then no cache dir will be created

Why do you want to add this feature?
when running unit tests, the local cache will make the package dirty, and make result confuse

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

support fetch all the services from polaris

What is the feature you want to add?

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

promethues监控下调用方和被调用方未区分

Describe the bug
prometheus监控下被调用方和调用方取值相同
image
追踪到的可能问题代码
13532b4dd7d4dcf567652ad9cc4e50f
bc1dd7e108a3423a49f591f797a1a42

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • Version: v1.1.0

Additional context
Add any other context about the problem here.

运行polaris-go里的example的circuitbreaker时崩溃报空指针错误

Describe the bug
运行polaris-go里的example的circuitbreaker时崩溃报空指针错误

To Reproduce
分别运行circuitbreaker的provider 和 consumer ,运行两个provider实例,按照readme步骤测试熔断功能,先停止一个provider实例,curl 向 consumer再发起请求,consumer就崩溃了。

Expected behavior
希望能正常测试熔断功能

Environment

  • Version: [master]
  • OS: [centos 7.9]

Additional context
分别运行circuitbreaker的provider 和 consumer ,运行两个provider实例,按照readme步骤测试熔断功能,先停止一个provider实例,curl 向 consumer再发起请求,consumer就崩溃了。

插件目录结构调整

什么是插件,插件需要满足3个原则:

  1. 实现某一个独立的功能的子模块,同一类型的所有插件要完成的事情是一致的
  2. 插件类型的名字,与插件所完成的事情存在关联

从上述2个原则来审视,以下插件需要进行调整:

  • alarmreporter:告警插件,用于上报告警信息,当前实现为空
    需去掉,不满足原则1,因为告警一般和监控相关,且一般不由SDK直接告警,一般是监控平台进行触发

  • subscribe:订阅插件,用于承载用户的订阅及通知的能力
    去掉,不满足原则1,SDK订阅能力通过缓存或者服务端直接驱动,并非独立功能的子模块,需挪入到主流程

  • cmdb:地域信息获取插件,用于提供多种获取SDK自身所在地域信息的能力
    需改名,插件类型名不符合所做的事情,不满足原则2,改名为location。
    同时需要增加通过服务端返回的ReportClientResponse信息解析获取地域信息的插件。
    插件名需要改成:polaris_server(服务端获取),environment(环境变量获取),rest(通过调用REST接口来获取)

  • reporthandler:report client的请求前置处理及后置处理逻辑
    需去掉,不满意原则1,插件并不是完成一个独立的功能,属于report client的一个辅助能力。
    插件去掉后,相关逻辑以这种方式实现:

    1. report client上报的数据统一从context中获取,context将需要带给服务端的数据都打入一个标记(代表是否需要上报),report client不关心上报的数据具体是啥。
    2. 监控插件启动时,将自身的端口等信息,写入到context中,设置标记
    3. clientid在SDK初始化的时候,也写入context中,设置标记
  • statreporter:完成统计监控上报的事情,当前实现为对接prometheus
    需改名,插件类型名不容易懂,与业界主流概念不相符,不满足原则2,改名为metric。

优化ConsumerAPI.UpdateServiceCallResult 的流程

What is the feature you want to add?

  • 当前 UpdateServiceCallResult 必须传入一个 Instance 实例,这里对于一些框架的对接不是很友好
  • 能够只传入 Service、Namespace、Host、Port 实例四元祖,在 SDK 内部闭环处理 Instance 实例的查找

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

config 相关配置信息是不是可以按需要配置吗?

Discussions:polarismesh/polaris#396

What is the feature you want to add?
比如,某个时候只需要注册服务和配置中心功能,这个时候是不是可以设置消费者服务不开启配置?在不需要服务消费服务时,还会生成服务发现的一些文件信息,这样会有点怪怪

Why do you want to add this feature?
实现配置信息,可以按需加载。

支持最新的限流控制台参数配置

What is the feature you want to add?

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

I looked at the entire code base, but did not do go fmt, which does not conform to the go code specification

As a well-known manufacturer at home and abroad, even the basic go code specifications have not been done well. It looks really uncomfortable. The last project was the polaris project. I can't think of this polaris-go as well. Is this the style of the big factory? It's really low. It is recommended that you first standardize the code, go fmt the code, and then open it to the outside world. Don't you big manufacturers feel ashamed?

Even if you use vim or vscode editors, you can do some basic code formatting after writing the code. It is recommended to use the goland editor and the golanglint tool. It is fine to format the code of the entire project once. At the very least, when someone else contributes to you, it will look more comfortable and not so uncomfortable.

The code is written for people to see. If the open source code is presented to go developers or trailblazers, it should be carefully polished, rather than being fine after writing, and then executing go build, no matter what. This is not the style of an open source project. As a large company that has attracted much attention from the industry, you should reflect on which link has gone wrong, whether open source has not been properly checked, or whether your go developers are at this level, then Just huh.

feat: about deprecate add config listener by AddChangeListenerWithChannel

What is the feature you want to add?

deprecate AddChangeListenerWithChannel func

Why do you want to add this feature?

AddChangeListenerWithChannel跟AddChangeListener使用场景差不多,AddChangeListener适配更多场景

How to implement this feature?

Additional context

Use AddChangeListener instead.

支持熔断的远程规则配置

What is the feature you want to add?
支持熔断规则的远程配置
Why do you want to add this feature?
sdk当前只支持本地规则配置,需要扩展远程规则配置

feat: active health check

What is the feature you want to add?

active health check feature

Why do you want to add this feature?

some kind of service has very few QPS at the free time, for detect the failure asap, we need active health check always

How to implement this feature?

send health check request from callee, users will config the health check url in sdk config

Additional context

增加代码设置配置的能力

在使用grpc-poloris-go的时候,当前配置只能通过配置文件的方式设置,我们场景中需要用到代码配置能力,结合代码,需要修改配置结构体字段标签为omitempty,确保设置了有效值的字段才被导入到配置对象里。

discover缓存的节点全不可用后,SDK无法重新刷新并恢复

Describe the bug

  • 开启北极星二次寻址之后,如果 polaris.discover 下的服务列表都不可用,无法在接入IP再次发起发现请求,导致SDK无法恢复正常

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • Version: [e.g. v1.0.0]
  • OS: [e.g. CentOS8]

Additional context
Add any other context about the problem here.

polaris-server 一开始就挂掉,每次获取限流配置都会超时两秒,阻塞正常业务。

Describe the bug
在使用polaris-go的过程中发现,如果polaris-server一开始就挂掉,获取限流配置每次都是两秒,超时两秒在生产环境是不可接受的。然后我又尝试获取过一次配置之后,再把polaris-server停止,不再有超时现象。我觉得哪怕最开始的时候获取不到限流配置也应该缓存下,后续在更新缓存, 不应该阻塞正常业务。

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • Version: [e.g. v1.0.0]
  • OS: [e.g. CentOS8]

Additional context
Add any other context about the problem here.

support push metrics data to prometheus

What is the feature you want to add?

support push metrics data to prometheus

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

reformat go imports and update licenses

What is the feature you want to add?

  1. Update Regexp2 licenses
  2. Reformat go imports
    Why do you want to add this feature?

find . -name "*.go" -type f | grep -v .pb.go|grep -v test/tools/tools.go | grep -v pkg/plugin/register/plugins.go | xargs -I {} goimports-reviser -rm-unused -format {} -project-name github.com/polarismesh/polaris-go

find . -name "*.go" -type f |grep -v .pb.go|grep -v test/tools/tools.go | grep -v pkg/plugin/register/plugins.go | xargs -I {} goimports -local github.com/polarismesh/polaris-go -w {}

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

SDK 支持mock,以及可以往配置中心写入数据

What is the feature you want to add?
SDK支持向配置中心写入数据
Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

golang版本支持regexp2的正则匹配

What is the feature you want to add?
golang版本支持regexp2的正则匹配

Why do you want to add this feature?
希望支持(?!xxx)等非获取匹配功能

How to implement this feature?
线上操作, 希望过滤某个指定版本的实例

Additional context
Add any other context or screenshots about the feature request here.
image

添加就近路由examples

What is the feature you want to add?

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

支持北极星服务端的异步注册逻辑

What is the feature you want to add?

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

make polaris-go api more easy to use

  1. go sdk中api的写法不是很优雅
    像api.NewProviderAPI() 这种写法令人感到有带一些迷惑,无法很直观的看出来是哪个api(尤其是接入polaris的多数为server端应用,大部分程序都会去建个api包,用于提供对外的rpc或http api)。可能像zap.NewProduction() 或 gin.Default() 这样,写成 polaris.NewProviderAPI()这样会更直观一点。

polarismesh/polaris#103

support local sdk config for ratelimit

What is the feature you want to add?
ratelimit feature should not rely on the remote config, user can use the feature when he is only use the polaris-go sdk

Why do you want to add this feature?

when user use the ratelimit feature, he can use this feature without the remote configuration

How to implement this feature?

  1. add support the local mode
  2. in local mode, user can use the ratelimit config to do ratelimit

Additional context
Add any other context or screenshots about the feature request here.

支持通过 pushgateway 上报监控数据

What is the feature you want to add?

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

根据实例id获取实例信息

What is the feature you want to add?
根据实例id获取实例信息
Why do you want to add this feature?
在做kitex的实例和北极星实例转换的时候,因为北极星实例信息过多,代码强转无法满足

support environment in polaris.yaml

What is the feature you want to add?

Why do you want to add this feature?

How to implement this feature?

Additional context
Add any other context or screenshots about the feature request here.

路由和负载均衡能力可以单独使用

What is the feature you want to add?

增加API,用户可以单独使用路由和负载均衡功能,不依赖北极星的服务发现机制

Why do you want to add this feature?

与其他框架对接时,框架往往会单独使用路由和负载均衡能力,北极星当前一体化的API对接起来比较困难

How to implement this feature?

增加routerAPI

// RouterAPI 路由API方法
type RouterAPI interface {
	SDKOwner
	// process routers to filter instances
	ProcessRouters(*ProcessRoutersRequest) (*ProcessRoutersResponse, error)
	// process load balancer to get the target instancesbbbb
	ProcessLoadBalance(*ProcessLoadBalanceRequest) (*ProcessLoadBalanceResponse, error)
}

type ProcessRoutersRequest struct {
	model.ProcessRoutersRequest
}

type ProcessRoutersResponse struct {
	model.ProcessRoutersResponse
}

type ProcessLoadBalanceRequest struct {
	model.ProcessLoadBalanceRequest
}

type ProcessLoadBalanceResponse struct {
	model.ProcessLoadBalanceResponse
}

// model包下的请求类型定义

type ProcessRoutersRequest struct {
	// router plugins
	Routers []string
	// source service
	SourceService ServiceInfo
	// destination instances
	DstInstances ServiceInstances
	// invoke method
	Method string
}

type ProcessRoutersResponse struct {
	// instances after routing
	Instances ServiceInstances
}

type ProcessLoadBalanceRequest struct {
	// destination instances
	DstInstances ServiceInstances
	// load balance method
	LbPolicy string
	// hash key
	HashKey string
}

type ProcessLoadBalanceResponse struct {
	// instance after load balance
	TargetInstance Instance
	// sibling instances for target instance
	SiblingInstances []Instance
}

Additional context
Add any other context or screenshots about the feature request here.

关于路由规则的一个问题优化

1. 主要问题
当创建一个路由规则, 是类似于
{srcService: *, srcNamespace: *} -> {dstService: serivceA, dstNamespace: namespaceA}

表明对所有的主调方生效。

这个时候每个服务在拉取路由规则的时候,其中的outbound都会多一条:
{srcService: selfService, srcNamespace: selfNameSpace} - > {dstService: serivceA, dstNamespace: namespaceA}

当我调用一个服务,serviceB. 而这个serviceB不在outbound里面。
就会因为match不上而导致路由失败。

2. 可能导致问题的场景

我对一个服务创建了一个对所有主调生效的规则。
这个时候所有的服务srcService的outbound都会多一条规则。导致原本可以调用的服务不可调用了。

3. 可能的解决方式

当dstService没match到outbounds上,就走默认的路由规则。

pkg/model/now.go#36 & 45 line in mac os has err

Describe the bug
在mac os环境下,now.go下的这俩方法 CurrentMicrosecond、CurrentMillisecond 会报错,因为 win环境下go的Timeval
下的字段都是int32,但是macos下一个是int32,一个是int64,写法上不兼容,需要修改一下。
To Reproduce

  1. mac os准备go16的环境
  2. 打开now.go文件,就会发现报错

Expected behavior

  • 不报错

Environment

  • Version: go16
  • OS: mac os

Additional context
报错图片

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.