...

Package cluster

import "github.com/prometheus/alertmanager/cluster"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Constants
func OversizedMessage(b []byte) bool
type Channel
    func NewChannel(key string, send func([]byte), peers func() []*memberlist.Node, sendOversize func(*memberlist.Node, []byte) error, logger log.Logger, stopc chan struct{}, reg prometheus.Registerer) *Channel
    func (c *Channel) Broadcast(b []byte)
type ClusterChannel
type ClusterMember
type ClusterPeer
type Member
    func (m Member) Address() string
    func (m Member) Name() string
type Peer
    func Create(l log.Logger, reg prometheus.Registerer, bindAddr string, advertiseAddr string, knownPeers []string, waitIfEmpty bool, pushPullInterval time.Duration, gossipInterval time.Duration, tcpTimeout time.Duration, probeTimeout time.Duration, probeInterval time.Duration, tlsTransportConfig *TLSTransportConfig, allowInsecureAdvertise bool) (*Peer, error)
    func (p *Peer) AddState(key string, s State, reg prometheus.Registerer) ClusterChannel
    func (p *Peer) ClusterSize() int
    func (p *Peer) Info() map[string]interface{}
    func (p *Peer) Join(reconnectInterval time.Duration, reconnectTimeout time.Duration) error
    func (p *Peer) Leave(timeout time.Duration) error
    func (p *Peer) Name() string
    func (p *Peer) Peers() []ClusterMember
    func (p *Peer) Position() int
    func (p *Peer) Ready() bool
    func (p *Peer) Self() *memberlist.Node
    func (p *Peer) Settle(ctx context.Context, interval time.Duration)
    func (p *Peer) Status() string
    func (p *Peer) WaitReady(ctx context.Context) error
type PeerStatus
    func (s PeerStatus) String() string
type State
type TLSTransport
    func NewTLSTransport(ctx context.Context, logger log.Logger, reg prometheus.Registerer, bindAddr string, bindPort int, cfg *TLSTransportConfig) (*TLSTransport, error)
    func (t *TLSTransport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)
    func (t *TLSTransport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)
    func (t *TLSTransport) GetAutoBindPort() int
    func (t *TLSTransport) PacketCh() <-chan *memberlist.Packet
    func (t *TLSTransport) Shutdown() error
    func (t *TLSTransport) StreamCh() <-chan net.Conn
    func (t *TLSTransport) WriteTo(b []byte, addr string) (time.Time, error)
type TLSTransportConfig
    func GetTLSTransportConfig(configPath string) (*TLSTransportConfig, error)

Package files

advertise.go channel.go cluster.go connection_pool.go delegate.go tls_config.go tls_connection.go tls_transport.go

Constants

const (
    DefaultPushPullInterval  = 60 * time.Second
    DefaultGossipInterval    = 200 * time.Millisecond
    DefaultTCPTimeout        = 10 * time.Second
    DefaultProbeTimeout      = 500 * time.Millisecond
    DefaultProbeInterval     = 1 * time.Second
    DefaultReconnectInterval = 10 * time.Second
    DefaultReconnectTimeout  = 6 * time.Hour
    DefaultRefreshInterval   = 15 * time.Second
    MaxGossipPacketSize      = 1400
)

func OversizedMessage

func OversizedMessage(b []byte) bool

OversizedMessage indicates whether or not the byte payload should be sent via TCP.

type Channel

Channel allows clients to send messages for a specific state type that will be broadcasted in a best-effort manner.

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

func NewChannel

func NewChannel(
    key string,
    send func([]byte),
    peers func() []*memberlist.Node,
    sendOversize func(*memberlist.Node, []byte) error,
    logger log.Logger,
    stopc chan struct{},
    reg prometheus.Registerer,
) *Channel

NewChannel creates a new Channel struct, which handles sending normal and oversize messages to peers.

func (*Channel) Broadcast

func (c *Channel) Broadcast(b []byte)

Broadcast enqueues a message for broadcasting.

type ClusterChannel

ClusterChannel supports state broadcasting across peers.

type ClusterChannel interface {
    Broadcast([]byte)
}

type ClusterMember

ClusterMember interface that represents node peers in a cluster

type ClusterMember interface {
    // Name returns the name of the node
    Name() string
    // Address returns the IP address of the node
    Address() string
}

type ClusterPeer

ClusterPeer represents a single Peer in a gossip cluster.

type ClusterPeer interface {
    // Name returns the unique identifier of this peer in the cluster.
    Name() string
    // Status returns a status string representing the peer state.
    Status() string
    // Peers returns the peer nodes in the cluster.
    Peers() []ClusterMember
}

type Member

Member represents a member in the cluster.

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

func (Member) Address

func (m Member) Address() string

Address implements cluster.ClusterMember

func (Member) Name

func (m Member) Name() string

Name implements cluster.ClusterMember

type Peer

Peer is a single peer in a gossip cluster.

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

func Create

func Create(
    l log.Logger,
    reg prometheus.Registerer,
    bindAddr string,
    advertiseAddr string,
    knownPeers []string,
    waitIfEmpty bool,
    pushPullInterval time.Duration,
    gossipInterval time.Duration,
    tcpTimeout time.Duration,
    probeTimeout time.Duration,
    probeInterval time.Duration,
    tlsTransportConfig *TLSTransportConfig,
    allowInsecureAdvertise bool,
) (*Peer, error)

func (*Peer) AddState

func (p *Peer) AddState(key string, s State, reg prometheus.Registerer) ClusterChannel

AddState adds a new state that will be gossiped. It returns a channel to which broadcast messages for the state can be sent.

func (*Peer) ClusterSize

func (p *Peer) ClusterSize() int

ClusterSize returns the current number of alive members in the cluster.

func (*Peer) Info

func (p *Peer) Info() map[string]interface{}

Info returns a JSON-serializable dump of cluster state. Useful for debug.

func (*Peer) Join

func (p *Peer) Join(
    reconnectInterval time.Duration,
    reconnectTimeout time.Duration,
) error

func (*Peer) Leave

func (p *Peer) Leave(timeout time.Duration) error

Leave the cluster, waiting up to timeout.

func (*Peer) Name

func (p *Peer) Name() string

Name returns the unique ID of this peer in the cluster.

func (*Peer) Peers

func (p *Peer) Peers() []ClusterMember

Peers returns the peers in the cluster.

func (*Peer) Position

func (p *Peer) Position() int

Position returns the position of the peer in the cluster.

func (*Peer) Ready

func (p *Peer) Ready() bool

Return true when router has settled.

func (*Peer) Self

func (p *Peer) Self() *memberlist.Node

Self returns the node information about the peer itself.

func (*Peer) Settle

func (p *Peer) Settle(ctx context.Context, interval time.Duration)

Settle waits until the mesh is ready (and sets the appropriate internal state when it is). The idea is that we don't want to start "working" before we get a chance to know most of the alerts and/or silences. Inspired from https://github.com/apache/cassandra/blob/7a40abb6a5108688fb1b10c375bb751cbb782ea4/src/java/org/apache/cassandra/gms/Gossiper.java This is clearly not perfect or strictly correct but should prevent the alertmanager to send notification before it is obviously not ready. This is especially important for those that do not have persistent storage.

func (*Peer) Status

func (p *Peer) Status() string

Return a status string representing the peer state.

func (*Peer) WaitReady

func (p *Peer) WaitReady(ctx context.Context) error

Wait until Settle() has finished.

type PeerStatus

PeerStatus is the state that a peer is in.

type PeerStatus int
const (
    StatusNone PeerStatus = iota
    StatusAlive
    StatusFailed
)

func (PeerStatus) String

func (s PeerStatus) String() string

type State

State is a piece of state that can be serialized and merged with other serialized state.

type State interface {
    // MarshalBinary serializes the underlying state.
    MarshalBinary() ([]byte, error)

    // Merge merges serialized state into the underlying state.
    Merge(b []byte) error
}

type TLSTransport

TLSTransport is a Transport implementation that uses TLS over TCP for both packet and stream operations.

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

func NewTLSTransport

func NewTLSTransport(
    ctx context.Context,
    logger log.Logger,
    reg prometheus.Registerer,
    bindAddr string,
    bindPort int,
    cfg *TLSTransportConfig,
) (*TLSTransport, error)

NewTLSTransport returns a TLS transport with the given configuration. On successful initialization, a tls listener will be created and listening. A valid bindAddr is required. If bindPort == 0, the system will assign a free port automatically.

func (*TLSTransport) DialTimeout

func (t *TLSTransport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialTimeout is used to create a connection that allows memberlist to perform two-way communications with a peer.

func (*TLSTransport) FinalAdvertiseAddr

func (t *TLSTransport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)

FinalAdvertiseAddr is given the user's configured values (which might be empty) and returns the desired IP and port to advertise to the rest of the cluster.

func (*TLSTransport) GetAutoBindPort

func (t *TLSTransport) GetAutoBindPort() int

GetAutoBindPort returns the bind port that was automatically given by the system if a bindPort of 0 was specified during instantiation.

func (*TLSTransport) PacketCh

func (t *TLSTransport) PacketCh() <-chan *memberlist.Packet

PacketCh returns a channel that can be read to receive incoming packets from other peers.

func (*TLSTransport) Shutdown

func (t *TLSTransport) Shutdown() error

Shutdown is called when memberlist is shutting down; this gives the TLS Transport a chance to clean up the listener and other goroutines.

func (*TLSTransport) StreamCh

func (t *TLSTransport) StreamCh() <-chan net.Conn

StreamCh returns a channel that can be read to handle incoming stream connections from other peers.

func (*TLSTransport) WriteTo

func (t *TLSTransport) WriteTo(b []byte, addr string) (time.Time, error)

WriteTo is a packet-oriented interface that borrows a connection from the pool, and writes to it. It also returns a timestamp of when the packet was written.

type TLSTransportConfig

type TLSTransportConfig struct {
    TLSServerConfig *web.TLSConfig    `yaml:"tls_server_config"`
    TLSClientConfig *config.TLSConfig `yaml:"tls_client_config"`
}

func GetTLSTransportConfig

func GetTLSTransportConfig(configPath string) (*TLSTransportConfig, error)

Subdirectories

Name Synopsis
..
clusterpb