cluster

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateNodeID

func GenerateNodeID() string

Types

type Metrics

type Metrics struct {
	// Nodes contains the number of known nodes in the cluster, labelled by
	// status.
	Nodes *prometheus.GaugeVec
}

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) Register

func (m *Metrics) Register(registry *prometheus.Registry)

type Node

type Node struct {
	// ID is a unique identifier for the node in the cluster.
	//
	// The ID is immutable.
	ID string `json:"id"`

	// Status contains the known status of the node.
	Status NodeStatus `json:"status"`

	// ProxyAddr is the advertised proxy address.
	//
	// The address is immutable.
	ProxyAddr string `json:"proxy_addr"`

	// AdminAddr is the advertised admin address.
	//
	// The address is immutable.
	AdminAddr string `json:"admin_addr"`

	// Endpoints contains the known active endpoints on the node (endpoints
	// with at least one upstream listener).
	//
	// This maps the endpoint ID to the number of known listeners for that
	// endpoint.
	Endpoints map[string]int `json:"endpoints"`
}

Node represents the known state about a node in the cluster.

Note to ensure updates are propagated, never update a node directly, only ever update via the NetworkMap.

func (*Node) Copy

func (n *Node) Copy() *Node

func (*Node) Metadata

func (n *Node) Metadata() *NodeMetadata

type NodeMetadata

type NodeMetadata struct {
	ID        string     `json:"id"`
	Status    NodeStatus `json:"status"`
	ProxyAddr string     `json:"proxy_addr"`
	AdminAddr string     `json:"admin_addr"`
	Endpoints int        `json:"endpoints"`
	// Upstreams is the number of upstreams connected to this node.
	Upstreams int `json:"upstreams"`
}

NodeMetadata contains metadata fields from Node.

type NodeStatus

type NodeStatus string

NodeStatus contains the known status of a node.

const (
	// NodeStatusActive means the node is healthy and accepting traffic.
	NodeStatusActive NodeStatus = "active"
	// NodeStatusUnreachable means the node is considered unreachable.
	NodeStatusUnreachable NodeStatus = "unreachable"
	// NodeStatusLeft means the node has left the cluster.
	NodeStatusLeft NodeStatus = "left"
)

type State

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

State represents the known state of the cluster as seen by the local node.

This state is eventually consistent.

func NewState

func NewState(
	localNode *Node,
	logger log.Logger,
) *State

func (*State) AddLocalEndpoint

func (s *State) AddLocalEndpoint(endpointID string)

AddLocalEndpoint adds the active endpoint to the local node state.

func (*State) AddNode

func (s *State) AddNode(node *Node)

AddNode adds the given node to the cluster.

func (*State) LocalEndpointListeners

func (s *State) LocalEndpointListeners(endpointID string) int

func (*State) LocalID

func (s *State) LocalID() string

LocalID returns the ID of the local node.

func (*State) LocalNode

func (s *State) LocalNode() *Node

LocalNode returns the state of the local node.

func (*State) LookupEndpoint

func (s *State) LookupEndpoint(endpointID string) (*Node, bool)

LookupEndpoint looks up a node that the endpoint with the given ID is active on.

func (*State) Metrics

func (s *State) Metrics() *Metrics

func (*State) Node

func (s *State) Node(id string) (*Node, bool)

Node returns the known state of the node with the given ID, or false if the node is unknown.

func (*State) Nodes

func (s *State) Nodes() []*Node

Nodes returns the state of the known nodes.

func (*State) NodesMetadata

func (s *State) NodesMetadata() []*NodeMetadata

NodesMetadata returns the metadata of the known nodes.

func (*State) OnLocalEndpointUpdate

func (s *State) OnLocalEndpointUpdate(f func(endpointID string))

OnLocalEndpointUpdate subscribes to changes to the local nodes active endpoints.

The callback is called with the cluster mutex locked so must not block or call back to the cluster.

func (*State) OnRemoteEndpointUpdate added in v0.5.0

func (s *State) OnRemoteEndpointUpdate(f func(nodeID string, endpointID string))

func (*State) RemoveLocalEndpoint

func (s *State) RemoveLocalEndpoint(endpointID string)

RemoveLocalEndpoint removes the active endpoint from the local node state.

func (*State) RemoveNode

func (s *State) RemoveNode(id string) bool

RemoveNode removes the node with the given ID from the cluster.

func (*State) RemoveRemoteEndpoint

func (s *State) RemoveRemoteEndpoint(id string, endpointID string) bool

RemoveRemoteEndpoint removes the active endpoint from the node with the given ID.

func (*State) UpdateRemoteEndpoint

func (s *State) UpdateRemoteEndpoint(
	id string,
	endpointID string,
	listeners int,
) bool

UpdateRemoteEndpoint sets the number of listeners for the active endpoint for the node with the given ID.

func (*State) UpdateRemoteStatus

func (s *State) UpdateRemoteStatus(id string, status NodeStatus) bool

UpdateRemoteStatus sets the status of the remote node with the given ID.

type Status

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

func NewStatus

func NewStatus(state *State) *Status

func (*Status) Register

func (s *Status) Register(group *gin.RouterGroup)

Jump to

Keyboard shortcuts

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