api

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 15 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"
	// ServiceContractName service contract config name
	ServiceContractName = "serviceContract"
	// GrayName gray config name
	GrayName = "gray"
)
View Source
const (
	AllMatched = "*"
)

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 {
	CacheMgr CacheManager
	// contains filtered or unexported fields
}

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

func NewBaseCache

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

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) RefreshInterval added in v1.18.0

func (bc *BaseCache) RefreshInterval() time.Duration

func (*BaseCache) ResetLastFetchTime

func (bc *BaseCache) ResetLastFetchTime()

func (*BaseCache) ResetLastMtime

func (bc *BaseCache) ResetLastMtime(label string)

func (*BaseCache) Store added in v1.18.0

func (bc *BaseCache) Store() store.Store

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
	// 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
	CacheServiceContract
	CacheGray

	CacheLast
)

type CacheManager

type CacheManager interface {
	// GetCacher
	GetCacher(cacheIndex CacheIndex) Cache
	// RegisterCacher
	RegisterCacher(cacheIndex CacheIndex, item Cache)
	// OpenResourceCache
	OpenResourceCache(entries ...ConfigEntry) error
	// Service 获取Service缓存信息
	Service() ServiceCache
	// Instance 获取Instance缓存信息
	Instance() InstanceCache
	// RoutingConfig 获取路由配置的缓存信息
	RoutingConfig() RoutingConfigCache
	// CL5 获取l5缓存信息
	CL5() L5Cache
	// RateLimit 获取限流规则缓存信息
	RateLimit() RateLimitCache
	// CircuitBreaker 获取熔断规则缓存信息
	CircuitBreaker() CircuitBreakerCache
	// FaultDetector 获取探测规则缓存信息
	FaultDetector() FaultDetectCache
	// ServiceContract 获取服务契约缓存
	ServiceContract() ServiceContractCache
	// User Get user information cache information
	User() UserCache
	// AuthStrategy Get authentication cache information
	AuthStrategy() StrategyCache
	// Namespace Get namespace cache information
	Namespace() NamespaceCache
	// Client Get client cache information
	Client() ClientCache
	// ConfigFile get config file cache information
	ConfigFile() ConfigFileCache
	// ConfigGroup get config group cache information
	ConfigGroup() ConfigGroupCache
	// Gray get Gray cache information
	Gray() GrayCache
}

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 ConfigEntry added in v1.18.0

type ConfigEntry struct {
	Name   string                 `yaml:"name"`
	Option map[string]interface{} `yaml:"option"`
}

ConfigEntry 单个缓存资源配置

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
	// GetActiveGrayRelease
	GetActiveGrayRelease(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
	// ListGroups
	ListGroups(namespace string) ([]*model.ConfigFileGroup, string)
	// 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
	// IncludeGray 是否包含灰度文件,默认不包括
	IncludeGray bool
	// Metadata
	Metadata map[string]string
	// NoPage
	NoPage bool
}

type FaultDetectCache

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

FaultDetectCache fault detect rule cache service

type GrayCache added in v1.18.0

type GrayCache interface {
	Cache
	GetGrayRule(name string) []*apimodel.ClientLabel
	// HitGrayRule .
	HitGrayRule(name string, labels map[string]string) bool
}

GrayCache 灰度 Cache 接口

type InstanceCache

type InstanceCache interface {
	// Cache 公共缓存接口
	Cache
	// GetInstance 根据实例ID获取实例数据
	GetInstance(instanceID string) *model.Instance
	// GetInstancesByServiceID 根据服务名获取实例,先查找服务名对应的服务ID,再找实例列表
	GetInstancesByServiceID(serviceID string) []*model.Instance
	// GetInstances 根据服务名获取实例,先查找服务名对应的服务ID,再找实例列表
	GetInstances(serviceID string) *model.ServiceInstances
	// 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)
	// DiscoverServiceInstances 服务发现获取实例
	DiscoverServiceInstances(serviceID string, onlyHealthy bool) []*model.Instance
}

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 NamespaceCache

type NamespaceCache interface {
	Cache
	// GetNamespace get target namespace by id
	GetNamespace(id string) *model.Namespace
	// GetNamespacesByName list all namespace by name
	GetNamespacesByName(names []string) []*model.Namespace
	// GetNamespaceList list all namespace
	GetNamespaceList() []*model.Namespace
	// GetVisibleNamespaces list target namespace can visible other namespaces
	GetVisibleNamespaces(namespace string) []*model.Namespace
}

NamespaceCache 命名空间的 Cache 接口

type RateLimitCache

type RateLimitCache interface {
	Cache
	// IteratorRateLimit 遍历所有的限流规则
	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
	// GetVisibleServicesInOtherNamespace get same service in other namespace and it's visible
	GetVisibleServicesInOtherNamespace(name string, namespace string) []*model.Service
}

ServiceCache 服务数据缓存接口

type ServiceContractCache added in v1.18.0

type ServiceContractCache interface {
	Cache
	// Query .
	Query(filter map[string]string, offset, limit uint32) ([]*model.EnrichServiceContract, uint32, error)
	// ListVersions .
	ListVersions(service, namespace string) []*model.EnrichServiceContract
	// Get .
	Get(req *model.ServiceContract) *model.EnrichServiceContract
}

ServiceContractCache .

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