Documentation ¶
Index ¶
- Variables
- func CheckBCSGroup(local string, svr *loadbalance.ExportService) bool
- func CloseLogger()
- func ExportServiceKeyFunc(obj interface{}) (string, error)
- func GetName(node string) string
- func InitLogger(config *option.LBConfig)
- type AdapterZkClient
- func (azc *AdapterZkClient) Children(path string) ([]string, *zk.Stat, error)
- func (azc *AdapterZkClient) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)
- func (azc *AdapterZkClient) Exists(path string) (bool, *zk.Stat, error)
- func (azc *AdapterZkClient) ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)
- func (azc *AdapterZkClient) Get(path string) ([]byte, *zk.Stat, error)
- func (azc *AdapterZkClient) GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)
- type DataReflector
- type EventHandler
- type LBEventProcessor
- func (lp *LBEventProcessor) HandleSignal(signalChan <-chan os.Signal)
- func (lp *LBEventProcessor) OnAdd(obj interface{})
- func (lp *LBEventProcessor) OnDelete(obj interface{})
- func (lp *LBEventProcessor) OnUpdate(oldObj, newObj interface{})
- func (lp *LBEventProcessor) Start() error
- func (lp *LBEventProcessor) Stop()
- type ServiceReflector
- type ZkClient
Constants ¶
This section is empty.
Variables ¶
var ( // LoadbalanceZookeeperStateMetric loadbalance metric for zookeeper connection LoadbalanceZookeeperStateMetric = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: "loadbalance", Subsystem: "zookeeper", Name: "state", Help: "the state for zookeeper connection, 0 for abnormal, 1 for normal", }, []string{types.MetricLabelLoadbalance}, ) // LoadbalanceZookeeperEventAddMetric loadbalance metric for zookeeper event add LoadbalanceZookeeperEventAddMetric = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "loadbalance", Subsystem: "zookeeper", Name: "export_service_event_add", Help: "add event of exported service record in zookeeper", }, []string{types.MetricLabelLoadbalance}, ) // LoadbalanceZookeeperEventUpdateMetric loadbalance metric for zookeeper event update LoadbalanceZookeeperEventUpdateMetric = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "loadbalance", Subsystem: "zookeeper", Name: "export_service_event_update", Help: "update event of exported service record in zookeeper", }, []string{types.MetricLabelLoadbalance}, ) // LoadbalanceZookeeperEventDeleteMetric loadbalance metric for zookeeper event delete LoadbalanceZookeeperEventDeleteMetric = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "loadbalance", Subsystem: "zookeeper", Name: "export_service_event_delete", Help: "delete event of exported service record in zookeeper", }, []string{types.MetricLabelLoadbalance}, ) // LoadbalanceServiceConflictMetric loadbalance metric for service conflict about port or [port + domain + url] LoadbalanceServiceConflictMetric = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "loadbalance", Subsystem: "service", Name: "conflict_total", Help: "conflict counter of service", }, []string{types.MetricLabelLoadbalance, types.MetricLabelServiceName}, ) )
Functions ¶
func CheckBCSGroup ¶
func CheckBCSGroup(local string, svr *loadbalance.ExportService) bool
CheckBCSGroup check if local is in groups
func ExportServiceKeyFunc ¶
ExportServiceKeyFunc key function format Service uniq key
Types ¶
type AdapterZkClient ¶
type AdapterZkClient struct {
// contains filtered or unexported fields
}
AdapterZkClient to adapt common zk interface and go-zookeeper zk
func NewAdapterZkClient ¶
func NewAdapterZkClient(host []string, sessionTimeOut time.Duration) (*AdapterZkClient, error)
NewAdapterZkClient to new a AdapterZkClient and connect zk
type DataReflector ¶
type DataReflector interface { Lister() (http, https types.HTTPServiceInfoList, tcp, udp types.FourLayerServiceInfoList) Start() error Stop() }
DataReflector interface for unit test injection
type EventHandler ¶
type EventHandler interface { OnAdd(obj interface{}) OnDelete(obj interface{}) OnUpdate(oldObj, newObj interface{}) }
EventHandler is event interface when
type LBEventProcessor ¶
type LBEventProcessor struct {
// contains filtered or unexported fields
}
LBEventProcessor event loop for handling data change event.
func NewEventProcessor ¶
func NewEventProcessor(config *option.LBConfig) *LBEventProcessor
NewEventProcessor create EventProcessor with LBConfig
func (*LBEventProcessor) HandleSignal ¶
func (lp *LBEventProcessor) HandleSignal(signalChan <-chan os.Signal)
HandleSignal interface for handle signal from system/User
func (*LBEventProcessor) OnAdd ¶
func (lp *LBEventProcessor) OnAdd(obj interface{})
OnAdd receive data Add event
func (*LBEventProcessor) OnDelete ¶
func (lp *LBEventProcessor) OnDelete(obj interface{})
OnDelete receive data Delete event
func (*LBEventProcessor) OnUpdate ¶
func (lp *LBEventProcessor) OnUpdate(oldObj, newObj interface{})
OnUpdate receive data Update event
func (*LBEventProcessor) Start ¶
func (lp *LBEventProcessor) Start() error
Start starting point for event processing 1. start reflector to cache data from storage 2. start template manager for Create/Reload config for haproxy.cfg 3. start local logic loop for check data changed
func (*LBEventProcessor) Stop ¶
func (lp *LBEventProcessor) Stop()
Stop stop processor all worker gracefully
type ServiceReflector ¶
type ServiceReflector struct {
// contains filtered or unexported fields
}
ServiceReflector handling/holding service data coming from zookeeper reflector will do: 1. sync all zookeeper data in period, default 30 seconds 2. watch children of data path 3. watch all children data of path 4. cache all zookeeper data, notify EventHandler when data changed reflector will running in other goroutine,
func NewReflector ¶
func NewReflector(config *option.LBConfig, handler EventHandler) *ServiceReflector
NewReflector create new ServiceReflector
func (*ServiceReflector) Lister ¶
func (reflector *ServiceReflector) Lister() (http, https types.HTTPServiceInfoList, tcp, udp types.FourLayerServiceInfoList)
Lister classify all service to 3 types: http service, https service and tcp service
func (*ServiceReflector) Start ¶
func (reflector *ServiceReflector) Start() error
Start reflector to syncing data from data source to local cache 1. starting connection for zookeeper, watch cluster path, cluster children node data 2. starting goroutine list all cluster service period 3. starting channel receiving control events from upper app
func (*ServiceReflector) Stop ¶
func (reflector *ServiceReflector) Stop()
Stop reflector, send stop event to all goroutines
type ZkClient ¶
type ZkClient interface { Get(path string) ([]byte, *zk.Stat, error) GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error) Children(path string) ([]string, *zk.Stat, error) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error) Exists(path string) (bool, *zk.Stat, error) ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error) }
ZkClient interface to define zk operation interface is only use for dependency injection