plugin

package
v1.13.5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 6 Imported by: 12

Documentation

Index

Constants

View Source
const (
	ComponentServer = "server"
	ComponentRedis  = "redis"

	ComponentProtobufCache = "protobuf"
)

Variables

View Source
var RatelimitStr = map[RatelimitType]string{
	IPRatelimit:       "ip-limit",
	APIRatelimit:      "api-limit",
	ServiceRatelimit:  "service-limit",
	InstanceRatelimit: "instance-limit",
}

RatelimitStr rate limit string map

Functions

func RegisterPlugin

func RegisterPlugin(name string, plugin Plugin)

RegisterPlugin 注册插件

func SetPluginConfig

func SetPluginConfig(c *Config)

SetPluginConfig 设置插件配置

Types

type AddCheckRequest

type AddCheckRequest struct {
	Instances []string
	LocalHost string
}

AddCheckRequest add check request

type CMDB

type CMDB interface {
	Plugin

	// GetLocation 在CMDB中没有找到Host,返回error为nil,location为nil
	// 插件内部出现错误,返回error不为nil,忽略location
	GetLocation(host string) (*model.Location, error)

	// Range 提供一个Range接口,遍历所有的数据
	// 遍历失败,通过Range返回值error可以额捕获
	// 参数为一个回调函数
	// 返回值:bool,是否继续遍历
	// 返回值:error,回调函数处理结果,error不为nil,则停止遍历过程,并且通过Range返回error
	Range(handler func(host string, location *model.Location) (bool, error)) error

	// Size 获取当前CMDB存储的entry个数
	Size() int32
}

CMDB CMDB插件接口

func GetCMDB

func GetCMDB() CMDB

GetCMDB 获取CMDB插件

type CheckRequest

type CheckRequest struct {
	QueryRequest
	ExpireDurationSec uint32
	CurTimeSec        func() int64
}

CheckRequest check heartbeat request

type CheckResponse

type CheckResponse struct {
	Healthy              bool
	LastHeartbeatTimeSec int64
	StayUnchanged        bool
	Regular              bool
}

CheckResponse check heartbeat response

type Config

type Config struct {
	CMDB                 ConfigEntry `yaml:"cmdb"`
	RateLimit            ConfigEntry `yaml:"ratelimit"`
	History              ConfigEntry `yaml:"history"`
	Statis               ConfigEntry `yaml:"statis"`
	DiscoverStatis       ConfigEntry `yaml:"discoverStatis"`
	ParsePassword        ConfigEntry `yaml:"parsePassword"`
	Whitelist            ConfigEntry `yaml:"whitelist"`
	MeshResourceValidate ConfigEntry `yaml:"meshResourceValidate"`
	DiscoverEvent        ConfigEntry `yaml:"discoverEvent"`
}

Config 插件配置

type ConfigEntry

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

ConfigEntry 单个插件配置

type DiscoverChannel

type DiscoverChannel interface {
	Plugin
	// PublishEvent 发布一个服务事件
	PublishEvent(event model.InstanceEvent)
}

DiscoverChannel is used to receive discover events from the agent

func GetDiscoverEvent

func GetDiscoverEvent() DiscoverChannel

GetDiscoverEvent 获取服务发现事件插件

type DiscoverStatis

type DiscoverStatis interface {
	Plugin

	// AddDiscoverCall 添加发现调用
	AddDiscoverCall(service, namespace string, tt time.Time) error
}

DiscoverStatis 服务发现统计插件接口

func GetDiscoverStatis

func GetDiscoverStatis() DiscoverStatis

GetDiscoverStatis 获取服务发现统计插件

type HealthCheckType

type HealthCheckType int32

HealthCheckType health check type

const (
	HealthCheckerHeartbeat HealthCheckType = iota + 1
)

type HealthChecker

type HealthChecker interface {
	Plugin
	// Type for health check plugin, only one same type plugin is allowed
	Type() HealthCheckType
	// Report process heartbeat info report
	Report(request *ReportRequest) error
	// Check process the instance check
	Check(request *CheckRequest) (*CheckResponse, error)
	// Query queries the heartbeat time
	Query(request *QueryRequest) (*QueryResponse, error)
	// AddToCheck add the instances to check procedure
	AddToCheck(request *AddCheckRequest) error
	// RemoveFromCheck removes the instances from check procedure
	RemoveFromCheck(request *AddCheckRequest) error
	// Delete delete the id
	Delete(id string) error
}

HealthChecker health checker plugin interface

func GetHealthChecker

func GetHealthChecker(name string, cfg *ConfigEntry) HealthChecker

GetHealthChecker get the health checker by name

type History

type History interface {
	Plugin
	Record(entry *model.RecordEntry)
}

History 历史记录插件

func GetHistory

func GetHistory() History

GetHistory 获取历史记录插件

type ParsePassword

type ParsePassword interface {
	Plugin
	ParsePassword(cipher string) (string, error)
}

ParsePassword 密码插件

func GetParsePassword

func GetParsePassword() ParsePassword

GetParsePassword 获取解析密码插件

type Plugin

type Plugin interface {
	Name() string
	Initialize(c *ConfigEntry) error
	Destroy() error
}

Plugin 通用插件接口

type QueryRequest

type QueryRequest struct {
	InstanceId string
	Host       string
	Port       uint32
	Healthy    bool
}

QueryRequest query heartbeat request

type QueryResponse

type QueryResponse struct {
	Server           string
	Exists           bool
	LastHeartbeatSec int64
}

QueryResponse query heartbeat response

type Ratelimit

type Ratelimit interface {
	Plugin

	// Allow 是否允许访问, true: 允许, false: 不允许 TODO
	// 参数rateType即限流类型,id为限流的key
	// 如果rateType为RatelimitIP则id为ip, rateType为RatelimitService则id为ip_namespace_service或ip_serviceId
	Allow(typ RatelimitType, key string) bool
}

Ratelimit Ratelimit插件接口

func GetRatelimit

func GetRatelimit() Ratelimit

GetRatelimit 获取RateLimit插件

type RatelimitType

type RatelimitType int

RatelimitType rate limit type

const (
	// IPRatelimit 基于ip的流控
	IPRatelimit RatelimitType = iota + 1

	// APIRatelimit 基于接口级限流
	APIRatelimit

	// ServiceRatelimit 基于service的流控
	ServiceRatelimit

	// InstanceRatelimit 基于Instance的限流
	InstanceRatelimit
)

type ReportRequest

type ReportRequest struct {
	QueryRequest
	LocalHost  string
	CurTimeSec int64
}

ReportRequest report heartbeat request

type Statis

type Statis interface {
	Plugin

	AddAPICall(api string, protocol string, code int, duration int64) error

	AddRedisCall(api string, code int, duration int64) error

	AddCacheCall(component string, cacheType string, miss bool, call int) error
}

Statis 统计插件接口

func GetStatis

func GetStatis() Statis

GetStatis 获取统计插件

type Whitelist

type Whitelist interface {
	Plugin

	Contain(entry interface{}) bool
}

Whitelist 白名单接口

func GetWhitelist

func GetWhitelist() Whitelist

GetWhitelist 获取Whitelist插件

Directories

Path Synopsis
cmdb
discoverevent
discoverstat
healthchecker
history
ratelimit
statis

Jump to

Keyboard shortcuts

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