loadbalancer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MPL-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package loadbalancer provides simple TCP loadbalancer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TCP

type TCP struct {
	tcpproxy.Proxy

	Logger *zap.Logger

	DialTimeout     time.Duration
	KeepAlivePeriod time.Duration
	TCPUserTimeout  time.Duration
	// contains filtered or unexported fields
}

TCP is a simple loadbalancer for TCP connections across a set of upstreams.

Healthcheck is defined as TCP dial attempt by default.

Zero value of TCP is a valid proxy, use `AddRoute` to install load balancer for address.

Usage: call Run() to start lb and wait for shutdown, call Close() to shutdown lb.

func (*TCP) AddRoute

func (t *TCP) AddRoute(ipPort string, upstreamAddrs iter.Seq[string], options ...upstream.ListOption) error

AddRoute installs load balancer route from listen address ipAddr to list of upstreams.

TCP automatically does background health checks for the upstreams and picks only healthy ones. Healthcheck is simple Dial attempt.

AddRoute should be called before Start().

func (*TCP) Close

func (t *TCP) Close() error

Close the load balancer and stop health checks on upstreams.

func (*TCP) IsRouteHealthy

func (t *TCP) IsRouteHealthy(ipPort string) (bool, error)

IsRouteHealthy checks if the route has at least one upstream available.

func (*TCP) ReconcileRoute

func (t *TCP) ReconcileRoute(ipPort string, upstreamAddrs iter.Seq[string]) error

ReconcileRoute updates the list of upstreamAddrs for the specified route (ipPort).

ReconcileRoute can be called when the loadbalancer is running.

Jump to

Keyboard shortcuts

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