receiver

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	RELOAD_HOLD_DOWN = 5 * time.Second // Reload at worst every 5 seconds
)

Variables

This section is empty.

Functions

func FetchState

func FetchState(url string) (*catalog.ServicesState, error)

Used to fetch the current state from a Sidecar endpoint, usually on startup of this process, when the currentState is empty.

func ShouldNotify

func ShouldNotify(oldStatus int, newStatus int) bool

Check all the state transitions and only update HAproxy when a change will affect service availability.

func UpdateHandler

func UpdateHandler(response http.ResponseWriter, req *http.Request, rcvr *Receiver)

Receives POSTed state updates from a Sidecar instance

Types

type ApiErrors

type ApiErrors struct {
	Errors []string `json:"errors"`
}

type Receiver

type Receiver struct {
	StateLock      sync.Mutex
	ReloadChan     chan time.Time
	CurrentState   *catalog.ServicesState
	LastSvcChanged *service.Service
	OnUpdate       func(state *catalog.ServicesState)
	Looper         director.Looper
	Subscriptions  []string
}

func NewReceiver added in v1.3.0

func NewReceiver(capacity int, onUpdate func(state *catalog.ServicesState)) *Receiver

func (*Receiver) EnqueueUpdate

func (rcvr *Receiver) EnqueueUpdate()

EnqueueUpdate puts a new timestamp on the update channel, to be processed in a goroutine that runs the ProcessUpdates function.

func (*Receiver) FetchInitialState

func (rcvr *Receiver) FetchInitialState(stateUrl string) error

FetchInitialState is used at startup to bootstrap initial state from Sidecar.

func (*Receiver) IsSubscribed

func (rcvr *Receiver) IsSubscribed(svcName string) bool

IsSubscribed allows a receiver to filter incoming events by service name

func (*Receiver) ProcessUpdates

func (rcvr *Receiver) ProcessUpdates()

ProcessUpdates loops forever, processing updates to the state. By the time we get here, the HTTP UpdateHandler has already set the CurrentState to the newest state we know about. Here we'll try to group updates together to prevent repeatedly updating on a series of events that arrive in a row.

func (*Receiver) Subscribe

func (rcvr *Receiver) Subscribe(svcName string)

Subscribe is not synchronized and should not be called dynamically. This is generally used at setup of the Receiver, before any events begin arriving.

Jump to

Keyboard shortcuts

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