app

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 CloseLogger

func CloseLogger()

CloseLogger close logger

func ExportServiceKeyFunc

func ExportServiceKeyFunc(obj interface{}) (string, error)

ExportServiceKeyFunc key function format Service uniq key

func GetName

func GetName(node string) string

GetName get real service name from zookeeper node name

func InitLogger

func InitLogger(config *option.LBConfig)

InitLogger init app logger

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

func (*AdapterZkClient) Children

func (azc *AdapterZkClient) Children(path string) ([]string, *zk.Stat, error)

Children to get path children node

func (*AdapterZkClient) ChildrenW

func (azc *AdapterZkClient) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)

ChildrenW to get path children node and watch their change

func (*AdapterZkClient) Exists

func (azc *AdapterZkClient) Exists(path string) (bool, *zk.Stat, error)

Exists to judge node exist or not

func (*AdapterZkClient) ExistsW

func (azc *AdapterZkClient) ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)

ExistsW to judge node exist or not and watch it

func (*AdapterZkClient) Get

func (azc *AdapterZkClient) Get(path string) ([]byte, *zk.Stat, error)

Get to get a node value

func (*AdapterZkClient) GetW

func (azc *AdapterZkClient) GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)

GetW to get a node value and watch its change

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

Jump to

Keyboard shortcuts

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