package multiendpoint

import "github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp/multiendpoint"

Package multiendpoint implements multiendpoint feature. See MultiEndpoint

Index

Types

type MultiEndpoint

type MultiEndpoint interface {
	// Current returns current endpoint.
	//
	// Note that the read is not synchronized and in case of a race condition there is a chance of
	// getting an outdated current endpoint.
	Current() string

	// SetEndpointAvailability informs MultiEndpoint when an endpoint becomes available or unavailable.
	// This may change the current endpoint.
	SetEndpointAvailability(e string, avail bool)

	// SetEndpoints updates a list of endpoints:
	//   - remove obsolete endpoints
	//   - preserve remaining endpoints and their states
	//   - add new endpoints
	//   - update all endpoints priority according to the new order
	// This may change the current endpoint.
	SetEndpoints(endpoints []string) error
}

MultiEndpoint holds a list of endpoints, tracks their availability and defines the current endpoint. An endpoint has a priority defined by its position in the list (first item has top priority).

The current endpoint is the highest available endpoint in the list. If no endpoint is available, MultiEndpoint sticks to the previously current endpoint.

Sometimes switching between endpoints can be costly, and it is worth waiting for some time after current endpoint becomes unavailable. For this case, use [MultiEndpointOptions.RecoveryTimeout] to set the recovery timeout. MultiEndpoint will keep the current endpoint for up to recovery timeout after it became unavailable to give it some time to recover.

The list of endpoints can be changed at any time with [MultiEndpoint.SetEndpoints] function. MultiEndpoint will:

After updating the list of endpoints, MultiEndpoint will switch the current endpoint to the highest available endpoint in the list. If you have many processes using MultiEndpoint, this may lead to immediate shift of all traffic which may be undesired. To smooth this transfer, use [MultiEndpointOptions.SwitchingDelay] with randomized value to introduce a jitter. Each MultiEndpoint will delay switching from an available endpoint to another endpoint for this amount of time. This delay is only applicable when switching from a lower priority available endpoint to a higher priority available endpoint.

func NewMultiEndpoint

func NewMultiEndpoint(b *MultiEndpointOptions) (MultiEndpoint, error)

NewMultiEndpoint validates options and creates a new MultiEndpoint.

type MultiEndpointOptions

type MultiEndpointOptions struct {
	// A list of endpoints ordered by priority (first endpoint has top priority).
	Endpoints []string
	// RecoveryTimeout sets the amount of time MultiEndpoint keeps endpoint as current after it
	// became unavailable.
	RecoveryTimeout time.Duration
	// When switching from a lower priority available endpoint to a higher priority available
	// endpoint the MultiEndpoint will delay the switch for this duration.
	SwitchingDelay time.Duration
}

MultiEndpointOptions is used for configuring MultiEndpoint.

Source Files

endpoint.go multiendpoint.go

Version
v1.5.2 (latest)
Published
Oct 25, 2024
Platform
js/wasm
Imports
4 packages
Last checked
1 day ago

Tools for package owners.