api

package
v1.17.6 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NamespaceName cache name
	NamespaceName = "namespace"
	// ServiceName
	ServiceName = "service"
	// InstanceName instance name
	InstanceName = "instance"
	// L5Name l5 name
	L5Name = "l5"
	// RoutingConfigName router config name
	RoutingConfigName = "routingConfig"
	// RateLimitConfigName rate limit config name
	RateLimitConfigName = "rateLimitConfig"
	// CircuitBreakerName circuit breaker config name
	CircuitBreakerName = "circuitBreakerConfig"
	// FaultDetectRuleName fault detect config name
	FaultDetectRuleName = "faultDetectRule"
	// ConfigGroupCacheName config group config name
	ConfigGroupCacheName = "configGroup"
	// ConfigFileCacheName config file config name
	ConfigFileCacheName = "configFile"
	// ClientName client cache name
	ClientName = "client"
	// UsersName user data config name
	UsersName = "users"
	// StrategyRuleName strategy rule config name
	StrategyRuleName = "strategyRule"
)

Variables

View Source
var (
	// DefaultTimeDiff default time diff
	DefaultTimeDiff = -5 * time.Second
)

Functions

func CompositeComputeRevision

func CompositeComputeRevision(revisions []string) (string, error)

CompositeComputeRevision 将多个 revision 合并计算为一个

func ComputeRevisionBySlice

func ComputeRevisionBySlice(h hash.Hash, slice []string) (string, error)

func LogLastMtime

func LogLastMtime(lastMtimeLogged int64, lastMtime int64, prefix string) int64

LogLastMtime 定时打印mtime更新结果

Types

type BaseCache

type BaseCache struct {
	Manager  *ListenerManager
	CacheMgr CacheManager
	// contains filtered or unexported fields
}

BaseCache 对于 Cache 中的一些 func 做统一实现,避免重复逻辑

func NewBaseCache

func NewBaseCache(s store.Store, cacheMgr CacheManager) *BaseCache

func (*BaseCache) AddListener

func (bc *BaseCache) AddListener(listeners []Listener)

AddListener 添加

func (*BaseCache) Clear

func (bc *BaseCache) Clear()

func (*BaseCache) Close

func (bc *BaseCache) Close() error

func (*BaseCache) DoCacheUpdate

func (bc *BaseCache) DoCacheUpdate(name string, executor func() (map[string]time.Time, int64, error)) error

update

func (*BaseCache) IsFirstUpdate

func (bc *BaseCache) IsFirstUpdate() bool

func (*BaseCache) LastFetchTime

func (bc *BaseCache) LastFetchTime() time.Time

func (*BaseCache) LastMtime

func (bc *BaseCache) LastMtime(label string) time.Time

func (*BaseCache) OriginLastFetchTime

func (bc *BaseCache) OriginLastFetchTime() time.Time

OriginLastFetchTime only for test

func (*BaseCache) ResetLastFetchTime

func (bc *BaseCache) ResetLastFetchTime()

func (*BaseCache) ResetLastMtime

func (bc *BaseCache) ResetLastMtime(label string)

type BaseConfigArgs

type BaseConfigArgs struct {
	// Namespace
	Namespace string
	// Group
	Group string
	// Offset
	Offset uint32
	// Limit
	Limit uint32
	// OrderField Sort field
	OrderField string
	// OrderType Sorting rules
	OrderType string
}

type Cache

type Cache interface {
	// Initialize
	Initialize(c map[string]interface{}) error
	// AddListener 添加
	AddListener(listeners []Listener)
	// Update .
	Update() error
	// Clear .
	Clear() error
	// Name .
	Name() string
	// Close .
	Close() error
}

Cache 缓存接口

type CacheIndex

type CacheIndex int
const (
	// CacheNamespace int = iota
	// CacheBusiness
	CacheService CacheIndex = iota
	CacheInstance
	CacheRoutingConfig
	CacheCL5
	CacheRateLimit
	CacheCircuitBreaker
	CacheUser
	CacheAuthStrategy
	CacheNamespace
	CacheClient
	CacheConfigFile
	CacheFaultDetector
	CacheConfigGroup

	CacheLast
)

type CacheManager

type CacheManager interface {
	// GetCacher
	GetCacher(cacheIndex CacheIndex) Cache
	// RegisterCacher
	RegisterCacher(cacheIndex CacheIndex, item Cache)
}

CacheManager

type CircuitBreakerCache

type CircuitBreakerCache interface {
	Cache
	// GetCircuitBreakerConfig 根据ServiceID获取熔断配置
	GetCircuitBreakerConfig(svcName string, namespace string) *model.ServiceWithCircuitBreakerRules
}

CircuitBreakerCache circuitBreaker配置的cache接口

type ClientCache

type ClientCache interface {
	Cache
	// GetClient get client
	GetClient(id string) *model.Client
	// IteratorClients 迭代
	IteratorClients(iterProc ClientIterProc)
	// GetClientsByFilter Query client information
	GetClientsByFilter(filters map[string]string, offset, limit uint32) (uint32, []*model.Client, error)
}

ClientCache 客户端的 Cache 接口

type ClientIterProc

type ClientIterProc func(key string, value *model.Client) bool

ClientIterProc client iter proc func

type ConfigFileArgs

type ConfigFileArgs struct {
	BaseConfigArgs
	FileName string
	Metadata map[string]string
}

type ConfigFileCache

type ConfigFileCache interface {
	Cache
	// GetActiveRelease
	GetGroupActiveReleases(namespace, group string) ([]*model.ConfigFileRelease, string)
	// GetActiveRelease
	GetActiveRelease(namespace, group, fileName string) *model.ConfigFileRelease
	// GetRelease
	GetRelease(key model.ConfigFileReleaseKey) *model.ConfigFileRelease
	// QueryReleases
	QueryReleases(args *ConfigReleaseArgs) (uint32, []*model.SimpleConfigFileRelease, error)
}

ConfigFileCache file cache

type ConfigGroupArgs

type ConfigGroupArgs struct {
	Namespace  string
	Name       string
	Business   string
	Department string
	Metadata   map[string]string
	Offset     uint32
	Limit      uint32
	// OrderField Sort field
	OrderField string
	// OrderType Sorting rules
	OrderType string
}

ConfigGroupArgs

type ConfigGroupCache

type ConfigGroupCache interface {
	Cache
	// GetGroupByName
	GetGroupByName(namespace, name string) *model.ConfigFileGroup
	// GetGroupByID
	GetGroupByID(id uint64) *model.ConfigFileGroup
	// Query
	Query(args *ConfigGroupArgs) (uint32, []*model.ConfigFileGroup, error)
}

ConfigGroupCache file cache

type ConfigReleaseArgs

type ConfigReleaseArgs struct {
	BaseConfigArgs
	// FileName
	FileName string
	// ReleaseName
	ReleaseName string
	// OnlyActive
	OnlyActive bool
	// Metadata
	Metadata map[string]string
	// NoPage
	NoPage bool
}

type EventType

type EventType int

EventType common event type

const (
	// EventCreated value create event
	EventCreated EventType = iota
	// EventUpdated value update event
	EventUpdated
	// EventDeleted value delete event
	EventDeleted
	// EventInstanceReload value instances reload
	EventInstanceReload
	// EventPrincipalRemove value principal batch remove
	EventPrincipalRemove
)

type FaultDetectCache

type FaultDetectCache interface {
	Cache
	// GetFaultDetectConfig 根据ServiceID获取探测配置
	GetFaultDetectConfig(svcName string, namespace string) *model.ServiceWithFaultDetectRules
}

FaultDetectCache fault detect rule cache service

type InstanceCache

type InstanceCache interface {
	// Cache 公共缓存接口
	Cache
	// GetInstance 根据实例ID获取实例数据
	GetInstance(instanceID string) *model.Instance
	// GetInstancesByServiceID 根据服务名获取实例,先查找服务名对应的服务ID,再找实例列表
	GetInstancesByServiceID(serviceID string) []*model.Instance
	// IteratorInstances 迭代
	IteratorInstances(iterProc InstanceIterProc) error
	// IteratorInstancesWithService 根据服务ID进行迭代
	IteratorInstancesWithService(serviceID string, iterProc InstanceIterProc) error
	// GetInstancesCount 获取instance的个数
	GetInstancesCount() int
	// GetInstancesCountByServiceID 根据服务ID获取实例数
	GetInstancesCountByServiceID(serviceID string) model.InstanceCount
	// GetServicePorts 根据服务ID获取端口号
	GetServicePorts(serviceID string) []*model.ServicePort
	// GetInstanceLabels Get the label of all instances under a service
	GetInstanceLabels(serviceID string) *apiservice.InstanceLabels
	// QueryInstances query instance for OSS
	QueryInstances(filter, metaFilter map[string]string, offset, limit uint32) (uint32, []*model.Instance, error)
}

InstanceCache 实例相关的缓存接口

type InstanceIterProc

type InstanceIterProc func(key string, value *model.Instance) (bool, error)

InstanceIterProc instance iter proc func

type L5Cache

type L5Cache interface {
	Cache
	// GetRouteByIP 根据IP获取访问关系
	GetRouteByIP(ip uint32) []*model.Route
	// CheckRouteExisted 检查IP对应的SID是否存在访问关系
	CheckRouteExisted(ip uint32, modID uint32, cmdID uint32) bool
	// GetPolicy 获取有状态路由信息policy
	GetPolicy(modID uint32) *model.Policy
	// GetSection 获取有状态路由信息policy
	GetSection(modeID uint32) []*model.Section
	// GetIPConfig 获取IpConfig
	GetIPConfig(ip uint32) *model.IPConfig
}

L5Cache L5的cache接口

type Listener

type Listener interface {
	// OnCreated callback when cache value created
	OnCreated(value interface{})
	// OnUpdated callback when cache value updated
	OnUpdated(value interface{})
	// OnDeleted callback when cache value deleted
	OnDeleted(value interface{})
	// OnBatchCreated callback when cache value created
	OnBatchCreated(value interface{})
	// OnBatchUpdated callback when cache value updated
	OnBatchUpdated(value interface{})
	// OnBatchDeleted callback when cache value deleted
	OnBatchDeleted(value interface{})
}

Listener listener for value changes

type ListenerManager

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

func NewListenerManager

func NewListenerManager() *ListenerManager

func (*ListenerManager) Append

func (l *ListenerManager) Append(listeners ...Listener)

func (*ListenerManager) OnEvent

func (l *ListenerManager) OnEvent(value interface{}, event EventType)

type NamespaceCache

type NamespaceCache interface {
	Cache
	// GetNamespace
	GetNamespace(id string) *model.Namespace
	// GetNamespacesByName
	GetNamespacesByName(names []string) []*model.Namespace
	// GetNamespaceList
	GetNamespaceList() []*model.Namespace
}

NamespaceCache 命名空间的 Cache 接口

type RateLimitCache

type RateLimitCache interface {
	Cache
	// GetRateLimit 根据serviceID进行迭代回调
	IteratorRateLimit(rateLimitIterProc RateLimitIterProc)
	// GetRateLimitRules 根据serviceID获取限流数据
	GetRateLimitRules(serviceKey model.ServiceKey) ([]*model.RateLimit, string)
	// QueryRateLimitRules
	QueryRateLimitRules(args RateLimitRuleArgs) (uint32, []*model.RateLimit, error)
	// GetRateLimitsCount 获取限流规则总数
	GetRateLimitsCount() int
}

RateLimitCache rateLimit的cache接口

type RateLimitIterProc

type RateLimitIterProc func(rateLimit *model.RateLimit)

RateLimitIterProc rate limit iter func

type RateLimitRuleArgs

type RateLimitRuleArgs struct {
	// Filter extend filter params
	Filter map[string]string
	// ID route rule id
	ID string
	// Name route rule name
	Name string
	// Service service name
	Service string
	// Namespace namesapce
	Namespace string
	// Disable *bool
	Disable *bool
	// Offset
	Offset uint32
	// Limit
	Limit uint32
	// OrderField Sort field
	OrderField string
	// OrderType Sorting rules
	OrderType string
}

RateLimitRuleArgs ratelimit rules query parameters

type RouterRuleIterProc

type RouterRuleIterProc func(key string, value *model.ExtendRouterConfig)

RouterRuleIterProc Method definition of routing rules

type RoutingArgs

type RoutingArgs struct {
	// Filter extend filter params
	Filter map[string]string
	// ID route rule id
	ID string
	// Name route rule name
	Name string
	// Service service name
	Service string
	// Namespace namesapce
	Namespace string
	// SourceService source service name
	SourceService string
	// SourceNamespace source service namespace
	SourceNamespace string
	// DestinationService destination service name
	DestinationService string
	// DestinationNamespace destination service namespace
	DestinationNamespace string
	// Enable
	Enable *bool
	// Offset
	Offset uint32
	// Limit
	Limit uint32
	// OrderField Sort field
	OrderField string
	// OrderType Sorting rules
	OrderType string
}

RoutingArgs Routing rules query parameters

type RoutingConfigCache

type RoutingConfigCache interface {
	Cache
	// GetRouterConfig Obtain routing configuration based on serviceid
	GetRouterConfig(id, service, namespace string) (*apitraffic.Routing, error)
	// GetRouterConfig Obtain routing configuration based on serviceid
	GetRouterConfigV2(id, service, namespace string) (*apitraffic.Routing, error)
	// GetRoutingConfigCount Get the total number of routing configuration cache
	GetRoutingConfigCount() int
	// QueryRoutingConfigsV2 Query Route Configuration List
	QueryRoutingConfigsV2(args *RoutingArgs) (uint32, []*model.ExtendRouterConfig, error)
	// ListRouterRule list all router rule
	ListRouterRule(service, namespace string) []*model.ExtendRouterConfig
	// IsConvertFromV1 Whether the current routing rules are converted from the V1 rule
	IsConvertFromV1(id string) (string, bool)
	// IteratorRouterRule iterator router rule
	IteratorRouterRule(iterProc RouterRuleIterProc)
}

RoutingConfigCache Cache interface configured by routing

type ServiceArgs

type ServiceArgs struct {
	// Filter 普通服务字段条件
	Filter map[string]string
	// Metadata 元数据条件
	Metadata map[string]string
	// SvcIds 是否按照服务的ID进行等值查询
	SvcIds map[string]struct{}
	// WildName 是否进行名字的模糊匹配
	WildName bool
	// WildBusiness 是否进行业务的模糊匹配
	WildBusiness bool
	// WildNamespace 是否进行命名空间的模糊匹配
	WildNamespace bool
	// Namespace 条件中的命名空间
	Namespace string
	// Name 条件中的服务名
	Name string
	// EmptyCondition 是否是空条件,即只需要从所有服务或者某个命名空间下面的服务,进行不需要匹配的遍历,返回前面的服务即可
	EmptyCondition bool
}

ServiceArgs 服务查询条件

type ServiceCache

type ServiceCache interface {
	Cache
	// GetNamespaceCntInfo Return to the service statistics according to the namespace,
	// 	the count statistics and health instance statistics
	GetNamespaceCntInfo(namespace string) model.NamespaceServiceCount
	// GetAllNamespaces Return all namespaces
	GetAllNamespaces() []string
	// GetServiceByID According to ID query service information
	GetServiceByID(id string) *model.Service
	// GetServiceByName Inquiry service information according to service name
	GetServiceByName(name string, namespace string) *model.Service
	// IteratorServices Iterative Cache Service Information
	IteratorServices(iterProc ServiceIterProc) error
	// CleanNamespace Clear the cache of NameSpace
	CleanNamespace(namespace string)
	// GetServicesCount Get the number of services in the cache
	GetServicesCount() int
	// GetServiceByCl5Name Get the corresponding SID according to CL5name
	GetServiceByCl5Name(cl5Name string) *model.Service
	// GetServicesByFilter Serving the service filtering in the cache through Filter
	GetServicesByFilter(serviceFilters *ServiceArgs,
		instanceFilters *store.InstanceArgs, offset, limit uint32) (uint32, []*model.EnhancedService, error)
	// ListServices get service list and revision by namespace
	ListServices(ns string) (string, []*model.Service)
	// ListAllServices get all service and revision
	ListAllServices() (string, []*model.Service)
	// ListServiceAlias list service link alias list
	ListServiceAlias(namespace, name string) []*model.Service
	// GetAliasFor get alias reference service info
	GetAliasFor(name string, namespace string) *model.Service
	// GetRevisionWorker .
	GetRevisionWorker() ServiceRevisionWorker
}

ServiceCache 服务数据缓存接口

type ServiceIterProc

type ServiceIterProc func(key string, value *model.Service) (bool, error)

ServiceIterProc 迭代回调函数

type ServiceRevisionWorker

type ServiceRevisionWorker interface {
	// Notify
	Notify(serviceID string, valid bool)
	// GetServiceRevisionCount
	GetServiceRevisionCount() int
	// GetServiceInstanceRevision
	GetServiceInstanceRevision(serviceID string) string
}

ServiceRevisionWorker

type StrategyCache

type StrategyCache interface {
	Cache
	// GetStrategyDetailsByUID
	GetStrategyDetailsByUID(uid string) []*model.StrategyDetail
	// GetStrategyDetailsByGroupID returns all strategy details of a group.
	GetStrategyDetailsByGroupID(groupId string) []*model.StrategyDetail
	// IsResourceLinkStrategy 该资源是否关联了鉴权策略
	IsResourceLinkStrategy(resType apisecurity.ResourceType, resId string) bool
	// IsResourceEditable 判断该资源是否可以操作
	IsResourceEditable(principal model.Principal, resType apisecurity.ResourceType, resId string) bool
	// ForceSync 强制同步鉴权策略到cache (串行)
	ForceSync() error
}

StrategyCache is a cache for strategy rules.

type UserCache

type UserCache interface {
	Cache
	// GetAdmin 获取管理员信息
	GetAdmin() *model.User
	// GetUserByID
	GetUserByID(id string) *model.User
	// GetUserByName
	GetUserByName(name, ownerName string) *model.User
	// GetUserGroup
	GetGroup(id string) *model.UserGroupDetail
	// IsUserInGroup 判断 userid 是否在对应的 group 中
	IsUserInGroup(userId, groupId string) bool
	// IsOwner
	IsOwner(id string) bool
	// GetUserLinkGroupIds
	GetUserLinkGroupIds(id string) []string
}

UserCache User information cache

Jump to

Keyboard shortcuts

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