monitor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RetryCampaignInterval        = 5 * time.Second
	DefaultEtcdSessionTTLSeconds = 5
)
View Source
const (
	LeaderWatcherInterval = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ElectLeaderStatus

type ElectLeaderStatus struct {
	NodeID string
	Err    error
}

type IMonitor

type IMonitor interface {
	RunElectLeader(ctx context.Context, ch chan *ElectLeaderStatus, path string)
}

type LeaderInfo

type LeaderInfo struct {
	NodeID string
}

type Monitor

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

func New

func New(etcdClient *clientv3.Client, nodeID string) (*Monitor, error)

func (*Monitor) GetLeader

func (m *Monitor) GetLeader(ctx context.Context, election *concurrency.Election) (*LeaderInfo, error)

GetLeader fetches the value that is set by the leader.

func (*Monitor) RunElectLeader

func (m *Monitor) RunElectLeader(ctx context.Context, ch chan *ElectLeaderStatus, path string) error

RunElectLeader is the main entrypoint for launching a monitoring instance. It will elect and launch a leader + continue monitoring for leadership changes.

Flow:

1. In a loop, Campaign() to become leader 2. Campaign() blocks until leader is acquired 3. When leader is acquired:

  • Launch runLeader
  • Launch runLeaderWatcher
  1. runLeaderWatcher verifies that we are still leader AND monitors shutdown ctx. If either has changed/triggered: it will shutdown RunLeader and itself.
  2. runLeader has watches for incoming alerts/etc.

Etcd layout

TBD

Jump to

Keyboard shortcuts

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