servicerouter

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFilterInstances

func GetFilterInstances(ctx model.ValueContext, routers []ServiceRouter, routeInfo *RouteInfo,
	serviceInstances model.ServiceInstances) ([]model.Instance, *model.Cluster, *model.ServiceInfo, error)

GetFilterInstances 根据服务路由链,过滤服务节点,返回对应的服务列表

func GetRouteResultPool

func GetRouteResultPool() *sync.Pool

GetRouteResultPool 获取路由结果对象池

Types

type FailOverType added in v1.5.8

type FailOverType int32
const (
	FailOverAll FailOverType
	FailOverNone
)

type Proxy

type Proxy struct {
	ServiceRouter
	// contains filtered or unexported fields
}

Proxy is a proxy for service router

func (*Proxy) GetFilteredInstances

func (p *Proxy) GetFilteredInstances(
	routeInfo *RouteInfo, serviceClusters model.ServiceClusters, withinCluster *model.Cluster) (*RouteResult, error)

GetFilteredInstances proxy ServiceRouter GetFilteredInstances

func (*Proxy) SetRealPlugin

func (p *Proxy) SetRealPlugin(plug plugin.Plugin, engine model.Engine)

SetRealPlugin 设置

type RouteGauge

type RouteGauge struct {
	model.EmptyInstanceGauge
	PluginID         int32
	SrcService       model.ServiceKey
	RetCode          model.ErrCode
	Cluster          *model.Cluster
	ServiceInstances model.ServiceInstances
	RouteRuleType    RuleType
	Status           RouteStatus
}

RouteGauge 路由调用统计数据

type RouteInfo

type RouteInfo struct {
	// 源服务信息
	SourceService model.ServiceMetadata
	// 源路由规则
	SourceRouteRule model.ServiceRule
	// 目标服务信息
	DestService model.ServiceMetadata
	// 目标路由规则
	DestRouteRule model.ServiceRule
	// 在路由匹配过程中使用到的环境变量
	EnvironmentVariables map[string]string
	// 全死全活路由插件,用于做路由兜底
	// 路由链不为空,但是没有走filterOnly,则使用该路由插件来进行兜底
	FilterOnlyRouter ServiceRouter

	// 是否开启元数据匹配不到时启用自定义匹配规则,仅用于dstMetadata路由插件
	EnableFailOverDefaultMeta bool
	// 自定义匹配规则,仅当EnableFailOverDefaultMeta为true时生效
	FailOverDefaultMeta model.FailOverDefaultMetaConfig
	// 金丝雀
	Canary string
	// 进行匹配的规则类型,如规则路由有入规则和出规则之分
	MatchRuleType RuleType
	// 规则路由失败降级类型
	FailOverType *FailOverType
	// contains filtered or unexported fields
}

RouteInfo 路由信息

func (*RouteInfo) ClearValue

func (r *RouteInfo) ClearValue()

ClearValue 清理值

func (*RouteInfo) Init

func (r *RouteInfo) Init(supplier plugin.Supplier)

Init 初始化map

func (*RouteInfo) IsRouterEnable

func (r *RouteInfo) IsRouterEnable(routerId int32) bool

IsRouterEnable 路由插件是否启用

func (*RouteInfo) SetIgnoreFilterOnlyOnEndChain

func (r *RouteInfo) SetIgnoreFilterOnlyOnEndChain(run bool)

SetIgnoreFilterOnlyOnEndChain 设置是否需要执行全死全活插件兜底

func (*RouteInfo) SetRouterEnable

func (r *RouteInfo) SetRouterEnable(routerId int32, enable bool)

SetRouterEnable 设置是否启用路由插件

func (*RouteInfo) Validate

func (r *RouteInfo) Validate() error

Validate 校验入参

type RouteResult

type RouteResult struct {
	// 根据路由规则重定向的目标服务,无需重定向则返回空
	RedirectDestService *model.ServiceInfo
	// 根据路由规则过滤后的目标服务集群,假如重定向则列表为空
	OutputCluster *model.Cluster
	// 路由结束状态
	Status RouteStatus
}

RouteResult 路由结果信息

func GetFilterCluster

func GetFilterCluster(ctx model.ValueContext, routers []ServiceRouter, routeInfo *RouteInfo,
	svcClusters model.ServiceClusters) (*RouteResult, model.SDKError)

GetFilterCluster 根据服务理由链,过滤服务节点,返回对应的cluster

func PoolGetRouteResult

func PoolGetRouteResult(ctx model.ValueContext) *RouteResult

PoolGetRouteResult 通过池子获取路由结果

type RouteStatus

type RouteStatus int

RouteStatus 路由结束状态

const (
	// Normal 正常结束
	Normal RouteStatus = 0
	// RecoverAll 全活
	RecoverAll RouteStatus = 1
	// DegradeToCity 降级到城市
	DegradeToCity RouteStatus = 2
	// DegradeToRegion 降级到大区
	DegradeToRegion RouteStatus = 3
	// DegradeToAll 降级到全部区域
	DegradeToAll RouteStatus = 4
	// DegradeToNotMatchCanary 降级到不完全匹配的金丝雀节点
	DegradeToNotMatchCanary RouteStatus = 5
	// DegradeToNotCanary 降级到非金丝雀节点
	DegradeToNotCanary RouteStatus = 6
	// DegradeToCanary 正常环境降级到金丝雀环境
	DegradeToCanary RouteStatus = 7
	// LimitedCanary 金丝雀环境发生异常
	LimitedCanary RouteStatus = 8
	// LimitedNoCanary 非金丝雀环境发生异常
	LimitedNoCanary RouteStatus = 9
	// DegradeToFilterOnly 降级使用filterOnly
	DegradeToFilterOnly RouteStatus = 10
)

func (RouteStatus) String

func (rs RouteStatus) String() string

String 转换为字符串

type RouterChain

type RouterChain struct {
	// 服务路由链
	Chain []ServiceRouter
}

RouterChain 服务路由链结构

type RuleType

type RuleType int
const (
	UnknownRule RuleType = 0
	DestRule    RuleType = 1
	SrcRule     RuleType = 2
)

type ServiceRouter

type ServiceRouter interface {
	plugin.Plugin
	// Enable 当前是否需要启动该服务路由插件
	Enable(routeInfo *RouteInfo, serviceClusters model.ServiceClusters) bool
	// GetFilteredInstances 获取通过规则过滤后的服务集群信息以及服务实例列表
	// routeInfo: 路由信息,包括源和目标服务的实例及路由规则
	// serviceClusters:服务级缓存信息
	// withinCluster:上一个环节过滤的集群信息,本次路由需要继承
	GetFilteredInstances(
		routeInfo *RouteInfo, serviceClusters model.ServiceClusters, withinCluster *model.Cluster) (*RouteResult, error)
}

ServiceRouter 【扩展点接口】服务路由

Jump to

Keyboard shortcuts

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