spotconsul

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorConsulKeyNotExist = errors.New("key not exist")

Functions

func Prettify

func Prettify(i interface{}) string

Prettify returns the string representation of a value.

func String

func String(v string) *string

String returns a pointer to the string value passed in.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

Types

type BalanceZone

type BalanceZone struct {
	Enabled           bool    `json:"enabled"`
	LearningRate      float64 `json:"learningRate"`
	LearningThreshold float64 `json:"learningThreshold"`
}

管理节点间均衡参数

type CDFactors

type CDFactors struct {
	Updated int64               `json:"updated"`
	Data    []*CDInstanceFactor `json:"data"`
}

type CDInstanceFactor

type CDInstanceFactor struct {
	CPUUtilization float64 `json:"CPUUtilization"`
	InstanceId     string  `json:"instanceid"`
	PublicIp       string  `json:"public_ip"`
	Zone           string  `json:"zone"`
}

type CDZoneCPU

type CDZoneCPU struct {
	Updated int64         `json:"updated"`
	Data    []interface{} `json:"data"`
}

type Config

type Config struct {
	Global *GlobalConfig  `json:"global"`
	Logic  []*LogicConfig `json:"logic"`
}

func NewConfig

func NewConfig(filepath string) *Config

type Consul

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

func NewConsul

func NewConsul(address string) *Consul

创建一个链接,失败的话会panic

func (*Consul) GetKey

func (c *Consul) GetKey(key string) ([]byte, error)

func (*Consul) GetService

func (c *Consul) GetService(service string) ([]*api.ServiceEntry, error)

包装一下,不需要meta,只要健康的节点

func (*Consul) PutKey

func (c *Consul) PutKey(key string, value []byte) error

type CrossZone

type CrossZone struct {
	AlarmThreshold    float64 `json:"alarmThreshold"`
	CrossRate         float64 `json:"crossRate"`
	Enabled           bool    `json:"enabled"`
	LearningRate      float64 `json:"learningRate"`
	LearningThreshold float64 `json:"learningThreshold"`
}

管理跨区域的均衡参数

type DataInstanceFactor

type DataInstanceFactor struct {
}

type GlobalConfig

type GlobalConfig struct {
	LoopingTimeS       int64 `json:"loopingTimeS"`
	LingerTimeS        int64 `json:"lingerTimeS"`
	FreshLearningStart bool  `json:"freshLearningStart"`
}

type GlobalService

type GlobalService struct {
	Services []*Service
}

Manage global wide service

type InitialWeight

type InitialWeight struct {
	InitialFactors map[string]float64
}

func NewInitialWeight

func NewInitialWeight() *InitialWeight

func (*InitialWeight) Fetch

func (iw *InitialWeight) Fetch(service *Service)

func (*InitialWeight) Unhealthy

func (iw *InitialWeight) Unhealthy(factors LearningFactors) []string

计算learning权重和初始化权重,返回确认有风险的实例 TODO:通过计算方差或人工限定的阈值防止风险

type InstanceLoad

type InstanceLoad struct {
	Load       float64
	InstanceId string
	PublicIp   string
}

type Lab

type Lab struct {
	BalanceZone BalanceZone `json:"balanceZone"`
	CrossZone   CrossZone   `json:"crossZone"`
}

type LearningFactors

type LearningFactors struct {
	InstanceFactors map[string]float64 `json:"instanceFactors"`
	CrossRate       map[string]float64 `json:"crossRate"`
}

type Logic

type Logic struct {
	Consul        *Consul
	InitialWeight *InitialWeight
	OnlineLab     *OnlineLab
	Service       *Service
	WeightLearner *WeightLearner
	ServiceName   string
	Workload      Workload // interface support other workload
	// contains filtered or unexported fields
}

func NewLearningLogic

func NewLearningLogic(logicCfg *LogicConfig, globalCfg *GlobalConfig) *Logic

func (*Logic) FetchAll

func (l *Logic) FetchAll() error

func (*Logic) Learning

func (l *Logic) Learning() error

func (*Logic) RunOnce

func (l *Logic) RunOnce() error

func (*Logic) RunningLoop

func (l *Logic) RunningLoop(ctx context.Context)

func (*Logic) UpdateAll

func (l *Logic) UpdateAll() error

type LogicConfig

type LogicConfig struct {
	ConsulAddr        string `json:"consulAddr"`
	InstanceLoadKey   string `json:"instanceLoadKey"`
	LearningFactorKey string `json:"learningFactorKey"`
	OnlineLabKey      string `json:"onlineLabKey"`
	ServiceName       string `json:"serviceName"`
	ZoneCPUKey        string `json:"zoneCPUKey"`
}

type MockWorkload

type MockWorkload struct {
}

Mock一个负载对象用于快速开发测试

func (*MockWorkload) Fetch

func (wl *MockWorkload) Fetch(consul *Consul) error

func (*MockWorkload) GetInstanceLoad

func (wl *MockWorkload) GetInstanceLoad() []*InstanceLoad

func (*MockWorkload) GetZoneLoad

func (wl *MockWorkload) GetZoneLoad() map[string]float64

type OnlineLab

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

func NewOnlineLab

func NewOnlineLab(key string) *OnlineLab

需要给个默认的参数

func (*OnlineLab) DefaultLab

func (ol *OnlineLab) DefaultLab()

设置默认的lab,方便测试和初期上线,或紧急恢复等等 这里一定要设置安全的值

func (*OnlineLab) Fetch

func (ol *OnlineLab) Fetch(consul *Consul) error

如果fetch成功了,lab可用不为空

func (*OnlineLab) GetLab

func (ol *OnlineLab) GetLab() (*Lab, error)

使用时防止用到空指针

type Service

type Service struct {
	Name   string
	Nodes  map[string]*ServiceNode
	Zones  map[string][]*ServiceNode
	Region string
}

Manage a service, every service manage many zones

func GetService

func GetService(consul *Consul, serviceName string) (*Service, error)

type ServiceNode

type ServiceNode struct {
	DefaultFactor float64
	InstanceId    string
	Host          string
	Zone          string
}

Better to use a struct to manage node detail Data filled when reading consul key

type WeightLearner

type WeightLearner struct {
	Key           string
	Factors       *LearningFactors
	InitialWeight *InitialWeight
}

Weight factor should learn from workload 用一个模型来管理权重与学习方法便于升级维护 初始化的权重用于控制实时学习权重的偏离风险,明显偏离太多是有可能发生了bug,需要控制一下

func MockWeightLearner

func MockWeightLearner(key string) *WeightLearner

方便做前期测试使用,设置默认的学习数据

func NewWeightLearner

func NewWeightLearner(key string) *WeightLearner

func (*WeightLearner) Clear

func (wl *WeightLearner) Clear(consul *Consul) error

func (*WeightLearner) Fetch

func (wl *WeightLearner) Fetch(consul *Consul) error

func (*WeightLearner) GetLearningFactors

func (wl *WeightLearner) GetLearningFactors() *LearningFactors

func (*WeightLearner) LearningCrossRate

func (wl *WeightLearner) LearningCrossRate(workload Workload, ol *OnlineLab) error

func (*WeightLearner) LearningFactors

func (wl *WeightLearner) LearningFactors(service *Service, workload Workload, ol *OnlineLab) error

func (*WeightLearner) RiskControl

func (wl *WeightLearner) RiskControl(initWeight *InitialWeight)

func (*WeightLearner) Update

func (wl *WeightLearner) Update(consul *Consul) error

type Workload

type Workload interface {
	Fetch(consul *Consul) error
	GetInstanceLoad() []*InstanceLoad
	GetZoneLoad() map[string]float64
}

type WorkloadCPU

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

func NewWorkloadCPU

func NewWorkloadCPU(instanceLoadKey string, zoneLoadKey string) *WorkloadCPU

func (*WorkloadCPU) Fetch

func (wl *WorkloadCPU) Fetch(consul *Consul) error

func (*WorkloadCPU) GetInstanceLoad

func (wl *WorkloadCPU) GetInstanceLoad() []*InstanceLoad

func (*WorkloadCPU) GetZoneLoad

func (wl *WorkloadCPU) GetZoneLoad() map[string]float64

Jump to

Keyboard shortcuts

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