model

package
v1.6.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 25 Imported by: 89

Documentation

Index

Constants

View Source
const (
	ArgumentTypeCustom = iota
	ArgumentTypeMethod
	ArgumentTypeHeader
	ArgumentTypeQuery
	ArgumentTypeCallerService
	ArgumentTypeCallerIP
	ArgumentTypePath
	ArgumentTypeCookie
)
View Source
const (
	LabelKeyMethod        = "$method"
	LabelKeyHeader        = "$header."
	LabelKeyQuery         = "$query."
	LabelKeyCallerService = "$caller_service."
	LabelKeyCallerIp      = "$caller_ip"
	LabelKeyPath          = "$path"
	LabelKeyCookie        = "$cookie."
)
View Source
const (
	NearbyMetadataEnable = "internal-enable-nearby"
	CanaryMetadataEnable = "internal-canary"

	CanaryMetaKey = "canary"
)

用于拼接metadata的样式

View Source
const (
	// ContextKeyEngine 主流程引擎的上下文key
	// SDK初始化后,会将主流程引擎对象放入上下文中,供插件按需使用
	ContextKeyEngine = "engine"
	// ContextKeyToken SDK的唯一标识id
	ContextKeyToken = "SDKToken"
	// ContextKeyPlugins sdkcontext上面的pluginManager
	ContextKeyPlugins = "plugins"
	// ContextKeyTakeEffectTime sdkContext创建开始时间
	ContextKeyTakeEffectTime = "SDKTakeEffectTime"
	// ContextKeyFinishInitTime sdkContext创建结束时间
	ContextKeyFinishInitTime = "SDKFinishInitTime"
	// ContextKeySelfIP sdk bind ip
	ContextKeySelfIP = "__sdk_bind_ip__"
)
View Source
const (
	// LocationInit 地域信息初始化,未获取到地域信息
	LocationInit uint32 = iota
	// LocationError 地域信息获取失败,出现异常
	LocationError
	// LocationReady 地域信息获取成功
	LocationReady
	// LocationEmpty 地域信息获取成功,但是是空的,即没有在cmdb上面发现地域信息
	LocationEmpty
)
View Source
const (
	// 返回码取模的底数
	RetCodeDivFactor = 1000
	// 取模后的成功错误码
	SuccessRetCode = 200
	// 取模后的server内部错误
	ServerExceptionRetCode = 500
)
View Source
const (
	// RateLimitLocal 在本地限流.
	RateLimitLocal = "local"
	// RateLimitGlobal 在全局限流.
	RateLimitGlobal = "global"
)
View Source
const (
	// MeshServiceEntry ServiceEntry.
	MeshServiceEntry string = "networking.istio.io/v1alpha3/ServiceEntry"
	// MeshVirtualService VirtualService.
	MeshVirtualService string = "networking.istio.io/v1alpha3/VirtualService"
	// MeshDestinationRule DestinationRule.
	MeshDestinationRule string = "networking.istio.io/v1alpha3/DestinationRule"
	// MeshEnvoyFilter EnvoyFilter.
	MeshEnvoyFilter string = "networking.istio.io/v1alpha3/EnvoyFilter"
	// MeshGateway Gateway.
	MeshGateway string = "networking.istio.io/v1alpha3/Gateway"
)

网格规则类型.

View Source
const (
	// ModeNoAgent 以no agent模式运行
	ModeNoAgent = iota
	// ModeWithAgent 带agent模式运行
	ModeWithAgent
)
View Source
const (
	// MinWeight 最小权重值
	MinWeight int = 0
	// MaxWeight 最大权重值
	MaxWeight int = 10000
	// MinPriority 最小优先级
	MinPriority = 0
	// MaxPriority 最大优先级
	MaxPriority = 9
)
View Source
const (
	// HealthCheckTypeHeartBeat 健康检查类型:心跳
	HealthCheckTypeHeartBeat int = 0
	// DefaultHeartbeatTtl
	DefaultHeartbeatTtl int = 5
)
View Source
const (
	BaseIndexErrCode = 1000
)
View Source
const (
	BaseSDKInternalErrCode = 3000
)
View Source
const (
	BaseServerErrCode = 2000
)
View Source
const (
	ErrCodeDiskError = BaseSDKInternalErrCode + 1
)
View Source
const (
	HomeVar = "$HOME"
)

Variables

View Source
var (
	// MeshPrefix 网格请求key前缀.
	MeshPrefix = "mesh_resource"
	// MeshKeyLen 网格请求key分割长度.
	MeshKeyLen = 3
	// MeshKeySpliter 网格请求key分隔符.
	MeshKeySpliter = "MESHa071a34fecSPLITER"
)
View Source
var EmptyServiceKey = &ServiceKey{}
View Source
var ErrorCallAborted = errors.New("call aborted")

Functions

func CheckConfigFileMetadata added in v1.5.5

func CheckConfigFileMetadata(configFileMetadata ConfigFileMetadata) error

func ConvertDuration added in v1.2.0

func ConvertDuration(d *duration.Duration) (time.Duration, error)

ConvertDuration converts to golang duration and logs errors

func CurrentMicrosecond

func CurrentMicrosecond() int64

CurrentMicrosecond 获取微秒时间

func CurrentMillisecond

func CurrentMillisecond() int64

CurrentMillisecond 获取微秒时间

func CurrentNanosecond

func CurrentNanosecond() int64

CurrentNanosecond obtains the current microsecond, use syscall for better performance

func DescMetricType added in v1.2.0

func DescMetricType(t MetricType) string

func EnsureAndVerifyDir

func EnsureAndVerifyDir(dir string) error

EnsureAndVerifyDir 检测缓存目录,不存在则创建

func ErrCodeToString

func ErrCodeToString(ec ErrCode) string

ErrCodeToString 将错误码转换为字符串

func GetCrc64Hash added in v1.4.0

func GetCrc64Hash(value string) (uint64, error)

func GetIP

func GetIP(name string) (string, error)

GetIP get local ip from inteface name like eth1

func HashMessage

func HashMessage(message proto.Message) uint64

HashMessage 对PB消息进行hash

func HashStr

func HashStr(key string) (uint64, error)

HashStr 对字符串进行hash操作

func IsDir

func IsDir(path string) bool

IsDir file path is dir

func IsFile

func IsFile(path string) bool

IsFile file path is dir

func IsNearbyMatch

func IsNearbyMatch(dst, src string) bool

IsNearbyMatch 判断是否满足就近条件

func IsServerException

func IsServerException(retCode uint32) bool

IsServerException 判断是否为内部server错误

func IsSuccessResultCode

func IsSuccessResultCode(retCode uint32) bool

IsSuccessResultCode 判断是否成功的错误码

func ParseMilliSeconds

func ParseMilliSeconds(v int64) int64

ParseMilliSeconds 时间转换成毫秒

func PathExist

func PathExist(path string) bool

PathExist 查看文件路径是否存在

func PoolGetByteBuffer

func PoolGetByteBuffer(size int) *bytes.Buffer

PoolGetByteBuffer 通过池子获取字符串队列

func PoolGetStringSlice

func PoolGetStringSlice(size int) []string

PoolGetStringSlice 获取字符串数组

func PoolPutByteBuffer

func PoolPutByteBuffer(size int, buf *bytes.Buffer)

PoolPutByteBuffer 归还字节数组

func PoolPutStringSlice

func PoolPutStringSlice(size int, slice []string)

PoolPutStringSlice 归还字符串数组

func ProtoDurationToMS added in v1.2.0

func ProtoDurationToMS(dur *duration.Duration) int64

ProtoDurationToMS pb时间段转毫秒

func ReplaceHomeVar

func ReplaceHomeVar(path string) string

ReplaceHomeVar 替换相对路径

func SortMap

func SortMap(values map[string]string, keys []string) ([]string, int)

SortMap 对map进行排序, keys的长度必须等于map的长度 返回已经排序的key,以及map中总字符串长度

func TimestampMsToUtcIso8601

func TimestampMsToUtcIso8601(timestamp int64) string

TimestampMsToUtcIso8601 格式化时间戳

func ToBoolPtr added in v1.5.4

func ToBoolPtr(v bool) *bool

ToBoolPtr .

func ToDurationPtr

func ToDurationPtr(v time.Duration) *time.Duration

ToDurationPtr 转换时间指针

func ToMilliSeconds

func ToMilliSeconds(v time.Duration) int64

ToMilliSeconds 时间转换成毫秒

func ToNetIP

func ToNetIP(val uint32) net.IP

ToNetIP 将uint32类型转化为ipv4地址

func ToStringService

func ToStringService(svc ServiceMetadata, printMeta bool) string

ToStringService 服务元数据的ToString操作

func ValidMetircType

func ValidMetircType(t MetricType) bool

ValidMetircType 检测是不是合法的统计类型.

Types

type APICallKey

type APICallKey struct {
	// 调用的API接口名字
	APIName ApiOperation
	// 必选,本地服务调用的错误码
	RetCode ErrCode
	// 延迟的范围
	DelayRange ApiDelayRange
}

APICallKey API调用的唯一标识

type APICallResult

type APICallResult struct {
	EmptyInstanceGauge
	APICallKey
	// 必选,本地服务调用的状态,正常or异常
	RetStatus RetStatus
	// contains filtered or unexported fields
}

APICallResult sdk api调用结果

func (*APICallResult) GetAPI

func (a *APICallResult) GetAPI() ApiOperation

GetAPI 获取调用api

func (*APICallResult) GetDelay

func (a *APICallResult) GetDelay() *time.Duration

GetDelay 调用时延

func (*APICallResult) GetDelayRange

func (a *APICallResult) GetDelayRange() ApiDelayRange

GetDelayRange 返回延迟范围

func (*APICallResult) GetRetCode

func (a *APICallResult) GetRetCode() *int32

GetRetCode 实例的返回码

func (*APICallResult) GetRetCodeValue

func (a *APICallResult) GetRetCodeValue() int32

GetRetCodeValue 实例的返回码

func (*APICallResult) GetRetStatus

func (a *APICallResult) GetRetStatus() RetStatus

GetRetStatus 实例的调用返回状态

func (*APICallResult) SetDelay

func (a *APICallResult) SetDelay(delay time.Duration)

SetDelay 设置调用时延

func (*APICallResult) SetFail

func (a *APICallResult) SetFail(retCode ErrCode, delay time.Duration)

SetFail 设置失败的调用结果

func (*APICallResult) SetSuccess

func (a *APICallResult) SetSuccess(delay time.Duration)

SetSuccess 设置成功的调用结果

type ActiveDetectStatus

type ActiveDetectStatus interface {
	// GetStatus 健康探测结果状态
	GetStatus() HealthCheckStatus
	// GetStartTime 状态转换的时间
	GetStartTime() time.Time
}

ActiveDetectStatus 健康探测管理器

type ApiDelayRange

type ApiDelayRange int

ApiDelayRange API延时范围.

const (
	ApiDelayBelow50 ApiDelayRange = iota
	ApiDelayBelow100
	ApiDelayBelow150
	ApiDelayBelow200
	ApiDelayOver200
	ApiDelayMax
)

API延时范围常量.

func GetApiDelayRange

func GetApiDelayRange(delay time.Duration) ApiDelayRange

GetApiDelayRange 获取api时延范围.

func (ApiDelayRange) String

func (a ApiDelayRange) String() string

String ToString方法.

type ApiOperation

type ApiOperation int

ApiOperation 命名类型,标识具体的API类型.

const (
	ApiGetOneInstance ApiOperation = iota
	ApiGetInstances
	ApiGetRouteRule
	ApiRegister
	ApiDeregister
	ApiHeartbeat
	ApiGetQuota
	ApiGetAllInstances
	ApiUpdateServiceCallResult
	ApiServices
	ApiInitCalleeServices
	ApiProcessRouters
	ApiProcessLoadBalance
	// ApiOperationMax 这个必须在最下面
	ApiOperationMax
)

API标识.

func (ApiOperation) String

func (a ApiOperation) String() string

String ToString方法.

type Argument added in v1.2.0

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

Argument 限流/路由参数

func BuildArgumentFromLabel added in v1.2.0

func BuildArgumentFromLabel(labelKey string, labelValue string) Argument

func BuildCallerIPArgument added in v1.2.0

func BuildCallerIPArgument(callerIP string) Argument

func BuildCallerServiceArgument added in v1.2.0

func BuildCallerServiceArgument(namespace string, service string) Argument

func BuildCookieArgument added in v1.3.0

func BuildCookieArgument(key, value string) Argument

func BuildCustomArgument added in v1.2.0

func BuildCustomArgument(key string, value string) Argument

func BuildHeaderArgument added in v1.2.0

func BuildHeaderArgument(key string, value string) Argument

func BuildMethodArgument added in v1.2.0

func BuildMethodArgument(method string) Argument

func BuildPathArgument added in v1.3.0

func BuildPathArgument(path string) Argument

func BuildQueryArgument added in v1.2.0

func BuildQueryArgument(key string, value string) Argument

func (Argument) ArgumentType added in v1.2.0

func (a Argument) ArgumentType() int

func (Argument) Key added in v1.2.0

func (a Argument) Key() string

func (Argument) String added in v1.2.0

func (a Argument) String() string

func (Argument) ToLabels added in v1.2.0

func (a Argument) ToLabels(labels map[string]string)

func (Argument) Value added in v1.2.0

func (a Argument) Value() string

type BaseCircuitBreakerStatus

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

func (*BaseCircuitBreakerStatus) GetCircuitBreaker

func (c *BaseCircuitBreakerStatus) GetCircuitBreaker() string

GetCircuitBreaker 标识被哪个熔断器熔断

func (*BaseCircuitBreakerStatus) GetFallbackInfo

func (c *BaseCircuitBreakerStatus) GetFallbackInfo() *FallbackInfo

func (*BaseCircuitBreakerStatus) GetStartTime

func (c *BaseCircuitBreakerStatus) GetStartTime() time.Time

GetStartTime 状态转换的时间

func (*BaseCircuitBreakerStatus) GetStatus

func (c *BaseCircuitBreakerStatus) GetStatus() Status

GetStatus 熔断状态

func (*BaseCircuitBreakerStatus) IsAvailable

func (c *BaseCircuitBreakerStatus) IsAvailable() bool

func (*BaseCircuitBreakerStatus) SetFallbackInfo

func (c *BaseCircuitBreakerStatus) SetFallbackInfo(info *FallbackInfo)

type CacheValueQuery

type CacheValueQuery interface {
	// GetDstService 获取目标服务
	GetDstService() *ServiceKey
	// GetSrcService 获取源服务
	GetSrcService() *ServiceKey
	// GetNotifierTrigger 获取缓存查询触发器
	GetNotifierTrigger() *NotifyTrigger
	// SetDstInstances 设置目标服务实例
	SetDstInstances(instances ServiceInstances)
	// SetDstRoute 设置目标服务路由规则
	SetDstRoute(rule ServiceRule)
	// SetDstRateLimit 设置目标服务限流规则
	SetDstRateLimit(rule ServiceRule)
	// SetSrcRoute 设置源服务路由规则
	SetSrcRoute(rule ServiceRule)
	// GetControlParam 获取API调用控制参数
	GetControlParam() *ControlParam
	// GetCallResult 获取API调用统计
	GetCallResult() *APICallResult
	// SetServices 设置服务列表
	SetServices(mc Services)
}

CacheValueQuery 缓存查询请求对象

type CallAborted

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

func NewCallAborted

func NewCallAborted(err error,
	rule string,
	fallback *FallbackInfo) *CallAborted

func (*CallAborted) GetError

func (c *CallAborted) GetError() error

func (*CallAborted) GetFallbackBody

func (c *CallAborted) GetFallbackBody() string

func (*CallAborted) GetFallbackCode

func (c *CallAborted) GetFallbackCode() int

func (*CallAborted) GetFallbackHeaders

func (c *CallAborted) GetFallbackHeaders() map[string]string

func (*CallAborted) HasFallback

func (c *CallAborted) HasFallback() bool

type ChangeType added in v1.1.0

type ChangeType int

ChangeType 配置文件变更类型

const (
	// Modified 修改类型
	Modified ChangeType = iota
	// Deleted 删除类型
	Deleted
	// Added 新增类型
	Added
	// NotChanged 没有变更
	NotChanged
)

type CheckResult

type CheckResult struct {
	Pass         bool
	RuleName     string
	FallbackInfo *FallbackInfo
}

type CircuitBreakGauge added in v1.1.0

type CircuitBreakGauge struct {
	EmptyInstanceGauge
	ChangeInstance Instance
	Method         string
	CBStatus       CircuitBreakerStatus
}

CircuitBreakGauge Circuit Break Gauge

func (*CircuitBreakGauge) GetCalledInstance added in v1.1.0

func (cbg *CircuitBreakGauge) GetCalledInstance() Instance

GetCalledInstance 获取状态发生改变的实例

func (*CircuitBreakGauge) GetCircuitBreakerStatus added in v1.1.0

func (cbg *CircuitBreakGauge) GetCircuitBreakerStatus() CircuitBreakerStatus

GetCircuitBreakerStatus 获取当前实例熔断状态

func (*CircuitBreakGauge) Validate added in v1.1.0

func (cbg *CircuitBreakGauge) Validate() error

检测指标是否合法

type CircuitBreakerStatus

type CircuitBreakerStatus interface {
	// GetCircuitBreaker 标识被哪个熔断器熔断
	GetCircuitBreaker() string
	// GetStatus 熔断状态
	GetStatus() Status
	// GetStartTime 状态转换的时间
	GetStartTime() time.Time
	// GetFallbackInfo 获取熔断器的降级信息
	GetFallbackInfo() *FallbackInfo
	// SetFallbackInfo 获取熔断器的降级信息
	SetFallbackInfo(*FallbackInfo)
}

CircuitBreakerStatus 熔断器状态管理器

func NewCircuitBreakerStatus

func NewCircuitBreakerStatus(name string, status Status, startTime time.Time,
	options ...InitCircuitBreakerStatus) CircuitBreakerStatus

func NewHalfOpenStatus

func NewHalfOpenStatus(name string, start time.Time, maxRequest int) CircuitBreakerStatus

type CircuitBreakerStatusImpl

type CircuitBreakerStatusImpl struct {
	CircuitBreaker string
	Status         Status
	StartTime      time.Time
	// contains filtered or unexported fields
}

CircuitBreakerStatusImpl 熔断状态模型,实现了CircuitBreakerStatus接口

func (*CircuitBreakerStatusImpl) GetCircuitBreaker

func (c *CircuitBreakerStatusImpl) GetCircuitBreaker() string

GetCircuitBreaker 标识被哪个熔断器熔断

func (*CircuitBreakerStatusImpl) GetStartTime

func (c *CircuitBreakerStatusImpl) GetStartTime() time.Time

GetStartTime 状态转换的时间

func (*CircuitBreakerStatusImpl) GetStatus

func (c *CircuitBreakerStatusImpl) GetStatus() Status

GetStatus 熔断状态

func (CircuitBreakerStatusImpl) String

func (c CircuitBreakerStatusImpl) String() string

String 打印熔断状态数据

type CircuitBreakerStatusWrapper

type CircuitBreakerStatusWrapper struct {
	Val CircuitBreakerStatus
}

CircuitBreakerStatusWrapper 上方熔断管理器的包装,用于存入 atomic.Value

type Cluster

type Cluster struct {
	ClusterKey
	MetaComposedValue
	// 集群的元数据信息,key为metaKey, valueKey为metaValue, valueValue为composedValue
	Metadata map[string]map[string]string
	// 元数据KV的个数
	MetaCount int
	// 是否包含限制路由的实例,全死全活后为true
	HasLimitedInstances bool
	// 没有符合就近路由的实例
	MissLocationInstances bool
	// 位置信息匹配情况
	LocationMatchInfo string

	IncludeHalfOpen bool
	// contains filtered or unexported fields
}

Cluster 路由后的集群信息,包含的是标签以及地域信息

func NewCluster

func NewCluster(clusters ServiceClusters, cls *Cluster) *Cluster

NewCluster 新建Cluster

func (*Cluster) AddMetadata

func (c *Cluster) AddMetadata(key string, value string) bool

AddMetadata 开放给插件进行手动元数据的添加

func (*Cluster) ClearClusterValue

func (c *Cluster) ClearClusterValue()

ClearClusterValue 清理集群值缓存

func (*Cluster) GetAllInstances

func (c *Cluster) GetAllInstances() ([]Instance, int)

GetAllInstances 获取完整的服务实例列表

func (*Cluster) GetClusterValue

func (c *Cluster) GetClusterValue() *ClusterValue

GetClusterValue 重构建集群缓存

func (*Cluster) GetClusters

func (c *Cluster) GetClusters() ServiceClusters

GetClusters 获取父集群

func (*Cluster) GetContainMetaKeyClusterValue

func (c *Cluster) GetContainMetaKeyClusterValue() *ClusterValue

GetContainMetaKeyClusterValue 重构 包含Key 的缓存

func (*Cluster) GetContainNotMatchMetaKeyClusterValue

func (c *Cluster) GetContainNotMatchMetaKeyClusterValue() *ClusterValue

GetContainNotMatchMetaKeyClusterValue 重构 包含Key但是不匹配 的缓存

func (*Cluster) GetInstances

func (c *Cluster) GetInstances() ([]Instance, int)

GetInstances 通过服务实例全量列表获取集群服务实例

func (*Cluster) GetInstancesWhenSkipRouteFilter

func (c *Cluster) GetInstancesWhenSkipRouteFilter() ([]Instance, int)

GetInstancesWhenSkipRouteFilter 通过服务实例全量列表获取集群服务实例,但是不进行路由过滤

func (*Cluster) GetNotContainMetaKeyClusterValue

func (c *Cluster) GetNotContainMetaKeyClusterValue() *ClusterValue

GetNotContainMetaKeyClusterValue 重构 不包含Key 的缓存

func (*Cluster) MatchContainMetaKeyData

func (c *Cluster) MatchContainMetaKeyData(instance Instance) bool

MatchContainMetaKeyData 判断是否包含标签key

func (*Cluster) PoolPut

func (c *Cluster) PoolPut()

PoolPut 归还对象到池子中

func (*Cluster) ReloadComposeMetaValue

func (c *Cluster) ReloadComposeMetaValue()

ReloadComposeMetaValue 重建组合元数据KV

func (*Cluster) RuleAddMetadata

func (c *Cluster) RuleAddMetadata(key string, value string, composedValue string) bool

RuleAddMetadata 通过路由规则插件添加复合元数据,不会进行缓存数据的变更

func (*Cluster) SetReuse

func (c *Cluster) SetReuse(value bool)

SetReuse 设置是否需要复用cluster

func (Cluster) String

func (c Cluster) String() string

String 集群信息ToString

type ClusterEventHandler

type ClusterEventHandler struct {
	// 在集群值构建完毕后进行调用
	PostClusterValueBuilt func(value *ClusterValue)
}

ClusterEventHandler 集群事件处理器

type ClusterKey

type ClusterKey struct {
	// 组合后的元数据kv
	ComposeMetaValue string
	Location         Location
}

ClusterKey 集群缓存KEY对象

func (ClusterKey) String

func (k ClusterKey) String() string

String ToString

type ClusterOwner added in v1.2.0

type ClusterOwner interface {
	// GetCluster get the retained cluster
	GetCluster() *Cluster
}

ClusterOwner 保存了cluster指针的对象

type ClusterValue

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

ClusterValue 集群缓存VALUE对象

func (*ClusterValue) Count

func (v *ClusterValue) Count() int

Count 获取cluster下的服务可分配实例数量

func (*ClusterValue) GetAllInstanceSet

func (v *ClusterValue) GetAllInstanceSet() *InstanceSet

GetAllInstanceSet 获取全量服务实例集合

func (*ClusterValue) GetInstancesSet

func (v *ClusterValue) GetInstancesSet(hasLimitedInstances bool, includeHalfOpen bool) *InstanceSet

GetInstancesSet 获取实例集合,根据参数来进行选择返回全量或者健康

func (*ClusterValue) GetInstancesSetWhenSkipRouteFilter

func (v *ClusterValue) GetInstancesSetWhenSkipRouteFilter(hasLimitedInstances bool, includeHalfOpen bool) *InstanceSet

func (ClusterValue) String

func (v ClusterValue) String() string

String 缓存值的ToString

type ConfigFile added in v1.1.0

type ConfigFile interface {
	ConfigFileMetadata
	// GetLabels 获取配置文件标签
	GetLabels() map[string]string
	// GetContent 获取配置文件内容
	GetContent() string
	// HasContent 是否有配置内容
	HasContent() bool
	// AddChangeListenerWithChannel 增加配置文件变更监听器
	AddChangeListenerWithChannel() <-chan ConfigFileChangeEvent
	// AddChangeListener 增加配置文件变更监听器
	AddChangeListener(cb OnConfigFileChange)
}

ConfigFile 文本类型配置文件对象

type ConfigFileChangeEvent added in v1.1.0

type ConfigFileChangeEvent struct {
	ConfigFileMetadata ConfigFileMetadata
	// OldValue 变更之前的值
	OldValue string
	// NewValue 变更之后的值
	NewValue string
	// ChangeType 变更类型
	ChangeType ChangeType
}

ConfigFileChangeEvent 配置文件变更事件

type ConfigFileGroup added in v1.5.6

type ConfigFileGroup interface {
	// GetFiles
	GetFiles() ([]*SimpleConfigFile, string, bool)
	// AddChangeListener 增加配置文件变更监听器
	AddChangeListener(cb OnConfigGroupChange)
}

type ConfigFileMetadata added in v1.1.0

type ConfigFileMetadata interface {
	// GetNamespace 获取 Namespace 信息
	GetNamespace() string
	// GetFileGroup 获取配置文件组
	GetFileGroup() string
	// GetFileName 获取配置文件值
	GetFileName() string
}

ConfigFileMetadata 配置文件元信息

type ConfigGroupChangeEvent added in v1.5.6

type ConfigGroupChangeEvent struct {
	Before []*SimpleConfigFile
	After  []*SimpleConfigFile
}

ConfigGroupChangeEvent 配置文件变更事件

type ConfigMode

type ConfigMode int

ConfigMode 配置模式.

const (
	// ConfigQuotaLocalMode 在本地配置.
	ConfigQuotaLocalMode ConfigMode = 0
	// ConfigQuotaGlobalMode 在全局配置.
	ConfigQuotaGlobalMode ConfigMode = 1
)

type ControlParam

type ControlParam struct {
	Timeout       time.Duration
	MaxRetry      int
	RetryInterval time.Duration
}

ControlParam 单次查询的控制参数

type CustomerFunction

type CustomerFunction func(ctx context.Context, args interface{}) (interface{}, error)

type DecoratorFunction

type DecoratorFunction func(ctx context.Context, args interface{}) (interface{}, *CallAborted, error)

type DefaultConfigFileMetadata added in v1.1.0

type DefaultConfigFileMetadata struct {
	Namespace string
	FileGroup string
	FileName  string
}

DefaultConfigFileMetadata 默认 ConfigFileMetadata 实现类

func (*DefaultConfigFileMetadata) GetFileGroup added in v1.1.0

func (m *DefaultConfigFileMetadata) GetFileGroup() string

GetFileGroup 获取配置文件组

func (*DefaultConfigFileMetadata) GetFileName added in v1.1.0

func (m *DefaultConfigFileMetadata) GetFileName() string

GetFileName 获取配置文件值

func (*DefaultConfigFileMetadata) GetNamespace added in v1.1.0

func (m *DefaultConfigFileMetadata) GetNamespace() string

GetNamespace 获取 Namespace

type DefaultInstance added in v1.2.0

type DefaultInstance struct {
	// 必选,服务名
	Service string
	// 必选,命名空间
	Namespace string
}

DefaultInstance default instance implementation

type DefaultServiceInstances added in v1.2.0

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

func (*DefaultServiceInstances) GetHashValue added in v1.4.0

func (d *DefaultServiceInstances) GetHashValue() uint64

获取服务实例或规则的Hash值

func (*DefaultServiceInstances) GetInstance added in v1.2.0

func (d *DefaultServiceInstances) GetInstance(id string) Instance

获取单个服务实例

func (*DefaultServiceInstances) GetInstances added in v1.2.0

func (d *DefaultServiceInstances) GetInstances() []Instance

获取服务实例列表

func (*DefaultServiceInstances) GetMetadata added in v1.2.0

func (d *DefaultServiceInstances) GetMetadata() map[string]string

获取元数据信息

func (*DefaultServiceInstances) GetNamespace added in v1.2.0

func (d *DefaultServiceInstances) GetNamespace() string

获取命名空间

func (*DefaultServiceInstances) GetRevision added in v1.2.0

func (d *DefaultServiceInstances) GetRevision() string

获取服务实例或规则的版本号

func (*DefaultServiceInstances) GetService added in v1.2.0

func (d *DefaultServiceInstances) GetService() string

获取服务名

func (*DefaultServiceInstances) GetServiceClusters added in v1.2.0

func (d *DefaultServiceInstances) GetServiceClusters() ServiceClusters

获取集群索引

func (*DefaultServiceInstances) GetTotalWeight added in v1.2.0

func (d *DefaultServiceInstances) GetTotalWeight() int

获取全部实例总权重

func (*DefaultServiceInstances) GetType added in v1.2.0

func (d *DefaultServiceInstances) GetType() EventType

获取配置类型

func (*DefaultServiceInstances) IsCacheLoaded added in v1.2.0

func (d *DefaultServiceInstances) IsCacheLoaded() bool

数据是否来自于缓存文件

func (*DefaultServiceInstances) IsInitialized added in v1.2.0

func (d *DefaultServiceInstances) IsInitialized() bool

是否初始化,实例列表或路由值是否加载

func (*DefaultServiceInstances) IsNotExists added in v1.4.0

func (d *DefaultServiceInstances) IsNotExists() bool

func (*DefaultServiceInstances) ReloadServiceClusters added in v1.2.0

func (d *DefaultServiceInstances) ReloadServiceClusters()

重建缓存索引

type EmptyInstanceGauge

type EmptyInstanceGauge struct{}

EmptyInstanceGauge instangeGauge的空实现.

func (EmptyInstanceGauge) GetAPI

func (e EmptyInstanceGauge) GetAPI() ApiOperation

GetAPI api.

func (EmptyInstanceGauge) GetCalledInstance

func (e EmptyInstanceGauge) GetCalledInstance() Instance

GetCalledInstance 获取被调节点.

func (EmptyInstanceGauge) GetCircuitBreakerStatus

func (e EmptyInstanceGauge) GetCircuitBreakerStatus() CircuitBreakerStatus

GetCircuitBreakerStatus 实例的熔断状态

func (EmptyInstanceGauge) GetDelay

func (e EmptyInstanceGauge) GetDelay() *time.Duration

GetDelay 调用时延 delay.

func (EmptyInstanceGauge) GetDelayRange

func (e EmptyInstanceGauge) GetDelayRange() ApiDelayRange

GetDelayRange 调用时延.

func (EmptyInstanceGauge) GetHost

func (e EmptyInstanceGauge) GetHost() string

GetHost 实例的节点信息

func (EmptyInstanceGauge) GetNamespace

func (e EmptyInstanceGauge) GetNamespace() string

GetNamespace 获取服务的命名空间

func (EmptyInstanceGauge) GetPort

func (e EmptyInstanceGauge) GetPort() int

GetPort 实例的端口信息

func (EmptyInstanceGauge) GetRetCodeValue

func (e EmptyInstanceGauge) GetRetCodeValue() int32

GetRetCodeValue 实例的返回码 ret code.

func (EmptyInstanceGauge) GetRetStatus

func (e EmptyInstanceGauge) GetRetStatus() RetStatus

GetRetStatus 实例的调用返回状态

func (EmptyInstanceGauge) GetService

func (e EmptyInstanceGauge) GetService() string

GetService 获取服务名

func (EmptyInstanceGauge) Validate

func (e EmptyInstanceGauge) Validate() error

Validate 校验.

type Engine

type Engine interface {
	// Destroy 销毁流程引擎
	Destroy() error
	// SyncGetResources 同步加载资源,可通过配置参数指定一次同时加载多个资源
	SyncGetResources(req CacheValueQuery) error
	// SyncGetOneInstance 同步获取负载均衡后的服务实例
	SyncGetOneInstance(req *GetOneInstanceRequest) (*OneInstanceResponse, error)
	// SyncGetInstances 同步获取批量服务实例
	SyncGetInstances(req *GetInstancesRequest) (*InstancesResponse, error)
	// SyncGetAllInstances 同步获取全量服务实例
	SyncGetAllInstances(req *GetAllInstancesRequest) (*InstancesResponse, error)
	// SyncRegister 同步进行服务注册
	SyncRegister(instance *InstanceRegisterRequest) (*InstanceRegisterResponse, error)
	// SyncDeregister 同步进行服务反注册
	SyncDeregister(instance *InstanceDeRegisterRequest) error
	// SyncHeartbeat 同步进行心跳上报
	SyncHeartbeat(instance *InstanceHeartbeatRequest) error
	// SyncUpdateServiceCallResult 上报调用结果信息
	SyncUpdateServiceCallResult(result *ServiceCallResult) error
	// SyncReportStat 上报实例统计信息
	SyncReportStat(typ MetricType, stat InstanceGauge) error
	// SyncGetServiceRule 同步获取服务规则
	SyncGetServiceRule(
		eventType EventType, req *GetServiceRuleRequest) (*ServiceRuleResponse, error)
	// SyncGetServices 同步获取批量服务
	SyncGetServices(
		eventType EventType, req *GetServicesRequest) (*ServicesResponse, error)
	// AsyncGetQuota 同步获取配额信息
	AsyncGetQuota(request *QuotaRequestImpl) (*QuotaFutureImpl, error)
	// ScheduleTask 启动定时任务
	ScheduleTask(task *PeriodicTask) (chan<- *PriorityTask, TaskValues)
	// WatchService 监听服务的change
	WatchService(request *WatchServiceRequest) (*WatchServiceResponse, error)
	// GetContext 获取上下文
	GetContext() ValueContext
	// InitCalleeService 所需的被调初始化
	InitCalleeService(req *InitCalleeServiceRequest) error
	// SyncGetConfigFile 同步获取配置文件
	SyncGetConfigFile(req *GetConfigFileRequest) (ConfigFile, error)
	// SyncGetConfigGroup 同步获取配置文件
	SyncGetConfigGroup(namespace, fileGroup string) (ConfigFileGroup, error)
	// SyncCreateConfigFile 同步创建配置文件
	SyncCreateConfigFile(namespace, fileGroup, fileName, content string) error
	// SyncUpdateConfigFile 同步更新配置文件
	SyncUpdateConfigFile(namespace, fileGroup, fileName, content string) error
	// SyncPublishConfigFile 同步发布配置文件
	SyncPublishConfigFile(namespace, fileGroup, fileName string) error
	// ProcessRouters 执行路由链过滤,返回经过路由后的实例列表
	ProcessRouters(req *ProcessRoutersRequest) (*InstancesResponse, error)
	// ProcessLoadBalance 执行负载均衡策略,返回负载均衡后的实例
	ProcessLoadBalance(req *ProcessLoadBalanceRequest) (*OneInstanceResponse, error)
	// WatchAllInstances 监听实例变更事件
	WatchAllInstances(request *WatchAllInstancesRequest) (*WatchAllInstancesResponse, error)
	// WatchAllServices 监听服务列表变更事件
	WatchAllServices(request *WatchAllServicesRequest) (*WatchAllServicesResponse, error)
	// Check
	Check(Resource) (*CheckResult, error)
	// Report
	Report(*ResourceStat) error
	// MakeFunctionDecorator
	MakeFunctionDecorator(CustomerFunction, *RequestContext) DecoratorFunction
	// MakeInvokeHandler
	MakeInvokeHandler(*RequestContext) InvokeHandler
}

Engine 编排调度引擎,API相关逻辑在这里执行

type ErrCode

type ErrCode int32

ErrCode 错误码类型,Polaris SDK对外返回错误码都使用该类型

const (
	// ErrCodeSuccess 没有发生错误
	ErrCodeSuccess ErrCode = 0
	// ErrCodeUnknown 未知错误
	ErrCodeUnknown ErrCode = BaseIndexErrCode
	// ErrCodeAPIInvalidArgument API参数非法的错误码
	ErrCodeAPIInvalidArgument ErrCode = BaseIndexErrCode + 1
	// ErrCodeAPIInvalidConfig 配置非法的错误码
	ErrCodeAPIInvalidConfig ErrCode = BaseIndexErrCode + 2
	// ErrCodePluginError 插件错误的错误码
	ErrCodePluginError ErrCode = BaseIndexErrCode + 3
	// ErrCodeAPITimeoutError API超时错误的错误码
	ErrCodeAPITimeoutError ErrCode = BaseIndexErrCode + 4
	// ErrCodeInvalidStateError SDK已经destroy后,继续调API会出现的错误码
	ErrCodeInvalidStateError ErrCode = BaseIndexErrCode + 5
	// ErrCodeServerUserError 连接server时,server返回400错误信息
	ErrCodeServerUserError ErrCode = BaseIndexErrCode + 6
	// ErrCodeNetworkError 连接server时所出现的未知网络异常
	ErrCodeNetworkError ErrCode = BaseIndexErrCode + 7
	// ErrCodeCircuitBreakerError 服务熔断错误
	ErrCodeCircuitBreakerError ErrCode = BaseIndexErrCode + 8
	// ErrCodeInstanceInfoError 实例信息有误,如服务权重信息为空
	ErrCodeInstanceInfoError ErrCode = BaseIndexErrCode + 9
	// ErrCodeAPIInstanceNotFound 服务实例获取失败
	ErrCodeAPIInstanceNotFound ErrCode = BaseIndexErrCode + 10
	// ErrCodeInvalidRule 路由规则非法
	ErrCodeInvalidRule ErrCode = BaseIndexErrCode + 11
	// ErrCodeRouteRuleNotMatch 路由规则匹配失败
	ErrCodeRouteRuleNotMatch ErrCode = BaseIndexErrCode + 12
	// ErrCodeInvalidResponse Server返回的消息不合法
	ErrCodeInvalidResponse ErrCode = BaseIndexErrCode + 13
	// ErrCodeInternalError 内部算法及系统错误
	ErrCodeInternalError ErrCode = BaseIndexErrCode + 14
	// ErrCodeServiceNotFound 服务不存在
	ErrCodeServiceNotFound ErrCode = BaseIndexErrCode + 15
	// ErrCodeServerException server返回500错误
	ErrCodeServerException ErrCode = BaseIndexErrCode + 16
	// ErrCodeLocationNotFound 获取地域信息失败
	ErrCodeLocationNotFound ErrCode = BaseIndexErrCode + 17
	// ErrCodeLocationMismatch 就近路由失败,在对应就近级别上面没有实例
	ErrCodeLocationMismatch ErrCode = BaseIndexErrCode + 18
	// ErrCodeDstMetaMismatch 目标规则元数据过滤失败
	ErrCodeDstMetaMismatch ErrCode = BaseIndexErrCode + 19
	// ErrCodeMeshConfigNotFound 目标类型的网格规则未找到
	ErrCodeMeshConfigNotFound ErrCode = BaseIndexErrCode + 20
	// ErrCodeConsumerInitCalleeError 初始化服务运行中需要的被调服务失败
	ErrCodeConsumerInitCalleeError ErrCode = BaseIndexErrCode + 21
	// ErrCodeCount 接口错误码数量,每添加了一个错误码,将这个数值加1
	ErrCodeCount = 23
)
const (
	ErrCodeConnectError          ErrCode = BaseServerErrCode + 1
	ErrCodeServerError           ErrCode = BaseServerErrCode + 2
	ErrorCodeRpcError            ErrCode = BaseServerErrCode + 3
	ErrorCodeRpcTimeout          ErrCode = BaseServerErrCode + 4
	ErrCodeInvalidServerResponse ErrCode = BaseServerErrCode + 5
	ErrCodeInvalidRequest        ErrCode = BaseServerErrCode + 6
	ErrCodeUnauthorized          ErrCode = BaseServerErrCode + 7
	ErrCodeRequestLimit          ErrCode = BaseServerErrCode + 8
	ErrCodeCmdbNotFound          ErrCode = BaseServerErrCode + 9
	ErrCodeUnknownServerError    ErrCode = BaseServerErrCode + 100
)

func ErrCodeFromIndex

func ErrCodeFromIndex(i int) ErrCode

ErrCodeFromIndex 根据错误码索引返回错误码

func GetErrorCodeFromError

func GetErrorCodeFromError(e error) ErrCode

GetErrorCodeFromError 从错误中获取错误码

func (ErrCode) Retryable

func (e ErrCode) Retryable() bool

Retryable 是否可重试的错误码

type ErrCodeType

type ErrCodeType int

ErrCodeType 错误码类型

const (
	// 北极星系统错误
	PolarisError ErrCodeType = 0
	// 用户错误
	UserError ErrCodeType = 1
)

func GetErrCodeType

func GetErrCodeType(e ErrCode) ErrCodeType

GetErrCodeType 获取错误码类型

type EventType

type EventType uint32

EventType 事件类型,用于标识各种不同的事件

const (
	// EventUnknown 未知事件
	EventUnknown EventType = 0
	// EventInstances 实例事件
	EventInstances EventType = 0x2001
	// EventRouting 路由配置事件
	EventRouting EventType = 0x2002
	// EventRateLimiting 限流配置事件
	EventRateLimiting EventType = 0x2003
	// EventServices 批量服务
	EventServices EventType = 0x2005
	// EventCircuitBreaker 熔断规则
	EventCircuitBreaker EventType = 0x2006
	// EventFaultDetect 探测规则
	EventFaultDetect EventType = 0x2007
)

func ToEventType

func ToEventType(value string) EventType

ToEventType 通过字符串构造事件类型

func (EventType) String

func (e EventType) String() string

String ToString方法

type ExtendedSelector

type ExtendedSelector interface {
	Select(criteria interface{}) (int, *ReplicateNodes, error)

	// ID 对应负载均衡插件的名字
	ID() int32
}

ExtendedSelector 可供插件自定义的实例选择器

type FailOverDefaultMetaConfig

type FailOverDefaultMetaConfig struct {
	// 元数据路由兜底策略类型
	Type FailOverHandler
	// 仅type==CustomMeta时需要填写
	Meta map[string]string
}

FailOverDefaultMetaConfig .

type FailOverHandler

type FailOverHandler int

FailOverHandler 元数据路由兜底策略

const (
	// GetOneHealth 通配所有可用ip实例,等于关闭meta路由
	GetOneHealth FailOverHandler = 1
	// NotContainMetaKey 匹配不带 metaData key路由
	NotContainMetaKey FailOverHandler = 2
	// CustomMeta 匹配自定义meta
	CustomMeta FailOverHandler = 3
)

type FallbackInfo

type FallbackInfo struct {
	Code    int
	Headers map[string]string
	Body    string
}

type FilteredInstanceCounter

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

FilteredInstanceCounter 本地缓存中过滤的实例数量

func (*FilteredInstanceCounter) AddIsolatedInstances

func (f *FilteredInstanceCounter) AddIsolatedInstances(n int32)

AddIsolatedInstances 增加过滤的被隔离实例数量

func (*FilteredInstanceCounter) AddRouteFilteredInstances

func (f *FilteredInstanceCounter) AddRouteFilteredInstances(routerName string, n int32)

AddRouteFilteredInstances 增加被就近接入路由过滤的实例数量

func (*FilteredInstanceCounter) AddUnhealthyInstances

func (f *FilteredInstanceCounter) AddUnhealthyInstances(n int32)

AddUnhealthyInstances 增加过滤的不健康实例数量

func (*FilteredInstanceCounter) GetIsolatedInstances

func (f *FilteredInstanceCounter) GetIsolatedInstances() int32

GetIsolatedInstances 被隔离实例数量

func (*FilteredInstanceCounter) GetUnhealthyInstances

func (f *FilteredInstanceCounter) GetUnhealthyInstances() int32

GetUnhealthyInstances 不健康实例数量

type GetAllInstancesRequest

type GetAllInstancesRequest struct {
	// 可选,流水号,用于跟踪用户的请求,默认0
	FlowID uint64
	// 必选,服务名
	Service string
	// 必选,命名空间
	Namespace string
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
	// contains filtered or unexported fields
}

GetAllInstancesRequest 获取所有实例的请求

func (*GetAllInstancesRequest) GetMetadata

func (g *GetAllInstancesRequest) GetMetadata() map[string]string

GetMetadata 获取命名空间

func (*GetAllInstancesRequest) GetNamespace

func (g *GetAllInstancesRequest) GetNamespace() string

GetNamespace 获取命名空间

func (*GetAllInstancesRequest) GetResponse

func (g *GetAllInstancesRequest) GetResponse() *InstancesResponse

GetResponse 获取应答指针

func (*GetAllInstancesRequest) GetRetryCountPtr

func (g *GetAllInstancesRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*GetAllInstancesRequest) GetService

func (g *GetAllInstancesRequest) GetService() string

GetService 获取服务名

func (*GetAllInstancesRequest) GetTimeoutPtr

func (g *GetAllInstancesRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*GetAllInstancesRequest) SetRetryCount

func (g *GetAllInstancesRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*GetAllInstancesRequest) SetTimeout

func (g *GetAllInstancesRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (*GetAllInstancesRequest) Validate

func (g *GetAllInstancesRequest) Validate() error

Validate 校验获取全部服务实例请求对象

type GetConfigFileRequest

type GetConfigFileRequest struct {
	Namespace string
	FileGroup string
	FileName  string
	Subscribe bool
}

type GetInstancesRequest

type GetInstancesRequest struct {
	// 可选,流水号,用于跟踪用户的请求,默认0
	FlowID uint64
	// 必选,服务名
	Service string
	// 必选,命名空间
	Namespace string
	// 可选,元数据信息,仅用于dstMetadata路由插件的过滤
	Metadata map[string]string
	// 主调方服务信息,只用于路由规则匹配
	SourceService *ServiceInfo
	// 路由标签参数
	Arguments []Argument
	// 可选,是否包含被熔断的服务实例,默认false
	// Deprecated: 已弃用,1.0版本后会正式去掉,需要返回全量IP直接设置SkipRouteFilter=true
	IncludeCircuitBreakInstances bool
	// 可选,是否包含不健康的服务实例,默认false
	// Deprecated: 已弃用,1.0版本后会正式去掉,需要返回全量IP直接设置SkipRouteFilter=true
	IncludeUnhealthyInstances bool
	// 可选,是否跳过服务路由筛选,默认false
	SkipRouteFilter bool
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int

	// 金丝雀
	Canary string
	// contains filtered or unexported fields
}

GetInstancesRequest 批量服务实例查询请求

func (*GetInstancesRequest) AddArguments added in v1.3.0

func (g *GetInstancesRequest) AddArguments(argumet ...Argument)

AddArguments .

func (*GetInstancesRequest) GetCanary

func (g *GetInstancesRequest) GetCanary() string

GetCanary .

func (*GetInstancesRequest) GetMetadata

func (g *GetInstancesRequest) GetMetadata() map[string]string

GetMetadata 获取命名空间

func (*GetInstancesRequest) GetNamespace

func (g *GetInstancesRequest) GetNamespace() string

GetNamespace 获取命名空间

func (*GetInstancesRequest) GetResponse

func (g *GetInstancesRequest) GetResponse() *InstancesResponse

GetResponse 获取应答指针

func (*GetInstancesRequest) GetRetryCountPtr

func (g *GetInstancesRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*GetInstancesRequest) GetService

func (g *GetInstancesRequest) GetService() string

GetService 获取服务名

func (*GetInstancesRequest) GetTimeoutPtr

func (g *GetInstancesRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*GetInstancesRequest) SetCanary

func (g *GetInstancesRequest) SetCanary(canary string)

SetCanary .

func (*GetInstancesRequest) SetRetryCount

func (g *GetInstancesRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*GetInstancesRequest) SetTimeout

func (g *GetInstancesRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (*GetInstancesRequest) Validate

func (g *GetInstancesRequest) Validate() error

Validate 校验获取全部服务实例请求对象

type GetOneInstanceRequest

type GetOneInstanceRequest struct {
	// 可选,流水号,用于跟踪用户的请求,默认0
	FlowID uint64
	// 必选,服务名
	Service string
	// 必选,命名空间
	Namespace string
	// 可选,元数据信息,仅用于dstMetadata路由插件的过滤
	Metadata map[string]string
	// 是否开启元数据匹配不到时启用自定义匹配规则,仅用于dstMetadata路由插件
	EnableFailOverDefaultMeta bool
	// 自定义匹配规则,仅当EnableFailOverDefaultMeta为true时生效
	FailOverDefaultMeta FailOverDefaultMetaConfig
	// 用户计算hash值的key
	HashKey []byte
	// 已经计算好的hash值,用于一致性hash的负载均衡选择
	// Deprecated: 已弃用,请直接使用HashKey参数传入key来计算hash
	HashValue uint64
	// 主调方服务信息
	SourceService *ServiceInfo
	// 路由标签参数
	Arguments []Argument
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
	// 可选,备份节点数
	// 对于一致性hash等有状态的负载均衡方式
	ReplicateCount int

	// 可选,负载均衡算法
	LbPolicy string
	// 金丝雀
	Canary string
	// 可选,是否包含被熔断的服务实例,默认false
	IncludeCircuitBreakInstances bool
	// contains filtered or unexported fields
}

GetOneInstanceRequest 单个服务实例查询请求

func (*GetOneInstanceRequest) AddArguments added in v1.3.0

func (g *GetOneInstanceRequest) AddArguments(argumet ...Argument)

AddArguments .

func (*GetOneInstanceRequest) GetCanary

func (g *GetOneInstanceRequest) GetCanary() string

GetCanary .

func (*GetOneInstanceRequest) GetMetadata

func (g *GetOneInstanceRequest) GetMetadata() map[string]string

GetMetadata 获取命名空间

func (*GetOneInstanceRequest) GetNamespace

func (g *GetOneInstanceRequest) GetNamespace() string

GetNamespace 获取命名空间

func (*GetOneInstanceRequest) GetResponse

func (g *GetOneInstanceRequest) GetResponse() *InstancesResponse

GetResponse 获取应答指针

func (*GetOneInstanceRequest) GetRetryCountPtr

func (g *GetOneInstanceRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*GetOneInstanceRequest) GetService

func (g *GetOneInstanceRequest) GetService() string

GetService 获取服务名

func (*GetOneInstanceRequest) GetTimeoutPtr

func (g *GetOneInstanceRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*GetOneInstanceRequest) SetCanary

func (g *GetOneInstanceRequest) SetCanary(canary string)

SetCanary .

func (*GetOneInstanceRequest) SetRetryCount

func (g *GetOneInstanceRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*GetOneInstanceRequest) SetTimeout

func (g *GetOneInstanceRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (*GetOneInstanceRequest) Validate

func (g *GetOneInstanceRequest) Validate() error

Validate 校验获取单个服务实例请求对象

type GetServiceRuleRequest

type GetServiceRuleRequest struct {
	// 可选,流水号,用于跟踪用户的请求,默认0
	FlowID uint64
	// 命名空间
	Namespace string
	// 服务名
	Service string
	// 可选,仅对同步请求有效,本次查询最大超时信息,可选,默认直接获取全局的超时配置
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
	// contains filtered or unexported fields
}

GetServiceRuleRequest 获取服务规则请求.

func (*GetServiceRuleRequest) GetMetadata

func (g *GetServiceRuleRequest) GetMetadata() map[string]string

GetMetadata 获取元数据信息.

func (*GetServiceRuleRequest) GetNamespace

func (g *GetServiceRuleRequest) GetNamespace() string

GetNamespace 获取命名空间.

func (*GetServiceRuleRequest) GetResponse

func (g *GetServiceRuleRequest) GetResponse() *ServiceRuleResponse

GetResponse 获取应答.

func (*GetServiceRuleRequest) GetRetryCountPtr

func (g *GetServiceRuleRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针.

func (*GetServiceRuleRequest) GetService

func (g *GetServiceRuleRequest) GetService() string

GetService 获取服务名.

func (*GetServiceRuleRequest) GetTimeoutPtr

func (g *GetServiceRuleRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针.

func (*GetServiceRuleRequest) SetRetryCount

func (g *GetServiceRuleRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数.

func (*GetServiceRuleRequest) SetTimeout

func (g *GetServiceRuleRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间.

func (*GetServiceRuleRequest) Validate

func (g *GetServiceRuleRequest) Validate() error

Validate 校验获取服务规则请求对象.

type GetServicesRequest

type GetServicesRequest struct {
	// 可选,流水号,用于跟踪用户的请求,默认0
	FlowID uint64
	// 可选,业务名
	Business string
	// 可选,命名空间
	Namespace string
	// 可选,元数据信息,可用于过滤
	Metadata map[string]string
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
}

GetServicesRequest 获取服务请求

func (*GetServicesRequest) GetRetryCountPtr

func (g *GetServicesRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*GetServicesRequest) GetTimeoutPtr

func (g *GetServicesRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*GetServicesRequest) SetRetryCount

func (g *GetServicesRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*GetServicesRequest) SetTimeout

func (g *GetServicesRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (*GetServicesRequest) Validate

func (g *GetServicesRequest) Validate() error

Validate 验证请求参数

type HalfOpenStatus

type HalfOpenStatus struct {
	BaseCircuitBreakerStatus
	// contains filtered or unexported fields
}

func (*HalfOpenStatus) CalNextStatus

func (c *HalfOpenStatus) CalNextStatus() Status

func (*HalfOpenStatus) IsAvailable

func (c *HalfOpenStatus) IsAvailable() bool

func (*HalfOpenStatus) Report

func (c *HalfOpenStatus) Report(success bool) bool

func (*HalfOpenStatus) Schedule

func (c *HalfOpenStatus) Schedule() bool

type HashSet

type HashSet map[interface{}]bool

HashSet Hash集合数据结构

func (HashSet) Add

func (h HashSet) Add(value interface{})

Add 往集合添加值

func (HashSet) Contains

func (h HashSet) Contains(value interface{}) bool

Contains 值是否存在集合中

func (HashSet) Copy

func (h HashSet) Copy() HashSet

Copy 复制hashSet

func (HashSet) Delete

func (h HashSet) Delete(value interface{}) bool

Delete 往集合删除值

type HealthCheckStatus

type HealthCheckStatus int

HealthCheckStatus 健康探测状态

const (
	// Healthy 节点探测结果已经恢复健康, 代表可以放开一部分流量
	Healthy HealthCheckStatus = 1
	// Dead 节点仍然不可用
	Dead HealthCheckStatus = 2
)

type InitCalleeServiceRequest

type InitCalleeServiceRequest struct {
	Namespace string
	Service   string
	Timeout   *time.Duration
}

InitCalleeServiceRequest .

func (*InitCalleeServiceRequest) Validate

func (g *InitCalleeServiceRequest) Validate() error

Validate .验证请求参数

type InitCircuitBreakerStatus

type InitCircuitBreakerStatus func(CircuitBreakerStatus)

type Instance

type Instance interface {
	// GetInstanceKey 获取实例四元组标识
	GetInstanceKey() InstanceKey
	// GetNamespace 实例所在命名空间
	GetNamespace() string
	// GetService 实例所在服务名
	GetService() string
	// GetId 服务实例唯一标识
	GetId() string
	// GetHost 实例的域名/IP信息
	GetHost() string
	// GetPort 实例的监听端口
	GetPort() uint32
	// GetVpcId 实例的vpcId
	GetVpcId() string
	// GetProtocol 服务实例的协议
	GetProtocol() string
	// GetVersion 实例版本号
	GetVersion() string
	// GetWeight 实例静态权重值
	GetWeight() int
	// GetPriority 实例优先级信息
	GetPriority() uint32
	// GetMetadata 实例元数据信息
	GetMetadata() map[string]string
	// GetLogicSet 实例逻辑分区
	GetLogicSet() string
	// GetCircuitBreakerStatus 实例的断路器状态,包括:
	// 打开(被熔断)、半开(探测恢复)、关闭(正常运行)
	GetCircuitBreakerStatus() CircuitBreakerStatus
	// IsHealthy 实例是否健康,基于服务端返回的健康数据
	IsHealthy() bool
	// IsIsolated 实例是否已经被手动隔离
	IsIsolated() bool
	// IsEnableHealthCheck 实例是否启动了健康检查
	IsEnableHealthCheck() bool
	// GetRegion 实例所属的大区信息
	GetRegion() string
	// GetZone 实例所属的地方信息
	GetZone() string
	// GetIDC .
	// Deprecated,建议使用GetCampus方法
	GetIDC() string
	// GetCampus 实例所属的园区信息
	GetCampus() string
	// GetRevision .获取实例的修订版本信息
	// 与上一次比较,用于确认服务实例是否发生变更
	GetRevision() string
	// GetTtl 获取实例设置的 TTL
	GetTtl() int64
	// SetHealthy
	SetHealthy(status bool)
	// DeepClone deep clone Instance
	DeepClone() Instance
}

Instance 服务实例信息

type InstanceAddEvent

type InstanceAddEvent struct {
	Instances []Instance
}

InstanceAddEvent 实例Add事件

type InstanceDeRegisterRequest

type InstanceDeRegisterRequest struct {
	// 服务名
	Service string
	// 服务访问Token
	ServiceToken string
	// 命名空间
	Namespace string
	// 服务实例ID
	InstanceID string
	// 服务实例ip
	Host string
	// 服务实例端口
	Port int
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
}

InstanceDeRegisterRequest 反注册服务请求

func (*InstanceDeRegisterRequest) GetRetryCountPtr

func (g *InstanceDeRegisterRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*InstanceDeRegisterRequest) GetTimeoutPtr

func (g *InstanceDeRegisterRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*InstanceDeRegisterRequest) SetRetryCount

func (g *InstanceDeRegisterRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*InstanceDeRegisterRequest) SetTimeout

func (g *InstanceDeRegisterRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (InstanceDeRegisterRequest) String

func (g InstanceDeRegisterRequest) String() string

String 打印消息内容

func (*InstanceDeRegisterRequest) Validate

func (g *InstanceDeRegisterRequest) Validate() error

Validate 校验InstanceDeRegisterRequest

type InstanceDeleteEvent

type InstanceDeleteEvent struct {
	Instances []Instance
}

InstanceDeleteEvent 实例Delete事件

type InstanceEvent

type InstanceEvent struct {
	AddEvent    *InstanceAddEvent
	UpdateEvent *InstanceUpdateEvent
	DeleteEvent *InstanceDeleteEvent
}

InstanceEvent 实例事件

func (*InstanceEvent) GetSubScribeEventType

func (e *InstanceEvent) GetSubScribeEventType() SubScribeEventType

GetSubScribeEventType

type InstanceGauge

type InstanceGauge interface {
	// GetNamespace 获取服务的命名空间
	GetNamespace() string
	// GetService 获取服务名
	GetService() string
	// GetAPI 获取调用api
	GetAPI() ApiOperation
	// GetHost 实例的节点信息
	GetHost() string
	// GetPort 实例的端口信息
	GetPort() int
	// GetRetStatus 实例的调用返回状态
	GetRetStatus() RetStatus
	// GetCircuitBreakerStatus 实例的熔断状态
	GetCircuitBreakerStatus() CircuitBreakerStatus
	// GetRetCodeValue 实例的返回码
	GetRetCodeValue() int32
	// GetDelay 调用时延
	GetDelay() *time.Duration
	// GetDelayRange 调用时延
	GetDelayRange() ApiDelayRange
	// GetCalledInstance 获取被调节点
	GetCalledInstance() Instance
	// Validate 检测指标是否合法
	Validate() error
}

InstanceGauge 针对单个实例的单次评估指标.

type InstanceHeartbeatRequest

type InstanceHeartbeatRequest struct {
	// 必选,服务名
	Service string
	// 必选,服务访问Token
	ServiceToken string
	// 必选,命名空间
	Namespace string
	// 必选,服务实例ID
	InstanceID string
	// 必选,服务实例ip
	Host string
	// 必选,服务实例端口
	Port int
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
}

InstanceHeartbeatRequest 心跳上报请求

func (*InstanceHeartbeatRequest) GetRetryCountPtr

func (g *InstanceHeartbeatRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*InstanceHeartbeatRequest) GetTimeoutPtr

func (g *InstanceHeartbeatRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*InstanceHeartbeatRequest) SetRetryCount

func (g *InstanceHeartbeatRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*InstanceHeartbeatRequest) SetTimeout

func (g *InstanceHeartbeatRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (InstanceHeartbeatRequest) String

func (g InstanceHeartbeatRequest) String() string

String 打印消息内容

func (*InstanceHeartbeatRequest) Validate

func (g *InstanceHeartbeatRequest) Validate() error

Validate 校验InstanceDeRegisterRequest

type InstanceKey

type InstanceKey struct {
	ServiceKey
	Host string
	Port int
}

InstanceKey 服务实例的唯一标识

func (InstanceKey) String

func (i InstanceKey) String() string

String ToString方法

type InstanceRegisterRequest

type InstanceRegisterRequest struct {
	// 必选,服务名
	Service string
	// 必选,命名空间
	Namespace string
	// 必选,服务监听host,支持IPv6地址
	Host string
	// 必选,服务实例监听port
	Port int

	// 以下字段可选,默认nil表示客户端不配置,使用服务端配置
	// 可选,服务访问Token
	ServiceToken string
	// 服务协议
	Protocol *string
	// 服务权重,默认100,范围0-10000
	Weight *int
	// 实例优先级,默认为0,数值越小,优先级越高
	Priority *int
	// 实例提供服务版本号
	Version *string
	// 用户自定义metadata信息
	Metadata map[string]string
	// 该服务实例是否健康,默认健康
	Healthy *bool
	// 该服务实例是否隔离,默认不隔离
	Isolate *bool
	// ttl超时时间,如果节点要调用heartbeat上报,则必须填写,否则会400141错误码,单位:秒
	TTL *int

	Location *Location

	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
	// 可选,指定实例id
	InstanceId string
	// 可选, 是否将心跳上报交由 SDK 内部定时任务进行处理
	AutoHeartbeat bool
}

InstanceRegisterRequest 注册服务请求

func (*InstanceRegisterRequest) GetLocation added in v1.1.0

func (g *InstanceRegisterRequest) GetLocation() *Location

GetLocation 获取实例的地址信息

func (*InstanceRegisterRequest) GetRetryCountPtr

func (g *InstanceRegisterRequest) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针

func (*InstanceRegisterRequest) GetTimeoutPtr

func (g *InstanceRegisterRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针

func (*InstanceRegisterRequest) SetDefaultTTL added in v1.2.0

func (g *InstanceRegisterRequest) SetDefaultTTL()

SetDefaultTTL set default ttl

func (*InstanceRegisterRequest) SetHealthy

func (g *InstanceRegisterRequest) SetHealthy(healthy bool)

SetHealthy 设置实例是否健康

func (*InstanceRegisterRequest) SetIsolate

func (g *InstanceRegisterRequest) SetIsolate(isolate bool)

SetIsolate 设置实例是否隔离

func (*InstanceRegisterRequest) SetLocation added in v1.1.0

func (g *InstanceRegisterRequest) SetLocation(loc *Location)

SetLocation 设置服务实例的地理信息

func (*InstanceRegisterRequest) SetRetryCount

func (g *InstanceRegisterRequest) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数

func (*InstanceRegisterRequest) SetTTL

func (g *InstanceRegisterRequest) SetTTL(ttl int)

SetTTL 设置服务实例TTL

func (*InstanceRegisterRequest) SetTimeout

func (g *InstanceRegisterRequest) SetTimeout(duration time.Duration)

SetTimeout 设置超时时间

func (InstanceRegisterRequest) String

func (g InstanceRegisterRequest) String() string

String 打印消息内容

func (*InstanceRegisterRequest) Validate

func (g *InstanceRegisterRequest) Validate() error

Validate 校验InstanceRegisterRequest

type InstanceRegisterResponse

type InstanceRegisterResponse struct {
	// 实例ID
	InstanceID string
	// 实例是否已存在
	Existed bool
}

InstanceRegisterResponse 注册服务应答

type InstanceResource

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

func NewInstanceResource

func NewInstanceResource(svc, caller *ServiceKey, protocol, host string, port uint32) (*InstanceResource, error)

func (InstanceResource) GetCallerService

func (ar InstanceResource) GetCallerService() *ServiceKey

func (InstanceResource) GetLevel

func (ar InstanceResource) GetLevel() fault_tolerance.Level

func (*InstanceResource) GetNode

func (r *InstanceResource) GetNode() Node

func (*InstanceResource) GetProtocol

func (r *InstanceResource) GetProtocol() string

func (InstanceResource) GetService

func (ar InstanceResource) GetService() *ServiceKey

func (*InstanceResource) String

func (r *InstanceResource) String() string

type InstanceSet

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

InstanceSet 服务实例集合

func (*InstanceSet) Count

func (i *InstanceSet) Count() int

Count 实例数

func (*InstanceSet) GetInstances

func (i *InstanceSet) GetInstances() WeightIndexSlice

GetInstances 获取实例下标集合

func (*InstanceSet) GetLock

func (i *InstanceSet) GetLock() sync.Locker

GetLock 获取互斥锁,用于创建selector时使用,防止重复创建selector

func (*InstanceSet) GetRealInstances

func (i *InstanceSet) GetRealInstances() []Instance

GetRealInstances 获取实例对象集合

func (*InstanceSet) GetSelector

func (i *InstanceSet) GetSelector(id int32) ExtendedSelector

GetSelector 获取selector

func (*InstanceSet) GetServiceClusters

func (i *InstanceSet) GetServiceClusters() ServiceClusters

GetServiceClusters 获取当前服务集群

func (*InstanceSet) GetValue

func (i *InstanceSet) GetValue(index int) uint64

GetValue 获取节点累积的权重

func (*InstanceSet) MaxWeight

func (i *InstanceSet) MaxWeight() int

MaxWeight 最大权重

func (*InstanceSet) SetSelector

func (i *InstanceSet) SetSelector(selector ExtendedSelector)

SetSelector 设置selector

func (*InstanceSet) String

func (i *InstanceSet) String() string

String 服务实例集合ToString

func (*InstanceSet) TotalWeight

func (i *InstanceSet) TotalWeight() int

TotalWeight 总权重

type InstanceUpdateEvent

type InstanceUpdateEvent struct {
	UpdateList []OneInstanceUpdate
}

InstanceUpdateEvent 实例Update事件

type InstanceWeight

type InstanceWeight struct {
	// 实例ID
	InstanceID string
	// 实例动态权重值
	DynamicWeight uint32
}

InstanceWeight 节点权重

type InstancesListener added in v1.4.0

type InstancesListener interface {
	// OnInstancesUpdate notify when service instances changed
	OnInstancesUpdate(*InstancesResponse)
}

type InstancesResponse

type InstancesResponse struct {
	ServiceInfo
	// 可选,流水号,用于跟踪用户的请求,默认0
	FlowID uint64
	// 服务权重类型
	TotalWeight int
	// 获取实例的修订版本信息
	// 与上一次比较,用于确认服务实例是否发生变更
	Revision string
	// 获取服务实例hash值
	HashValue uint64
	// 服务实例列表
	Instances []Instance
	// 当前查询结果所属的集群,如果是获取GetOneInstance返回的结果,则为nil
	Cluster *Cluster
	// 服务是否存在
	NotExists bool
}

InstancesResponse 服务实例查询应答

func (*InstancesResponse) GetCluster added in v1.2.0

func (i *InstancesResponse) GetCluster() *Cluster

GetCluster InstancesResponse get the cluster

func (*InstancesResponse) GetHashValue added in v1.4.0

func (i *InstancesResponse) GetHashValue() uint64

GetHashValue 获取数据的hash值

func (*InstancesResponse) GetInstance

func (i *InstancesResponse) GetInstance(instanceID string) Instance

GetInstance 获取单个服务实例

func (*InstancesResponse) GetInstances

func (i *InstancesResponse) GetInstances() []Instance

GetInstances 获取服务实例列表

func (*InstancesResponse) GetRevision

func (i *InstancesResponse) GetRevision() string

GetRevision 获取服务的修订版本信息

func (*InstancesResponse) GetServiceClusters

func (i *InstancesResponse) GetServiceClusters() ServiceClusters

GetServiceClusters 获取集群缓存

func (*InstancesResponse) GetTotalWeight

func (i *InstancesResponse) GetTotalWeight() int

GetTotalWeight 获取全部实例总权重

func (*InstancesResponse) GetType

func (i *InstancesResponse) GetType() EventType

GetType 获取配置类型

func (*InstancesResponse) IsCacheLoaded

func (i *InstancesResponse) IsCacheLoaded() bool

IsCacheLoaded 数据是否来自于缓存文件

func (*InstancesResponse) IsInitialized

func (i *InstancesResponse) IsInitialized() bool

IsInitialized 服务实例列表是否已经加载

func (*InstancesResponse) IsNotExists added in v1.4.0

func (i *InstancesResponse) IsNotExists() bool

IsNotExists 服务是否存在

func (*InstancesResponse) ReloadServiceClusters

func (i *InstancesResponse) ReloadServiceClusters()

ReloadServiceClusters 重建集群缓存

type InvokeHandler

type InvokeHandler interface {
	// AcquirePermission .
	AcquirePermission() (bool, *CallAborted, error)
	// OnSuccess .
	OnSuccess(*ResponseContext)
	// OnError .
	OnError(*ResponseContext)
}

InvokeHandler .

type Location

type Location struct {
	Region string
	Zone   string
	Campus string
}

Location 位置信息

func (*Location) IsEmpty

func (l *Location) IsEmpty() bool

IsEmpty 位置信息是否为空

func (Location) String

func (l Location) String() string

String 位置信息ToString

type LocationBasedMetaKey

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

LocationBasedMetaKey 基于某个地域信息的元数据查询key

type LocationInfo

type LocationInfo interface {
	// GetLocation 获取地域明细
	GetLocation() *Location
	// GetLastError 在地域信息获取过程中的错误信息
	GetLastError() SDKError
	// GetStatus 获取地域信息状态
	GetStatus() uint32
	// IsLocationInitialized 查看地域信息是否已初始化状态
	IsLocationInitialized() bool
	// IsLocationReady 查看地域信息是否ready状态
	IsLocationReady() bool
}

LocationInfo 地域信息

type MeshKey

type MeshKey struct {
	// 命名空间
	// Namespace string
	Business string
	TypeUrl  string
}

func (MeshKey) String

func (s MeshKey) String() string

String ToString方法

type MetaComposedValue

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

MetaComposedValue 单个结构,针对单个会进行优化

type MethodResource

type MethodResource struct {
	Method string
	// contains filtered or unexported fields
}

func NewMethodResource

func NewMethodResource(svc, caller *ServiceKey, method string) (*MethodResource, error)

func (MethodResource) GetCallerService

func (ar MethodResource) GetCallerService() *ServiceKey

func (MethodResource) GetLevel

func (ar MethodResource) GetLevel() fault_tolerance.Level

func (MethodResource) GetService

func (ar MethodResource) GetService() *ServiceKey

func (*MethodResource) String

func (r *MethodResource) String() string

type MetricType

type MetricType int

MetricType 统计类型.

const (
	SDKAPIStat MetricType = iota
	ServiceStat
	InstanceStat
	SDKCfgStat
	CircuitBreakStat
	PluginAPIStat
	LoadBalanceStat
	RateLimitStat
	RouteStat
)

type Node

type Node struct {
	Host string
	Port uint32
}

func (Node) String

func (n Node) String() string

type NotifyTrigger

type NotifyTrigger struct {
	EnableDstInstances bool
	EnableDstRoute     bool
	EnableSrcRoute     bool
	EnableDstRateLimit bool
	EnableServices     bool
}

NotifyTrigger 通知开关,标识本次需要获取哪些资源

func (*NotifyTrigger) Clear

func (n *NotifyTrigger) Clear()

Clear 清理缓存信息

type OnConfigFileChange added in v1.1.0

type OnConfigFileChange func(event ConfigFileChangeEvent)

OnConfigFileChange 配置文件变更回调监听器

type OnConfigGroupChange added in v1.5.6

type OnConfigGroupChange func(event *ConfigGroupChangeEvent)

OnConfigGroupChange .

type OneInstanceResponse

type OneInstanceResponse struct {
	InstancesResponse
}

OneInstanceResponse 单个服务实例

func (*OneInstanceResponse) GetInstance

func (o *OneInstanceResponse) GetInstance() Instance

GetInstance get the only instance

type OneInstanceUpdate

type OneInstanceUpdate struct {
	Before Instance
	After  Instance
}

OneInstanceUpdate 实例one update struct

type PeriodicCallBack

type PeriodicCallBack interface {
	// 任务回调函数
	// 参数说明:
	// lastProcessTime:上一次任务处理时间
	// taskKey:任务数据主键
	// taskValue: 任务数据值
	// 返回值:
	// TaskResult:后续是否继续执行,本次是否忽略
	Process(taskKey interface{}, taskValue interface{}, lastProcessTime time.Time) TaskResult
	// OnTaskEvent 任务事件回调
	OnTaskEvent(event TaskEvent)
}

PeriodicCallBack 回调接口

type PeriodicTask

type PeriodicTask struct {
	// 任务标识
	Name string
	// 定时任务回调
	CallBack PeriodicCallBack
	// 是否需要处理高优先级任务
	TakePriority bool
	// 是否长稳运行
	LongRun bool
	// 调度周期
	Period time.Duration
	// 是否延迟启动,为true的话,则会延迟一个周期再执行第一次任务
	DelayStart bool
}

PeriodicTask 周期执行的任务信息(含高优先级任务)

type PriorityCallBack

type PriorityCallBack interface {
	// 处理任务内容
	Process()
}

PriorityCallBack 调度高优先级任务

type PriorityTask

type PriorityTask struct {
	// 任务标识
	Name string
	// 任务执行回调函数
	CallBack PriorityCallBack
}

PriorityTask 任务结构

type ProcessLoadBalanceRequest added in v1.2.0

type ProcessLoadBalanceRequest struct {
	// DstInstances indicate the destination instances resolved from discovery, required.
	// Two implementations to ServiceInstances:
	// 1. InstancesResponse, returned from ConsumerAPI.GetAllInstances.
	// 2. DefaultServiceInstances, for user to construct manually.
	DstInstances ServiceInstances
	// LbPolicy indicate the load balancer plugin, optional.
	// If empty, it will use the default load balancer config by console or sdk.
	LbPolicy string
	// HashKey indicate the hash key to do load balance, optional.
	HashKey []byte
	// ReplicateCount indicate the sibling count in consist hash ring, optional.
	ReplicateCount int
	// contains filtered or unexported fields
}

ProcessLoadBalanceRequest the input request parameters for RouterAPI.ProcessLoadBalance

func (*ProcessLoadBalanceRequest) GetResponse added in v1.2.0

func (p *ProcessLoadBalanceRequest) GetResponse() *InstancesResponse

GetResponse get the response object

func (*ProcessLoadBalanceRequest) Validate added in v1.2.0

func (p *ProcessLoadBalanceRequest) Validate() error

Validate validate the request object

type ProcessRoutersRequest added in v1.2.0

type ProcessRoutersRequest struct {
	// Routers indicate the router plugins, optional.
	// If empty, it will use the default routers config by console or sdk.
	Routers []string
	// SourceService indicate the source service to match the route rule, optional.
	SourceService ServiceInfo
	// Arguments traffic labels
	Arguments []Argument
	// DstInstances indicate the destination instances resolved from discovery, required.
	// Two implementations to ServiceInstances:
	// 1. InstancesResponse, returned from ConsumerAPI.GetAllInstances.
	// 2. DefaultServiceInstances, for user to construct manually.
	DstInstances ServiceInstances
	// Method indicate the invoke method to match the route rule, optional.
	Method string
	// Timeout indicate the max timeout for single remote request, optional.
	// Total request timeout is (1+RetryCount) * Timeout, default is 1s
	Timeout *time.Duration
	// RetryCount indicate the request retry count, default is 0
	RetryCount *int
	// contains filtered or unexported fields
}

ProcessRoutersRequest the input request parameters for RouterAPI.ProcessRouters

func (*ProcessRoutersRequest) AddArguments added in v1.3.0

func (p *ProcessRoutersRequest) AddArguments(arg ...Argument)

AddArgument add one traffic label

func (*ProcessRoutersRequest) GetResponse added in v1.2.0

func (p *ProcessRoutersRequest) GetResponse() *InstancesResponse

GetResponse get the response object

func (*ProcessRoutersRequest) GetRetryCountPtr added in v1.2.0

func (p *ProcessRoutersRequest) GetRetryCountPtr() *int

GetRetryCountPtr get the retry count pointer

func (*ProcessRoutersRequest) GetTimeoutPtr added in v1.2.0

func (p *ProcessRoutersRequest) GetTimeoutPtr() *time.Duration

GetTimeoutPtr get the timeout pointer

func (*ProcessRoutersRequest) SetRetryCount added in v1.2.0

func (p *ProcessRoutersRequest) SetRetryCount(v int)

SetRetryCount set the retry count to request

func (*ProcessRoutersRequest) SetTimeout added in v1.2.0

func (p *ProcessRoutersRequest) SetTimeout(duration time.Duration)

SetTimeout set the timeout value to request

func (*ProcessRoutersRequest) Validate added in v1.2.0

func (p *ProcessRoutersRequest) Validate() error

Validate validate the request object

type QuotaFutureImpl

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

QuotaFutureImpl 异步获取配额的future.

func QuotaFutureWithResponse added in v1.2.0

func QuotaFutureWithResponse(resp *QuotaResponse) *QuotaFutureImpl

func (*QuotaFutureImpl) Done

func (q *QuotaFutureImpl) Done() <-chan struct{}

Done 分配是否结束.

func (*QuotaFutureImpl) Get

func (q *QuotaFutureImpl) Get() *QuotaResponse

Get 获取分配结果.

func (*QuotaFutureImpl) GetImmediately added in v1.2.0

func (q *QuotaFutureImpl) GetImmediately() *QuotaResponse

func (*QuotaFutureImpl) Release

func (q *QuotaFutureImpl) Release()

Release 释放资源,仅用于并发数限流的场景.

type QuotaRequestImpl

type QuotaRequestImpl struct {

	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout *time.Duration
	// 可选,重试次数,默认直接获取全局的超时配置
	RetryCount *int
	// 可选,获取的配额数
	Token uint32
	// contains filtered or unexported fields
}

QuotaRequestImpl 配额获取的请求.

func (*QuotaRequestImpl) AddArgument added in v1.2.0

func (q *QuotaRequestImpl) AddArgument(argument Argument)

AddArgument add the match argument

func (*QuotaRequestImpl) Arguments added in v1.2.0

func (q *QuotaRequestImpl) Arguments() []Argument

func (*QuotaRequestImpl) GetLabels

func (q *QuotaRequestImpl) GetLabels() map[string]string

GetLabels 获取业务标签.

func (*QuotaRequestImpl) GetMethod added in v1.2.0

func (q *QuotaRequestImpl) GetMethod() string

func (*QuotaRequestImpl) GetNamespace

func (q *QuotaRequestImpl) GetNamespace() string

GetNamespace 获取命名空间.

func (*QuotaRequestImpl) GetRetryCountPtr

func (q *QuotaRequestImpl) GetRetryCountPtr() *int

GetRetryCountPtr 获取重试次数指针.

func (*QuotaRequestImpl) GetService

func (q *QuotaRequestImpl) GetService() string

GetService 获取服务名.

func (*QuotaRequestImpl) GetTimeoutPtr

func (q *QuotaRequestImpl) GetTimeoutPtr() *time.Duration

GetTimeoutPtr 获取超时值指针.

func (*QuotaRequestImpl) GetToken added in v1.2.0

func (q *QuotaRequestImpl) GetToken() uint32

GetToken get token

func (*QuotaRequestImpl) SetLabels

func (q *QuotaRequestImpl) SetLabels(labels map[string]string)

SetLabels 设置业务标签.

func (*QuotaRequestImpl) SetMethod added in v1.2.0

func (q *QuotaRequestImpl) SetMethod(method string)

SetMethod set method

func (*QuotaRequestImpl) SetNamespace

func (q *QuotaRequestImpl) SetNamespace(namespace string)

SetNamespace 设置命名空间.

func (*QuotaRequestImpl) SetRetryCount

func (q *QuotaRequestImpl) SetRetryCount(retryCount int)

SetRetryCount 设置重试次数.

func (*QuotaRequestImpl) SetService

func (q *QuotaRequestImpl) SetService(svc string)

SetService 设置服务名称.

func (*QuotaRequestImpl) SetTimeout

func (q *QuotaRequestImpl) SetTimeout(timeout time.Duration)

SetTimeout 设置单次查询超时时间.

func (*QuotaRequestImpl) SetToken added in v1.2.0

func (q *QuotaRequestImpl) SetToken(token uint32)

SetToken set token

func (*QuotaRequestImpl) Validate

func (q *QuotaRequestImpl) Validate() error

Validate 校验.

type QuotaResponse

type QuotaResponse struct {
	// 配额分配的返回码
	Code QuotaResultCode
	// 配额分配的结果提示信息
	Info string
	// 需要等待的时间段
	WaitMs int64
}

QuotaResponse 配额查询应答.

type QuotaResultCode

type QuotaResultCode int

QuotaResultCode 应答码.

const (
	// QuotaResultOk 应答码:成功.
	QuotaResultOk QuotaResultCode = 0
	// QuotaResultLimited 应答码:限制.
	QuotaResultLimited QuotaResultCode = -1
)

type RateLimitGauge added in v1.1.0

type RateLimitGauge struct {
	EmptyInstanceGauge
	Namespace string
	Service   string
	Method    string
	Arguments []Argument
	Result    QuotaResultCode
	RuleName  string
}

RateLimitGauge Rate Limit Gauge

type RegistryValue

type RegistryValue interface {
	// GetType 获取配置类型
	GetType() EventType
	// IsInitialized 是否初始化,实例列表或路由值是否加载
	IsInitialized() bool
	// GetRevision 获取服务实例或规则的版本号
	GetRevision() string
	// GetHashValue 获取资源的hash值
	GetHashValue() uint64
	// IsNotExists 资源是否存在
	IsNotExists() bool
}

RegistryValue 存储于sdk缓存中的对象,包括服务实例和服务路由

type ReplicateNodes

type ReplicateNodes struct {
	// 所依附的集群缓存
	SvcClusters ServiceClusters
	// 备份节点数
	Count int
	// 实例下标
	Indexes []int
	// 实例列表缓存
	Instances atomic.Value
}

ReplicateNodes 备份节点Set

func (*ReplicateNodes) GetInstances

func (r *ReplicateNodes) GetInstances() []Instance

GetInstances 获取服务实例

type ReportClientRequest

type ReportClientRequest struct {
	// 客户端进程唯一标识
	ID string
	// 客户端IP地址
	Host string
	// 客户端类型
	Type string
	// 客户端版本信息
	Version string
	// 可选,单次查询超时时间,默认直接获取全局的超时配置
	// 用户总最大超时时间为(1+RetryCount) * Timeout
	Timeout time.Duration
	// 地理位置信息
	Location *Location
	// 监控插件的上报信息
	StatInfos []StatInfo
	// 持久化回调
	PersistHandler func(message proto.Message) error
}

ReportClientRequest 客户端上报请求信息

func (*ReportClientRequest) Validate

func (r *ReportClientRequest) Validate() error

Validate 校验ReportClientRequest

type ReportClientResponse

type ReportClientResponse struct {
	Mode    RunMode
	Version string
	Region  string
	Zone    string
	Campus  string
}

ReportClientResponse 客户端上报应答信息

type RequestContext

type RequestContext struct {
	Caller      *ServiceKey
	Callee      *ServiceKey
	Method      string
	CodeConvert ResultToErrorCode
}

type Resource

type Resource interface {
	fmt.Stringer
	// GetLevel
	GetLevel() fault_tolerance.Level
	// GetService
	GetService() *ServiceKey
	// GetCallerService
	GetCallerService() *ServiceKey
}

Resource

type ResourceStat

type ResourceStat struct {
	Resource  Resource
	RetCode   string
	Delay     time.Duration
	RetStatus RetStatus
}

type ResponseContext

type ResponseContext struct {
	Duration time.Duration
	Result   interface{}
	Err      error
}

type ResultToErrorCode

type ResultToErrorCode interface {
	// OnSuccess
	OnSuccess(val interface{}) string
	// OnError
	OnError(err error) string
}

type RetStatus

type RetStatus string

RetStatus 调用结果状态

const (
	// RetSuccess 调用成功
	RetSuccess RetStatus = "success"
	// RetFail 调用失败
	RetFail RetStatus = "fail"
	// RetTimeout 调用超时
	RetTimeout RetStatus = "timeout"
	// RetFlowControl 限流
	RetFlowControl RetStatus = "flow_control"
	// RetReject 被熔断
	RetReject RetStatus = "reject"
	// RetUnknown
	RetUnknown RetStatus = "unknown"
)

type RuleCache

type RuleCache interface {
	// 通过字面值获取表达式对象
	GetRegexMatcher(message string) (*regexp.Regexp, error)
	// 获取消息缓存
	GetMessageCache(message proto.Message) interface{}
	// 设置消息缓存
	SetMessageCache(message proto.Message, cacheValue interface{})
}

RuleCache 服务规则缓存.

func NewRuleCache

func NewRuleCache() RuleCache

NewRuleCache 创建规则缓存对象.

type RunMode

type RunMode int

RunMode SDK的运行模式,可以指定为agent或者no-agent模式

type SDKError

type SDKError interface {
	// 获取错误码
	ErrorCode() ErrCode
	// 获取错误信息
	Error() string
	// 获取服务端返回的错误码
	ServerCode() uint32
	// 获取服务端返回的错误信息
	ServerInfo() string
}

SDKError SDK错误的总封装类型

func NewSDKError

func NewSDKError(errCode ErrCode, cause error, msg string, args ...interface{}) SDKError

NewSDKError SDK错误相关的类构建器

func NewSDKErrorWithServerInfo added in v1.2.0

func NewSDKErrorWithServerInfo(errCode ErrCode, cause error, serverCode uint32, serverInfo string, msg string, args ...interface{}) SDKError

NewSDKErrorWithServerInfo SDK错误相关的类构建器

func NewServerSDKError

func NewServerSDKError(serverCode uint32, serverInfo string, cause error, msg string, args ...interface{}) SDKError

NewServerSDKError 构造服务端相关错误

type SDKToken

type SDKToken struct {
	IP       string
	PID      int32
	UID      string
	Client   string
	Version  string
	PodName  string
	HostName string
}

SDKToken sdkContext的唯一标识

func (*SDKToken) InitUID

func (sdkToken *SDKToken) InitUID()

type SelectorBase

type SelectorBase struct {
	Id int32
}

SelectorBase 插件自定义的实例选择器base

func (*SelectorBase) ID

func (s *SelectorBase) ID() int32

type ServiceCallResult

type ServiceCallResult struct {
	EmptyInstanceGauge
	// 上报的服务实例
	CalledInstance Instance
	// 调用接口方法
	Method string
	// 必选,本地服务调用的状态,正常or异常
	RetStatus RetStatus
	// 必选,本地服务调用的返回码
	RetCode *int32
	// 必选,被调服务实例获取接口的最大时延
	Delay *time.Duration
	// 可选,主调实例的IP信息
	CalledIP string
	// 可选,生效的规则名称
	RuleName string
	// 可选,主调服务实例的服务信息
	SourceService *ServiceInfo
}

ServiceCallResult 服务调用结果

func (*ServiceCallResult) GetCalledInstance

func (s *ServiceCallResult) GetCalledInstance() Instance

GetCalledInstance 获取被调服务实例

func (*ServiceCallResult) GetCallerNamespace added in v1.2.0

func (s *ServiceCallResult) GetCallerNamespace() string

GetCallerNamespace 获取主调服务实例的命名空间

func (*ServiceCallResult) GetCallerService added in v1.2.0

func (s *ServiceCallResult) GetCallerService() string

GetCallerService 获取主调服务实例的服务信息

func (*ServiceCallResult) GetDelay

func (s *ServiceCallResult) GetDelay() *time.Duration

GetDelay 调用时延

func (*ServiceCallResult) GetHost

func (s *ServiceCallResult) GetHost() string

GetHost 实例的节点信息

func (*ServiceCallResult) GetID

func (s *ServiceCallResult) GetID() string

GetID 实例ID

func (*ServiceCallResult) GetMethod added in v1.5.2

func (s *ServiceCallResult) GetMethod() string

GetMethod 调用时延

func (*ServiceCallResult) GetNamespace

func (s *ServiceCallResult) GetNamespace() string

GetNamespace 实例所属命名空间

func (*ServiceCallResult) GetPort

func (s *ServiceCallResult) GetPort() int

GetPort 实例的端口信息

func (*ServiceCallResult) GetRetCode

func (s *ServiceCallResult) GetRetCode() *int32

GetRetCode 实例的返回码

func (*ServiceCallResult) GetRetCodeValue

func (s *ServiceCallResult) GetRetCodeValue() int32

GetRetCodeValue 实例的返回码

func (*ServiceCallResult) GetRetStatus

func (s *ServiceCallResult) GetRetStatus() RetStatus

GetRetStatus 获取本地调用状态

func (*ServiceCallResult) GetService

func (s *ServiceCallResult) GetService() string

GetService 实例所属服务名

func (*ServiceCallResult) SetCalledInstance

func (s *ServiceCallResult) SetCalledInstance(inst Instance) *ServiceCallResult

SetCalledInstance 设置实例

func (*ServiceCallResult) SetDelay

func (s *ServiceCallResult) SetDelay(duration time.Duration) *ServiceCallResult

SetDelay 设置时延值

func (*ServiceCallResult) SetMethod added in v1.5.2

func (s *ServiceCallResult) SetMethod(method string)

SetMethod 调用时延

func (*ServiceCallResult) SetRetCode

func (s *ServiceCallResult) SetRetCode(value int32) *ServiceCallResult

SetRetCode 设置实例返回码

func (*ServiceCallResult) SetRetStatus

func (s *ServiceCallResult) SetRetStatus(retStatus RetStatus) *ServiceCallResult

SetRetStatus 设置返回状态

func (*ServiceCallResult) Validate

func (s *ServiceCallResult) Validate() error

Validate 校验InstanceDeRegisterRequest

type ServiceClusters

type ServiceClusters interface {
	// GetNearbyCluster 获取就近集群
	GetNearbyCluster(location Location) (*Cluster, int)
	// SetNearbyCluster 设置就近集群
	SetNearbyCluster(location Location, cluster *Cluster, matchLevel int)
	// GetClusterInstances 获取缓存值
	GetClusterInstances(cacheKey ClusterKey) *ClusterValue
	// GetContainNotMatchMetaKeyClusterInstances 获取 包含指定key但是不匹配value 的ClusterValue
	GetContainNotMatchMetaKeyClusterInstances(cacheKey ClusterKey) *ClusterValue
	// GetNotContainMetaKeyClusterInstances 获取不包含指定meta的ClusterValue
	GetNotContainMetaKeyClusterInstances(cacheKey ClusterKey) *ClusterValue
	// GetContainMetaKeyClusterInstances 获取包含指定meta key的ClusterValue
	GetContainMetaKeyClusterInstances(cacheKey ClusterKey) *ClusterValue
	// AddInstance 构建缓存实例
	AddInstance(instance Instance)
	// HasRegion 服务存在该大区
	HasRegion(region string) bool
	// HasZone 服务存在该园区
	HasZone(zone string) bool
	// HasCampus 服务存在该机房
	HasCampus(campus string) bool
	// IsNearbyEnabled 是否开启了就近路由
	IsNearbyEnabled() bool
	// IsCanaryEnabled 是否开启了金丝雀路由
	IsCanaryEnabled() bool
	// GetInstanceMetaValues 获取实例的标签集合
	GetInstanceMetaValues(location Location, metaKey string) map[string]string
	// GetServiceKey 获取服务二元组信息
	GetServiceKey() ServiceKey
	// GetServiceInstances 获取所属服务
	GetServiceInstances() ServiceInstances
	// GetExtendedCacheValue 获取扩展的缓存值
	GetExtendedCacheValue(pluginIndex int) interface{}
	// SetExtendedCacheValue 设置扩展的缓存值,需要预初始化好,否则会有并发修改的问题
	SetExtendedCacheValue(pluginIndex int, value interface{})
	// GetInstancesWithMetaValuesNotEqual 获取该标签不等于指定标签值的实例集合
	GetInstancesWithMetaValuesNotEqual(location Location, metaKey string, metavalue string) map[string]string
}

ServiceClusters 集群缓存接口

func NewServiceClusters

func NewServiceClusters(svcInstances ServiceInstances) ServiceClusters

NewServiceClusters 创建集群缓存

type ServiceEventKey

type ServiceEventKey struct {
	// 服务标识
	ServiceKey
	// 网格标识
	// MeshKey
	// 值类型
	Type EventType
}

ServiceEventKey 服务加规则的唯一标识KEY

func (ServiceEventKey) String

func (s ServiceEventKey) String() string

String ToString方法

type ServiceInfo

type ServiceInfo struct {
	// 必选,服务名
	Service string
	// 必选,命名空间
	Namespace string
	// 可选,服务元数据信息
	Metadata map[string]string
}

ServiceInfo 服务信息

func (*ServiceInfo) AddArgument added in v1.3.0

func (i *ServiceInfo) AddArgument(arg Argument)

AddArgument 添加本次流量标签参数

func (*ServiceInfo) GetMetadata

func (i *ServiceInfo) GetMetadata() map[string]string

GetMetadata 获取元数据信息

func (*ServiceInfo) GetNamespace

func (i *ServiceInfo) GetNamespace() string

GetNamespace 获取命名空间

func (*ServiceInfo) GetService

func (i *ServiceInfo) GetService() string

GetService 获取服务名

func (*ServiceInfo) HasService added in v1.2.0

func (i *ServiceInfo) HasService() bool

HasService 是否存在服务名

func (*ServiceInfo) IsEmpty added in v1.2.0

func (i *ServiceInfo) IsEmpty() bool

IsEmpty 服务数据内容是否为空

func (ServiceInfo) String

func (i ServiceInfo) String() string

String 格式化输出内容

type ServiceInstances

type ServiceInstances interface {
	ServiceMetadata
	RegistryValue
	// GetInstances 获取服务实例列表
	GetInstances() []Instance
	// GetTotalWeight 获取全部实例总权重
	GetTotalWeight() int
	// GetServiceClusters 获取集群索引
	GetServiceClusters() ServiceClusters
	// ReloadServiceClusters 重建缓存索引
	ReloadServiceClusters()
	// GetInstance 获取单个服务实例
	GetInstance(string) Instance
	// IsCacheLoaded 数据是否来自于缓存文件
	IsCacheLoaded() bool
}

ServiceInstances 服务实例列表

func NewDefaultServiceInstances added in v1.2.0

func NewDefaultServiceInstances(service ServiceInfo, instances []Instance) ServiceInstances

func NewDefaultServiceInstancesWithRegistryValue added in v1.5.0

func NewDefaultServiceInstancesWithRegistryValue(service ServiceInfo, registryValue RegistryValue, instances []Instance) ServiceInstances

type ServiceKey

type ServiceKey struct {
	// 命名空间
	Namespace string
	// 服务名
	Service string
}

ServiceKey 服务的唯一标识KEY

func (ServiceKey) String

func (s ServiceKey) String() string

String ToString方法

type ServiceMetadata

type ServiceMetadata interface {
	// GetService 获取服务名
	GetService() string
	// GetNamespace 获取命名空间
	GetNamespace() string
	// GetMetadata 获取元数据信息
	GetMetadata() map[string]string
}

ServiceMetadata 服务元数据信息

type ServiceResource

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

func NewServiceResource

func NewServiceResource(svc, caller *ServiceKey) (*ServiceResource, error)

func (ServiceResource) GetCallerService

func (ar ServiceResource) GetCallerService() *ServiceKey

func (ServiceResource) GetLevel

func (ar ServiceResource) GetLevel() fault_tolerance.Level

func (ServiceResource) GetService

func (ar ServiceResource) GetService() *ServiceKey

func (*ServiceResource) String

func (r *ServiceResource) String() string

type ServiceRule

type ServiceRule interface {
	RegistryValue
	// 获取路由所属服务的命名空间
	GetNamespace() string
	// 获取路由所属服务的服务名
	GetService() string
	// 获取值
	// PB场景下,路由规则类型为*Routing
	GetValue() interface{}
	// 获取规则缓存信息
	GetRuleCache() RuleCache
	// 获取规则校验失败异常
	GetValidateError() error

	IsCacheLoaded() bool
}

ServiceRule 服务配置通用接口.

type ServiceRuleListener added in v1.4.0

type ServiceRuleListener interface {
	// OnServiceRuleUpdate notify when service rule changed
	OnServiceRuleUpdate(*ServiceRuleResponse)
}

type ServiceRuleResponse

type ServiceRuleResponse struct {
	// 规则类型
	Type EventType
	// 所属服务
	Service ServiceKey
	// 规则对象,不同EventType对应不同类型实例
	Value interface{}
	// 规则版本信息
	Revision string
	// 规则hash值
	HashValue uint64
	// 规则缓存
	RuleCache RuleCache
	// 规则校验异常
	ValidateError error
	// 服务是否存在
	NotExists bool
}

ServiceRuleResponse 服务规则应答.

func (*ServiceRuleResponse) GetHashValue added in v1.4.0

func (s *ServiceRuleResponse) GetHashValue() uint64

GetHashValue 获取数据的hash值

func (*ServiceRuleResponse) GetNamespace

func (s *ServiceRuleResponse) GetNamespace() string

GetNamespace 获取命名空间.

func (*ServiceRuleResponse) GetRevision

func (s *ServiceRuleResponse) GetRevision() string

GetRevision 获取配置规则的修订版本信息.

func (*ServiceRuleResponse) GetRuleCache

func (s *ServiceRuleResponse) GetRuleCache() RuleCache

GetRuleCache 获取规则缓存信息.

func (*ServiceRuleResponse) GetService

func (s *ServiceRuleResponse) GetService() string

GetService 获取服务名.

func (*ServiceRuleResponse) GetType

func (s *ServiceRuleResponse) GetType() EventType

GetType 获取配置类型.

func (*ServiceRuleResponse) GetValidateError

func (s *ServiceRuleResponse) GetValidateError() error

GetValidateError 获取规则校验异常.

func (*ServiceRuleResponse) GetValue

func (s *ServiceRuleResponse) GetValue() interface{}

GetValue 获取值 PB场景下,路由规则类型为*Routing.

func (*ServiceRuleResponse) IsCacheLoaded

func (s *ServiceRuleResponse) IsCacheLoaded() bool

func (*ServiceRuleResponse) IsInitialized

func (s *ServiceRuleResponse) IsInitialized() bool

IsInitialized 配置规则是否已经加载.

func (*ServiceRuleResponse) IsNotExists added in v1.4.0

func (s *ServiceRuleResponse) IsNotExists() bool

IsNotExists 规则是否存在

type Services

type Services interface {
	RegistryValue
	GetValue() []*ServiceKey
	GetNamespace() string
}

Services 批量服务

type ServicesListener added in v1.4.1

type ServicesListener interface {
	// OnServicesUpdate notify when service list changed
	OnServicesUpdate(*ServicesResponse)
}

type ServicesResponse

type ServicesResponse struct {
	// 规则类型
	Type EventType
	// 规则对象,不同EventType对应不同类型实例
	Value []*ServiceKey
	// 规则版本信息
	Revision string
	// 规则的hash值
	HashValue uint64
	// 规则缓存
	// RuleCache RuleCache
	// 规则校验异常
	ValidateError error
}

ServicesResponse 批量服务应答

func (*ServicesResponse) GetHashValue added in v1.4.0

func (s *ServicesResponse) GetHashValue() uint64

GetHashValue 获取数据的hash值

func (*ServicesResponse) GetRevision

func (s *ServicesResponse) GetRevision() string

GetRevision 获取配置规则的修订版本信息

func (*ServicesResponse) GetType

func (s *ServicesResponse) GetType() EventType

GetType 获取类型

func (*ServicesResponse) GetValidateError

func (s *ServicesResponse) GetValidateError() error

GetValidateError 获取规则校验异常

func (*ServicesResponse) GetValue

func (s *ServicesResponse) GetValue() []*ServiceKey

GetValue 获取值 PB场景下,路由规则类型为*Routing

func (*ServicesResponse) IsInitialized

func (s *ServicesResponse) IsInitialized() bool

IsInitialized 配置规则是否已经加载

func (*ServicesResponse) IsNotExists added in v1.4.0

func (s *ServicesResponse) IsNotExists() bool

IsNotExists 资源是否存在

type SimpleConfigFile added in v1.5.6

type SimpleConfigFile struct {
	Namespace   string
	FileGroup   string
	FileName    string
	Version     uint64
	Md5         string
	ReleaseTime time.Time
}

type StatInfo added in v1.1.0

type StatInfo struct {
	Target   string
	Port     uint32
	Path     string
	Protocol string
}

StatInfo 监控插件元数据信息

func (StatInfo) Empty added in v1.1.0

func (s StatInfo) Empty() bool

type Status

type Status int

Status 断路器状态

const (
	// Open 断路器已打开,代表节点已经被熔断
	Open Status = 1
	// HalfOpen 断路器半开,节点处于刚熔断恢复,只允许少量请求通过
	HalfOpen Status = 2
	// Close 断路器关闭,节点处于正常工作状态
	Close Status = 3
)

func (Status) String

func (s Status) String() string

String toString method

type SubScribeEvent

type SubScribeEvent interface {
	// GetSubScribeEventType
	GetSubScribeEventType() SubScribeEventType
}

type SubScribeEventType

type SubScribeEventType int
const (
	// service实例事件
	EventInstance SubScribeEventType = 1
)

type SyncHashSet

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

SyncHashSet 协程安全的HashSet

func NewSyncHashSet

func NewSyncHashSet() *SyncHashSet

NewSyncHashSet 创建协程安全的HashSet

func (*SyncHashSet) Add

func (s *SyncHashSet) Add(value interface{})

Add 往set添加元素

func (*SyncHashSet) Contains

func (s *SyncHashSet) Contains(value interface{}) bool

Contains 检查元素存在性

func (*SyncHashSet) Copy

func (s *SyncHashSet) Copy() HashSet

Copy 拷贝列表的元素

func (*SyncHashSet) Delete

func (s *SyncHashSet) Delete(value interface{}) bool

Delete 删除元素

type TaskEvent

type TaskEvent int
const (
	// EventStart 任务启动事件
	EventStart TaskEvent = iota
	// EventStop 任务停止事件
	EventStop
)

type TaskResult

type TaskResult int

任务处理结果

const (
	// CONTINUE 本次任务处理完毕,更新时间戳并等待下一轮
	CONTINUE TaskResult = iota
	// SKIP 本次任务无需执行,不更新时间戳
	SKIP
	// TERMINATE 后续任务无需再执行
	TERMINATE
)

type TaskValue

type TaskValue interface {
	// 比较两个元素
	CompareTo(interface{}) int
	// 删除前进行检查,返回true才删除,该检查是同步操作
	EnsureDeleted(value interface{}) bool
}

TaskValue 任务值类型

type TaskValues

type TaskValues interface {
	// 获取启动状态
	Started() bool
	// 增加数据
	// 对于非立即启动的任务,首次增加value时,协程才开始启动
	AddValue(key interface{}, value TaskValue)
	// 删除数据
	// 当缓存数据列表为空时,对于非长稳运行的任务,则会结束协程
	DeleteValue(key interface{}, value TaskValue)
}

TaskValues 定时任务处理的数据

type ValueContext

type ValueContext interface {
	// SetValue 设置kv值
	SetValue(key string, value interface{})
	// GetValue 获取kv值
	GetValue(key string) (interface{}, bool)
	// GetCurrentLocation 获取当前节点地域信息
	GetCurrentLocation() LocationInfo
	// GetClientId 获取客户端ID
	GetClientId() string
	// GetEngine 获取引擎接口
	GetEngine() Engine
	// WaitLocationInfo 等待location是否达到locationStatus
	WaitLocationInfo(ctx context.Context, locationStatus uint32) bool
	// SetCurrentLocation 设置当前节点地域信息
	// 返回是否由非ready转换为ready
	SetCurrentLocation(*Location, SDKError) bool
	// Now 获取当前时间戳
	Now() time.Time
	// Since 计算时间间隔
	Since(time.Time) time.Duration
}

ValueContext 用于主流程传递kv数据的上下文对象,线程安全

func NewValueContext

func NewValueContext() ValueContext

NewValueContext 创建kv上下文对象

type WatchAllInstancesRequest added in v1.4.0

type WatchAllInstancesRequest struct {
	ServiceKey
	// WatchModel model to wait responses
	WatchMode WatchMode
	// WaitIndex is used to enable a blocking query. Waits
	// until the timeout or the next index is reached
	WaitIndex uint64
	// WaitTime is used to bound the duration of a wait.
	// Defaults to that of the Config, but can be overridden.
	WaitTime time.Duration
	// InstancesListener listener for service listeners
	InstancesListener InstancesListener
}

func (*WatchAllInstancesRequest) Validate added in v1.4.0

func (req *WatchAllInstancesRequest) Validate() error

type WatchAllInstancesResponse added in v1.4.0

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

func NewWatchAllInstancesResponse added in v1.4.0

func NewWatchAllInstancesResponse(
	watchId uint64, response *InstancesResponse, cancelWatch func(uint642 uint64)) *WatchAllInstancesResponse

func (*WatchAllInstancesResponse) CancelWatch added in v1.4.0

func (w *WatchAllInstancesResponse) CancelWatch()

func (*WatchAllInstancesResponse) InstancesResponse added in v1.4.0

func (w *WatchAllInstancesResponse) InstancesResponse() *InstancesResponse

func (*WatchAllInstancesResponse) WatchId added in v1.4.0

func (w *WatchAllInstancesResponse) WatchId() uint64

type WatchAllServicesRequest added in v1.4.1

type WatchAllServicesRequest struct {
	// Namespace
	Namespace string
	// WatchModel model to wait responses
	WatchMode WatchMode
	// WaitIndex is used to enable a blocking query. Waits
	// until the timeout or the next index is reached
	WaitIndex uint64
	// WaitTime is used to bound the duration of a wait.
	// Defaults to that of the Config, but can be overridden.
	WaitTime time.Duration
	// ServicesListener listener for service listeners
	ServicesListener ServicesListener
}

func (*WatchAllServicesRequest) Validate added in v1.4.1

func (req *WatchAllServicesRequest) Validate() error

type WatchAllServicesResponse added in v1.4.1

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

func NewWatchAllServicesResponse added in v1.4.1

func NewWatchAllServicesResponse(
	watchId uint64, response *ServicesResponse, cancelWatch func(uint642 uint64)) *WatchAllServicesResponse

func (*WatchAllServicesResponse) CancelWatch added in v1.4.1

func (w *WatchAllServicesResponse) CancelWatch()

func (*WatchAllServicesResponse) ServicesResponse added in v1.4.1

func (w *WatchAllServicesResponse) ServicesResponse() *ServicesResponse

func (*WatchAllServicesResponse) WatchId added in v1.4.1

func (w *WatchAllServicesResponse) WatchId() uint64

type WatchMode added in v1.4.0

type WatchMode int
const (
	// WatchModeLongPull watch model by long pulling, the invocation would be hang on until revision updated or timeout
	WatchModeLongPull WatchMode = iota
	// WatchModeNotify watch model by notify to listener
	WatchModeNotify
)

type WatchRequest added in v1.4.0

type WatchRequest struct {
	ServiceEventKey

	// WatchModel model to wait responses
	WatchMode WatchMode

	// WaitIndex is used to enable a blocking query. Waits
	// until the timeout or the next index is reached
	WaitIndex uint64

	// WaitTime is used to bound the duration of a wait.
	// Defaults to that of the Config, but can be overridden.
	WaitTime time.Duration

	// InstancesListener listener for service listeners
	InstancesListener []InstancesListener

	// ServiceRuleListener listener for service rule listener
	ServiceRuleListener []ServiceRuleListener
}

func (*WatchRequest) Validate added in v1.4.0

func (req *WatchRequest) Validate() error

type WatchResponse added in v1.4.0

type WatchResponse struct {
	// InstancesResponse instances to this service
	InstancesResponse *InstancesResponse
	// ServiceRuleResponse service rule to this service
	ServiceRuleResponse *ServiceRuleResponse
}

type WatchServiceRequest

type WatchServiceRequest struct {
	Key ServiceKey
}

WatchServiceRequest WatchService req

func (*WatchServiceRequest) Validate

func (req *WatchServiceRequest) Validate() error

Validate WatchServiceRequest 校验

type WatchServiceResponse

type WatchServiceResponse struct {
	EventChannel        <-chan SubScribeEvent
	GetAllInstancesResp *InstancesResponse
}

WatchServiceResponse

type WeightIndexSlice

type WeightIndexSlice []WeightedIndex

WeightIndexSlice 权重索引集合

type WeightedIndex

type WeightedIndex struct {
	Index            int
	AccumulateWeight int
}

WeightedIndex 带累加权重的索引

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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