polarismesh

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 31 Imported by: 2

README

polarismesh

this project was inspired by grpc-go-polaris.

目前支持的北极星服务治理功能如下:

  • 服务注册及发现
  • 动态路由
  • 服务熔断
  • 访问限流:部分能力
    • 根据请求方法进行限流.
  • [] 配置中心:

Client

使用普通的Grpc Client, 格式: polaris://{namespace}/{service}?[options={query}]作为请求目标:

query: 为base64编码的json字符串,字段内容可参照woocoo项目文档说明.

例如:

conn, _ := grpc.Dial("polaris://woocoo/helloworld.Greeter", grpc.WithInsecure(), grpc.WithResolvers(&resolverBuilder{}))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultNamespace default namespace when namespace is not set
	DefaultNamespace = "default"
	// LoadBalanceConfig config for do the balance
	LoadBalanceConfig = fmt.Sprintf("{\n  \"loadBalancingConfig\": [ { \"%s\": {} } ]}", scheme)
)
View Source
var (

	// ErrorPolarisServiceRouteRuleEmpty error service route rule is empty
	ErrorPolarisServiceRouteRuleEmpty = errors.New("service route rule is empty")
)

Functions

func InitPolarisContext

func InitPolarisContext(cnf *conf.Configuration) (cfg config.Configuration, ctx api.SDKContext, err error)

InitPolarisContext create polaris context by config

func NewBalancerBuilder

func NewBalancerBuilder(name string, ctx api.SDKContext) balancer.Builder

NewBalancerBuilder creates a new polaris balancer builder

func PolarisContext

func PolarisContext() (ctx api.SDKContext, err error)

PolarisContext get or init the global polaris context

func RateLimitUnaryServerInterceptor

func RateLimitUnaryServerInterceptor(cfg *conf.Configuration) grpc.UnaryServerInterceptor

RateLimitUnaryServerInterceptor returns a new unary server interceptors that performs per-method rate limiting.

func SetPolarisContextOnceByConfig

func SetPolarisContextOnceByConfig(cfg config.Configuration) (err error)

SetPolarisContextOnceByConfig set polaris context by config, if polaris context has init then do nothing

func SetReportInfoAnalyzer

func SetReportInfoAnalyzer(analyzer ReportInfoAnalyzer)

SetReportInfoAnalyzer sets report info analyzer

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver implementation of registry.Driver. It is used to create a polaris registry

func (*Driver) CreateRegistry

func (drv *Driver) CreateRegistry(cnf *conf.Configuration) (registry.Registry, error)

CreateRegistry creates a polaris registry.

func (*Driver) GetRegistry

func (drv *Driver) GetRegistry(name string) (registry.Registry, error)

func (*Driver) ResolverBuilder

func (drv *Driver) ResolverBuilder(cnf *conf.Configuration) (resolver.Builder, error)

ResolverBuilder creates a polaris resolver builder.

func (*Driver) WithDialOptions

func (drv *Driver) WithDialOptions(registryOpt registry.DialOptions) (opts []grpc.DialOption, err error)

WithDialOptions returns the default dial options for the grpc Polaris GRPC Client.

type LBConfig

type LBConfig struct {
	serviceconfig.LoadBalancingConfig `json:"-"`
	HashKey                           string `json:"hash_key"`
	LbPolicy                          string `json:"lb_policy"`
}

LBConfig is the LB config for the polaris policy.

type Options

type Options struct {
	// TTL must between (0s, 60s) see: polaris.yaml
	TTL time.Duration `json:"ttl" yaml:"ttl"`
}

Options is the options for the polaris registry

type RateLimitInterceptor

type RateLimitInterceptor struct {
	// contains filtered or unexported fields
}

RateLimitInterceptor is a gRPC interceptor that implements rate limiting.

func NewRateLimitOptions

func NewRateLimitOptions() *RateLimitInterceptor

func (*RateLimitInterceptor) Apply

func (rl *RateLimitInterceptor) Apply(cnf *conf.Configuration)

type RegisterContext

type RegisterContext struct {
	// contains filtered or unexported fields
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func New

func New() *Registry

func (*Registry) Apply

func (r *Registry) Apply(cnf *conf.Configuration)

Apply the configuration to the registry and set the first config as the default global config

func (*Registry) Close

func (r *Registry) Close()

func (*Registry) GetServiceInfos

func (r *Registry) GetServiceInfos(service string) ([]*registry.ServiceInfo, error)

GetServiceInfos implements the registry interface

func (*Registry) Register

func (r *Registry) Register(serviceInfo *registry.ServiceInfo) error

func (*Registry) TTL

func (r *Registry) TTL() time.Duration

TTL return 0, polaris use heartbeat to keep alive,so ttl is not used

func (*Registry) Unregister

func (r *Registry) Unregister(serviceInfo *registry.ServiceInfo) error

Unregister the service from the registry if the service is not registered, return nil

type ReportInfoAnalyzer

type ReportInfoAnalyzer func(info balancer.DoneInfo) (model.RetStatus, uint32)

ReportInfoAnalyzer analyze balancer.DoneInfo to polaris report info

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL