Documentation ¶
Index ¶
- Constants
- Variables
- func CompositeComputeRevision(revisions []string) (string, error)
- func ComputeRevision(serviceRevision string, instances []*model.Instance) (string, error)
- func ComputeRevisionBySlice(h hash.Hash, slice []string) (string, error)
- func Initialize(ctx context.Context, cacheOpt *Config, storage store.Store) error
- func RegisterCache(name string, index int)
- func Run(cacheMgr *CacheManager, ctx context.Context) error
- func SetCacheConfig(conf *Config)
- type Cache
- type CacheManager
- func (nc *CacheManager) AddListener(cacheName CacheName, listeners []Listener)
- func (nc *CacheManager) AuthStrategy() StrategyCache
- func (nc *CacheManager) CL5() L5Cache
- func (nc *CacheManager) CircuitBreaker() CircuitBreakerCache
- func (nc *CacheManager) Clear() error
- func (nc *CacheManager) Client() ClientCache
- func (nc *CacheManager) ConfigFile() FileCache
- func (nc *CacheManager) FaultDetector() FaultDetectCache
- func (nc *CacheManager) GetServiceInstanceRevision(serviceID string) string
- func (nc *CacheManager) GetServiceRevisionCount() int
- func (nc *CacheManager) GetStore() store.Store
- func (nc *CacheManager) GetUpdateCacheInterval() time.Duration
- func (nc *CacheManager) Instance() InstanceCache
- func (nc *CacheManager) Namespace() NamespaceCache
- func (nc *CacheManager) RateLimit() RateLimitCache
- func (nc *CacheManager) RoutingConfig() RoutingConfigCache
- func (nc *CacheManager) Service() ServiceCache
- func (nc *CacheManager) Start(ctx context.Context) error
- func (nc *CacheManager) TestRefresh() error
- func (nc *CacheManager) TestUpdate() error
- func (nc *CacheManager) User() UserCache
- type CacheName
- type CircuitBreakerCache
- type ClientCache
- type ClientIterProc
- type Config
- type ConfigEntry
- type Entry
- type EventType
- type FaultDetectCache
- type FileCache
- type InstanceCache
- type InstanceIterProc
- type L5Cache
- type Listener
- type NamespaceCache
- type RateLimitCache
- type RateLimitIterProc
- type RateLimitRuleArgs
- type RouterRuleIterProc
- type RoutingArgs
- type RoutingConfigCache
- type ServiceArgs
- type ServiceCache
- type ServiceIterProc
- type ServiceWithRouterRules
- func (s *ServiceWithRouterRules) AddRouterRule(rule *model.ExtendRouterConfig)
- func (s *ServiceWithRouterRules) Clear()
- func (s *ServiceWithRouterRules) CountRouterRules() int
- func (s *ServiceWithRouterRules) DelRouterRule(id string)
- func (s *ServiceWithRouterRules) IterateRouterRules(callback func(*model.ExtendRouterConfig))
- type StrategyCache
- type UserCache
- type WatchInstanceReload
- func (fc *WatchInstanceReload) OnBatchCreated(value interface{})
- func (fc *WatchInstanceReload) OnBatchDeleted(value interface{})
- func (fc *WatchInstanceReload) OnBatchUpdated(value interface{})
- func (fc *WatchInstanceReload) OnCreated(value interface{})
- func (fc *WatchInstanceReload) OnDeleted(value interface{})
- func (fc *WatchInstanceReload) OnUpdated(value interface{})
Constants ¶
const ( // CacheNamespace int = iota // CacheBusiness CacheService = iota CacheInstance CacheRoutingConfig CacheCL5 CacheRateLimit CacheCircuitBreaker CacheUser CacheAuthStrategy CacheNamespace CacheClient CacheConfigFile CacheFaultDetector CacheLast )
const ( // RevisionConcurrenceCount Revision计算的并发线程数 RevisionConcurrenceCount = 64 // RevisionChanCount 存储revision计算的通知管道,可以稍微设置大一点 RevisionChanCount = 102400 )
const ( UsersName = "users" NameLinkOwnerTemp = "%s@%s" )
const (
// CircuitBreakerName circuit breaker config name
CircuitBreakerName = "circuitBreakerConfig"
)
const (
// ClientName client cache name
ClientName = "client"
)
const (
// FaultDetectRuleName fault detect config name
FaultDetectRuleName = "faultDetectRule"
)
const (
// InstanceName instance name
InstanceName = "instance"
)
const (
// L5Name l5 name
L5Name = "l5"
)
const (
// NamespaceName l5 name
NamespaceName = "namespace"
)
const (
// RateLimitConfigName rate limit config name
RateLimitConfigName = "rateLimitConfig"
)
const (
// RoutingConfigName router config name
RoutingConfigName = "routingConfig"
)
const (
ServiceName = "service"
)
const (
StrategyRuleName = "strategyRule"
)
const ( // UpdateCacheInterval 缓存更新时间间隔 UpdateCacheInterval = 1 * time.Second )
Variables ¶
var ( // DefaultTimeDiff default time diff DefaultTimeDiff = -5 * time.Second )
var ( TestCacheInitialize = func(ctx context.Context, cacheOpt *Config, storage store.Store) (*CacheManager, error) { mgr, err := newCacheManager(ctx, cacheOpt, storage) if err := Run(mgr, ctx); err != nil { return nil, err } return mgr, err } )
TestCacheInitialize 由于某一些模块依赖Cache,但是由于Cache模块初始化采用sync.Once,会导致单元测试之间Cache存在脏数据问题,因此为了确保单 元测试能够正常执行,这里将 cache.initialize 方法导出并命名为 TestCacheInitialize,仅用于单元测试初始化一个完整的 CacheManager
Functions ¶
func CompositeComputeRevision ¶
CompositeComputeRevision 将多个 revision 合并计算为一个
func ComputeRevision ¶
ComputeRevision 计算唯一的版本标识
func ComputeRevisionBySlice ¶ added in v1.14.0
func Initialize ¶
Initialize 初始化
Types ¶
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
CacheManager 名字服务缓存
func GetCacheManager ¶
func GetCacheManager() (*CacheManager, error)
GetCacheManager
@return *CacheManager @return error
func (*CacheManager) AddListener ¶
func (nc *CacheManager) AddListener(cacheName CacheName, listeners []Listener)
func (*CacheManager) AuthStrategy ¶
func (nc *CacheManager) AuthStrategy() StrategyCache
AuthStrategy Get authentication cache information
func (*CacheManager) CircuitBreaker ¶
func (nc *CacheManager) CircuitBreaker() CircuitBreakerCache
CircuitBreaker 获取熔断规则缓存信息
func (*CacheManager) Client ¶
func (nc *CacheManager) Client() ClientCache
Client Get client cache information
func (*CacheManager) ConfigFile ¶
func (nc *CacheManager) ConfigFile() FileCache
ConfigFile get config file cache information
func (*CacheManager) FaultDetector ¶ added in v1.14.0
func (nc *CacheManager) FaultDetector() FaultDetectCache
FaultDetector 获取探测规则缓存信息
func (*CacheManager) GetServiceInstanceRevision ¶
func (nc *CacheManager) GetServiceInstanceRevision(serviceID string) string
GetServiceInstanceRevision 获取服务实例计算之后的revision
func (*CacheManager) GetServiceRevisionCount ¶
func (nc *CacheManager) GetServiceRevisionCount() int
GetServiceRevisionCount 计算一下缓存中的revision的个数
func (*CacheManager) GetUpdateCacheInterval ¶
func (nc *CacheManager) GetUpdateCacheInterval() time.Duration
GetUpdateCacheInterval 获取当前cache的更新间隔
func (*CacheManager) Instance ¶
func (nc *CacheManager) Instance() InstanceCache
Instance 获取Instance缓存信息
func (*CacheManager) Namespace ¶
func (nc *CacheManager) Namespace() NamespaceCache
Namespace Get namespace cache information
func (*CacheManager) RateLimit ¶
func (nc *CacheManager) RateLimit() RateLimitCache
RateLimit 获取限流规则缓存信息
func (*CacheManager) RoutingConfig ¶
func (nc *CacheManager) RoutingConfig() RoutingConfigCache
RoutingConfig 获取路由配置的缓存信息
func (*CacheManager) Start ¶
func (nc *CacheManager) Start(ctx context.Context) error
Start 缓存对象启动协程,定时更新缓存
func (*CacheManager) TestRefresh ¶
func (nc *CacheManager) TestRefresh() error
TestRefresh only for test
func (*CacheManager) TestUpdate ¶ added in v1.16.0
func (nc *CacheManager) TestUpdate() error
TestUpdate only for test
func (*CacheManager) User ¶
func (nc *CacheManager) User() UserCache
User Get user information cache information
type CacheName ¶
type CacheName string
CacheName cache name
const ( CacheNameService CacheName = "Service" CacheNameInstance CacheName = "Instance" CacheNameRoutingConfig CacheName = "RoutingConfig" CacheNameCL5 CacheName = "CL5" CacheNameRateLimit CacheName = "RateLimit" CacheNameCircuitBreaker CacheName = "CircuitBreaker" CacheNameUser CacheName = "User" CacheNameAuthStrategy CacheName = "AuthStrategy" CacheNameNamespace CacheName = "Namespace" CacheNameClient CacheName = "Client" CacheNameConfigFile CacheName = "ConfigFile" CacheNameFaultDetectRule CacheName = "FaultDetectRule" )
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 ¶
ClientIterProc client iter proc func
type Config ¶
type Config struct { Open bool `yaml:"open"` DiffTime time.Duration `yaml:"diffTime"` Resources []ConfigEntry `yaml:"resources"` }
Config 缓存配置
type ConfigEntry ¶
ConfigEntry 单个缓存资源配置
type Entry ¶
type Entry struct { Content string Md5 string Version uint64 // 创建的时候,设置过期时间 ExpireTime time.Time // 标识是否是空缓存 Empty bool }
Entry 缓存实体对象
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 ¶ added in v1.14.0
type FaultDetectCache interface { Cache // GetFaultDetectConfig 根据ServiceID获取探测配置 GetFaultDetectConfig(svcName string, namespace string) *model.ServiceWithFaultDetectRules }
FaultDetectCache fault detect rule cache service
type FileCache ¶
type FileCache interface { Cache // Get 通过ns,group,filename获取 Entry Get(namespace, group, fileName string) (*Entry, bool) // GetOrLoadIfAbsent GetOrLoadIfAbsent(namespace, group, fileName string) (*Entry, error) // Remove Remove(namespace, group, fileName string) // ReLoad ReLoad(namespace, group, fileName string) (*Entry, error) // GetOrLoadGroupByName GetOrLoadGroupByName(namespace, group string) (*model.ConfigFileGroup, error) // GetOrLoadGroupById GetOrLoadGroupById(id uint64) (*model.ConfigFileGroup, error) // CleanAll CleanAll() }
FileCache file cache
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) []string // GetInstanceLabels Get the label of all instances under a service GetInstanceLabels(serviceID string) *apiservice.InstanceLabels }
InstanceCache 实例相关的缓存接口
type InstanceIterProc ¶
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 NamespaceCache ¶
type NamespaceCache interface { Cache // GetNamespace // @param id // @return *model.Namespace GetNamespace(id string) *model.Namespace // GetNamespacesByName // @param names // @return []*model.Namespace // @return error GetNamespacesByName(names []string) []*model.Namespace // GetNamespaceList // @return []*model.Namespace 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 ¶
RateLimitIterProc rate limit iter func
type RateLimitRuleArgs ¶ added in v1.17.0
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 ¶ added in v1.16.0
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) // GetRoutingConfigCount Get the total number of routing configuration cache GetRoutingConfigCount() int // QueryRoutingConfigsV2 Query Route Configuration List QueryRoutingConfigsV2(args *RoutingArgs) (uint32, []*model.ExtendRouterConfig, error) // 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 // Update Query trigger update interface Update() error }
ServiceCache 服务数据缓存接口
type ServiceIterProc ¶
ServiceIterProc 迭代回调函数
type ServiceWithRouterRules ¶ added in v1.16.0
type ServiceWithRouterRules struct { Service model.ServiceKey Revision string // contains filtered or unexported fields }
ServiceWithCircuitBreakerRules 与服务关系绑定的熔断规则
func NewServiceWithRouterRules ¶ added in v1.16.0
func NewServiceWithRouterRules(svcKey model.ServiceKey) *ServiceWithRouterRules
func (*ServiceWithRouterRules) AddRouterRule ¶ added in v1.16.0
func (s *ServiceWithRouterRules) AddRouterRule(rule *model.ExtendRouterConfig)
func (*ServiceWithRouterRules) Clear ¶ added in v1.16.0
func (s *ServiceWithRouterRules) Clear()
func (*ServiceWithRouterRules) CountRouterRules ¶ added in v1.16.0
func (s *ServiceWithRouterRules) CountRouterRules() int
func (*ServiceWithRouterRules) DelRouterRule ¶ added in v1.16.0
func (s *ServiceWithRouterRules) DelRouterRule(id string)
func (*ServiceWithRouterRules) IterateRouterRules ¶ added in v1.16.0
func (s *ServiceWithRouterRules) IterateRouterRules(callback func(*model.ExtendRouterConfig))
type StrategyCache ¶
type StrategyCache interface { Cache // GetStrategyDetailsByUID // @param uid // @return []*model.StrategyDetail 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 // ForceSyncStrategy2Cache 强制同步鉴权策略到cache (串行) ForceSyncStrategy2Cache() error }
StrategyCache is a cache for strategy rules.
type UserCache ¶
type UserCache interface { Cache // GetAdmin 获取管理员信息 GetAdmin() *model.User // GetUserByID // @param id // @return *model.User GetUserByID(id string) *model.User // GetUserByName // @param name // @return *model.User GetUserByName(name, ownerName string) *model.User // GetUserGroup // @param id // @return *model.UserGroupDetail GetGroup(id string) *model.UserGroupDetail // IsUserInGroup 判断 userid 是否在对应的 group 中 // @param userId // @param groupId // @return bool IsUserInGroup(userId, groupId string) bool // IsOwner // @param id // @return bool IsOwner(id string) bool // GetUserLinkGroupIds // @param id // @return []string GetUserLinkGroupIds(id string) []string }
UserCache User information cache
type WatchInstanceReload ¶
type WatchInstanceReload struct {
// 实际的处理方法
Handler func(val interface{})
}
WatchInstanceReload Listener 的一个简单实现
func (*WatchInstanceReload) OnBatchCreated ¶
func (fc *WatchInstanceReload) OnBatchCreated(value interface{})
OnBatchCreated callback when cache value created
func (*WatchInstanceReload) OnBatchDeleted ¶
func (fc *WatchInstanceReload) OnBatchDeleted(value interface{})
OnBatchDeleted callback when cache value deleted
func (*WatchInstanceReload) OnBatchUpdated ¶
func (fc *WatchInstanceReload) OnBatchUpdated(value interface{})
OnBatchUpdated callback when cache value updated
func (*WatchInstanceReload) OnCreated ¶
func (fc *WatchInstanceReload) OnCreated(value interface{})
OnCreated callback when cache value created
func (*WatchInstanceReload) OnDeleted ¶
func (fc *WatchInstanceReload) OnDeleted(value interface{})
OnDeleted callback when cache value deleted
func (*WatchInstanceReload) OnUpdated ¶
func (fc *WatchInstanceReload) OnUpdated(value interface{})
OnUpdated callback when cache value updated
Source Files ¶
- cache.go
- circuitbreaker_config.go
- client.go
- client_metrics.go
- config.go
- config_file.go
- config_file_bucket.go
- config_file_metrics.go
- default.go
- faultdetect.go
- instance.go
- instance_bucket.go
- instance_metrics.go
- l5.go
- listener.go
- log.go
- namespace.go
- ratelimit_bucket.go
- ratelimit_config.go
- ratelimit_query.go
- routing_config.go
- routing_config_bucket.go
- routing_config_query.go
- service.go
- service_bucket.go
- service_query.go
- strategy.go
- strategy_bucket.go
- test_export.go
- user.go
- user_bucket.go