observer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendFetcher

type BackendFetcher interface {
	GetBackendList(context.Context) (map[string]*BackendInfo, error)
}

BackendFetcher is an interface to fetch the backend list.

type BackendHealth

type BackendHealth struct {
	BackendInfo
	Healthy bool
	// The error occurred when health check fails. It's used to log why the backend becomes unhealthy.
	PingErr error
	// The backend version that returned to the client during handshake.
	ServerVersion string
	// Whether the backend in the same zone with TiProxy. If TiProxy location is undefined, take all backends as local.
	Local bool
}

func (*BackendHealth) Equals

func (bh *BackendHealth) Equals(health BackendHealth) bool

func (*BackendHealth) String

func (bh *BackendHealth) String() string

type BackendInfo

type BackendInfo struct {
	Labels     map[string]string
	IP         string
	StatusPort uint
}

BackendInfo stores the status info of each backend.

type BackendObserver

type BackendObserver interface {
	Start(ctx context.Context)
	Subscribe(name string) <-chan HealthResult
	Unsubscribe(name string)
	Refresh()
	Close()
}

type DefaultBackendObserver

type DefaultBackendObserver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DefaultBackendObserver refreshes backend list and notifies BackendEventReceiver.

func NewDefaultBackendObserver

func NewDefaultBackendObserver(logger *zap.Logger, config *config.HealthCheck, backendFetcher BackendFetcher, hc HealthCheck,
	cfgGetter config.ConfigGetter) *DefaultBackendObserver

NewDefaultBackendObserver creates a BackendObserver.

func (*DefaultBackendObserver) Close

func (bo *DefaultBackendObserver) Close()

Close releases all resources.

func (*DefaultBackendObserver) Refresh

func (bo *DefaultBackendObserver) Refresh()

Refresh indicates the observer to refresh immediately.

func (*DefaultBackendObserver) Start

func (bo *DefaultBackendObserver) Start(ctx context.Context)

Start starts watching.

func (*DefaultBackendObserver) Subscribe

func (bo *DefaultBackendObserver) Subscribe(name string) <-chan HealthResult

func (*DefaultBackendObserver) Unsubscribe

func (bo *DefaultBackendObserver) Unsubscribe(name string)

type DefaultHealthCheck

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

func NewDefaultHealthCheck

func NewDefaultHealthCheck(httpCli *http.Client, cfg *config.HealthCheck, logger *zap.Logger) *DefaultHealthCheck

func (*DefaultHealthCheck) Check

func (dhc *DefaultHealthCheck) Check(ctx context.Context, addr string, info *BackendInfo) *BackendHealth

type HealthCheck

type HealthCheck interface {
	Check(ctx context.Context, addr string, info *BackendInfo) *BackendHealth
}

HealthCheck is used to check the backends of one backend. One can pass a customized health check function to the observer.

type HealthResult

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

HealthResult contains the health check results and is used to notify the routers. It's read-only for subscribers.

func NewHealthResult

func NewHealthResult(backends map[string]*BackendHealth, err error) HealthResult

NewHealthResult is used for testing in other packages.

func (HealthResult) Backends

func (hr HealthResult) Backends() map[string]*BackendHealth

func (HealthResult) Error

func (hr HealthResult) Error() error

type PDFetcher

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

PDFetcher fetches backend list from PD.

func NewPDFetcher

func NewPDFetcher(tpFetcher TopologyFetcher, logger *zap.Logger, config *config.HealthCheck) *PDFetcher

func (*PDFetcher) GetBackendList

func (pf *PDFetcher) GetBackendList(ctx context.Context) (map[string]*BackendInfo, error)

type StaticFetcher

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

StaticFetcher uses configured static addrs. This is only used for testing.

func NewStaticFetcher

func NewStaticFetcher(staticAddrs []string) *StaticFetcher

func (*StaticFetcher) GetBackendList

func (sf *StaticFetcher) GetBackendList(context.Context) (map[string]*BackendInfo, error)

type TopologyFetcher

type TopologyFetcher interface {
	GetTiDBTopology(ctx context.Context) (map[string]*infosync.TiDBTopologyInfo, error)
}

TopologyFetcher is an interface to fetch the tidb topology from ETCD.

Jump to

Keyboard shortcuts

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