health

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: MIT, MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const SysMemberPrefix = "_nats.cluster.members."

SysMemberPrefix creates a namespace for system cluster membership communication. This prefix aims to avoid collisions with user-level topics. Only system processes / internal clients should write to these topics, but everyone is welcome to listen on them.

note: `_nats` is for now, can easily changed to be `_SYS` later once we're sure everything is working.

Variables

This section is empty.

Functions

func AgentLocLessThan

func AgentLocLessThan(i, j *AgentLoc) bool

AgentLocLessThan returns true iff i < j, in terms of leader preference where lowest is more electable/preferred as leader.

Types

type Agent

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

Agent implements the InternalClient interface. It provides health status checks and leader election from among the candidate hnatsd instances in a cluster.

func NewAgent

func NewAgent(opts *server.Options) *Agent

NewAgent makes a new Agent.

func (*Agent) Name

func (h *Agent) Name() string

Name should identify the internal client for logging.

func (*Agent) Start

func (h *Agent) Start(
	info server.Info,
	opts server.Options,
	logger server.Logger,

) (net.Conn, error)

Start makes an internal entirely in-process client that monitors cluster health and manages group membership functions.

func (*Agent) Stop

func (h *Agent) Stop()

Stop halts the background goroutine.

type AgentLoc

type AgentLoc struct {
	ID             string `json:"serverId"`
	NatsHost       string `json:"natsHost"`
	NatsClientPort int    `json:"natsClientPort"`

	Grpc ExtInt `json:"grpc"`

	// LeaseExpires is zero for any
	// non-leader. For the leader,
	// LeaseExpires tells you when
	// the leaders lease expires.
	LeaseExpires time.Time `json:"leaseExpires"`

	// lower rank is leader until lease
	// expires. Ties are broken by ID.
	// Rank should be assignable on the
	// gnatsd command line with -rank to
	// let the operator prioritize
	// leadership for certain hosts.
	Rank int `json:"rank"`

	// Pid or process id is the only
	// way to tell apart two processes
	// sometimes, if they share the
	// same nats server.
	//
	// Pid is one difference between
	// a nats.ServerLoc and a health.AgentLoc.
	//
	Pid int `json:"pid"`
}

AgentLoc conveys to interested parties the Id and location of one gnatsd server in the cluster.

func (AgentLoc) Less

func (a AgentLoc) Less(than btree.Item) bool

Less is how the agents are sorted. The Less method is expected by the btree. See the AgentLocLessThan for standalone implementation.

func (*AgentLoc) String

func (s *AgentLoc) String() string

type ExtInt

type ExtInt struct {
	External HostPort `json:"externalHostPort"`
	Internal HostPort `json:"internalHostPort"`
}

ExtInt conveys the external/internal port pairs. Sshd secures external ports, and forwards authenticated connections to localhost:internal port.

type HostPort

type HostPort struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

type Icc

type Icc struct {
	*net.TCPConn
}

Icc allows the server to detect a net.Conn as an internal client connection by checking if it implements the LocalInternalClient interface.

func NewInternalClientPair

func NewInternalClientPair() (cli, srv *Icc, err error)

NewInternalClientPair constructs a client/server pair that wrap tcp endpoints in Icc to let the server recognized them as internal.

func (*Icc) IsInternal

func (c *Icc) IsInternal()

IsInternal satisfy LocalInternalClient interface

type Membership

type Membership struct {
	Cfg MembershipCfg
	// contains filtered or unexported fields
}

Membership tracks the nats server cluster membership, issuing health checks and choosing a leader.

func NewMembership

func NewMembership(cfg *MembershipCfg) *Membership

NewMembership creates a new Membership.

func (*Membership) Start

func (m *Membership) Start() error

Start launches the Membership goroutine.

func (*Membership) Stop

func (m *Membership) Stop()

Stop blocks until the Membership goroutine acknowledges the shutdown request.

type MembershipCfg

type MembershipCfg struct {

	// max we allow for clocks to be out of sync.
	// default to 1 second if not set.
	MaxClockSkew time.Duration

	// how often we heartbeat. defaults to 100msec
	// if not set.
	BeatDur time.Duration

	// NatsURL example "nats://127.0.0.1:4222"
	NatsURL string

	// defaults to "_nats.cluster.members."
	SysMemberPrefix string

	// LeaseTime is the minimum time the
	// leader is elected for. Defaults to 10 sec.
	LeaseTime time.Duration

	// provide a default until the server gives us rank
	MyRank int

	// optional, if provided we will use this connection on
	// the client side.
	CliConn net.Conn

	// where we log stuff.
	Log server.Logger
	// contains filtered or unexported fields
}

MembershipCfg configures the Membership service, which is the health-agent implementation.

func (*MembershipCfg) Dial

func (cfg *MembershipCfg) Dial(network, address string) (net.Conn, error)

Dial allows us to replace a client's dial of an external TCP socket with an already established internal TCP connection.

func (*MembershipCfg) SetDefaults

func (cfg *MembershipCfg) SetDefaults()

SetDefaults fills in default values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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