poller

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package poller contains the poller/agent side connectivity and coordination logic.

Index

Constants

View Source
const (
	ActionTypeUnknown = iota
	ActionTypeStart
	ActionTypeRestart
	ActionTypeContinue
)

Variables

View Source
var (
	// ReconnectTimeout sets up 25 second timeout for reconnection
	ReconnectTimeout = 25 * time.Second
	// ErrInvalidConnectionStream used when conneciton stream is not properly initialized
	ErrInvalidConnectionStream = errors.New("ConnectionStream has not been properly set up.  Re-initialize")
	// ErrNoConnections used when no connections were set up in the stream
	ErrNoConnections = errors.New("No connections")
	// ErrUndefinedContext used when passed in context in Connect is undefined
	ErrUndefinedContext = errors.New("Context is undefined")
	// ErrCheckEmpty used when a check is nil or empty
	ErrCheckEmpty = errors.New("Check is empty")
	// CheckSpreadInMilliseconds sets up jitter time so as not
	// to send all requests at the same time
	CheckSpreadInMilliseconds = 30000
)

Functions

func Run

func Run(configFilePath string, insecure bool)

Types

type ActionType

type ActionType int

ActionType provides a non-protocol enumeration of valid check preparation actions

type ActionableCheck

type ActionableCheck struct {
	check.CheckIn

	Action ActionType
	// Populated indicates if the check.CheckIn has been fully populated; however,
	// this is not applicable if Action is protocol.PrepareActionContinue.
	Populated bool
}

ActionableCheck enriches a check.CheckIn with an action indicator. It is expected that during preparation these may have only abbreviated fields populated in check.CheckIn.

type CheckExecutor

type CheckExecutor interface {
	Execute(ch check.Check)
}

CheckExecutor facilitates running a check and consuming the CheckResultSet

type CheckScheduler

type CheckScheduler interface {
	Schedule(ch check.Check)
}

CheckScheduler arranges the periodic invocation of the given Check

type ChecksPreparation

type ChecksPreparation struct {
	ZoneId  string
	Version int

	// Actions is a map of checkId->ActionableCheck
	Actions map[string]ActionableCheck
}

func NewChecksPreparation

func NewChecksPreparation(zoneId string, version int, manifest []protocol.PollerPrepareManifest) (*ChecksPreparation, error)

NewChecksPreparation initiates a new checks preparation session. Returns the new ChecksPreparation if successful or an error if an unsupported action type was encountered.

func (*ChecksPreparation) AddDefinitions

func (cp *ChecksPreparation) AddDefinitions(block []*check.CheckIn)

func (*ChecksPreparation) GetActionableChecks

func (cp *ChecksPreparation) GetActionableChecks() (actionableChecks []ActionableCheck)

func (*ChecksPreparation) GetPreparationVersion

func (cp *ChecksPreparation) GetPreparationVersion() int

func (*ChecksPreparation) GetPreparationZoneId

func (cp *ChecksPreparation) GetPreparationZoneId() string

func (*ChecksPreparation) IsNewer

func (cp *ChecksPreparation) IsNewer(version int) bool

func (*ChecksPreparation) IsOlder

func (cp *ChecksPreparation) IsOlder(version int) bool

func (*ChecksPreparation) Validate

func (cp *ChecksPreparation) Validate(version int) error

func (*ChecksPreparation) VersionApplies

func (cp *ChecksPreparation) VersionApplies(version int) bool

type ChecksPrepared

type ChecksPrepared interface {
	GetActionableChecks() (actionableChecks []ActionableCheck)
}

ChecksPrepared conveys ActionableCheck instances that are fully populated and ready to be reconciled

type ChecksPreparing

type ChecksPreparing interface {
	GetActionableChecks() (actionableChecks []ActionableCheck)
}

ChecksPreparing conveys ActionableCheck instances are are ready to be validated.

type ChecksReconciler

type ChecksReconciler interface {
	// ReconcileChecks acts upon the given ChecksPrepared during a commit-phase.
	// The bulk of the processing is likely handled in an alternate go routine, so errors in the given
	// ChecksPrepared are handled but not reportable back to this caller. Use ValidateChecks prior to calling
	// this to pre-compute those errors.
	ReconcileChecks(cp ChecksPrepared)

	// Validate goes through the motions of ReconcileChecks in order to pre-validate consistency.
	// Unlike ReconcileChecks, this function should only require the manifest level of detail in the ActionableCheck
	// instances.
	// Returns an error upon finding the first entry that is not valid.
	ValidateChecks(cp ChecksPreparing) error
}

ChecksReconciler is implemented by receivers that can either reconcile prepared checks during a commit or pre-validate the checks prior to committing.

type CompletionFrame

type CompletionFrame struct {
	ID     uint64
	Method string
}

CompletionFrame is a pointer to a request with a specified method used for the request

type Connection

type Connection interface {
	ConnectionHealthProvider

	GetSession() Session
	SetReadDeadline(deadline time.Time)
	SetWriteDeadline(deadline time.Time)
	Connect(ctx context.Context, config *config.Config, tlsConfig *tls.Config) error
	Close()
	Wait()
	GetFarendWriter() io.Writer
	GetFarendReader() io.Reader
	GetGUID() string
}

Connection interface wraps the methods required to manage a single connection.

func NewConnection

func NewConnection(address string, guid string, checksReconciler ChecksReconciler) Connection

NewConnection instantiates a new EleConnection It sets up the address, unique guid, and connection timeout for this conneciton

type ConnectionFactory

type ConnectionFactory func(address string, guid string, checksReconciler ChecksReconciler) Connection

type ConnectionHealthProvider

type ConnectionHealthProvider interface {
	GetClockOffset() int64
	GetLatency() int64
}

type ConnectionStream

type ConnectionStream interface {
	RegisterConnection(qry string, conn Connection) error
	Stop()
	StopNotify() chan struct{}
	SendMetrics(crs *check.ResultSet) error
	Connect()
	WaitCh() <-chan struct{}
}

ConnectionStream interface wraps the necessary information to register, connect, and send data in connections. It is the main factory for connection handling

func NewConnectionStream

func NewConnectionStream(config *config.Config, rootCAs *x509.CertPool) ConnectionStream

NewConnectionStream instantiates a new EleConnectionStream It sets up the contexts and the starts the schedulers based on configured private zones

func NewCustomConnectionStream

func NewCustomConnectionStream(config *config.Config, rootCAs *x509.CertPool, connectionFactory ConnectionFactory) ConnectionStream

NewCustomConnectionStream is a variant of NewConnectionStream that allows providing a customized ConnectionFactory

type ConnectionsByHost

type ConnectionsByHost map[string]Connection

func (ConnectionsByHost) ChooseBest

func (conns ConnectionsByHost) ChooseBest() Connection

ChooseBest selects the best of its connections for posting metrics, etc. Returns nil if no connections were present.

type EleConnection

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

EleConnection implements Connection See Connection interface for more information

func (*EleConnection) Close

func (conn *EleConnection) Close()

Close closes the session

func (*EleConnection) Connect

func (conn *EleConnection) Connect(ctx context.Context, config *config.Config, tlsConfig *tls.Config) error

Connect sets up a tcp connection with connection defined address and passed in tlsConfig If context is not set, ErrUndefinedContext is returned The end result of this function is a usable connection ready to send data.

func (*EleConnection) GetClockOffset

func (conn *EleConnection) GetClockOffset() int64

func (*EleConnection) GetFarendReader

func (conn *EleConnection) GetFarendReader() io.Reader

GetFarendReader gets a reader to consume from the endpoint server

func (*EleConnection) GetFarendWriter

func (conn *EleConnection) GetFarendWriter() io.Writer

GetFarendWriter gets a writer directed towards the endpoint server

func (*EleConnection) GetGUID

func (conn *EleConnection) GetGUID() string

GetGUID retrieves connection's guid

func (*EleConnection) GetLatency

func (conn *EleConnection) GetLatency() int64

func (*EleConnection) GetSession

func (conn *EleConnection) GetSession() Session

GetSession retrieves connection's session

func (*EleConnection) SetReadDeadline

func (conn *EleConnection) SetReadDeadline(deadline time.Time)

SetReadDeadline sets up the read deadline for a socket. read deadline - time spent reading response for future calls

func (*EleConnection) SetWriteDeadline

func (conn *EleConnection) SetWriteDeadline(deadline time.Time)

SetWriteDeadline sets up the write deadline for a socket. write deadline - time spent writing request to socket for future calls

func (*EleConnection) Wait

func (conn *EleConnection) Wait()

Wait sets the connection session to wait for a new request

type EleConnectionStream

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

EleConnectionStream implements ConnectionStream See ConnectionStream for more information

func (*EleConnectionStream) Connect

func (cs *EleConnectionStream) Connect()

Connect connects to configured endpoints. There are 2 ways to connect: 1. You can utilize SRV records defined in the configuration to dynamically find endpoints 2. You can explicitly specify endpoint addresses and connect to them directly DEFAULT: Using SRV records

func (*EleConnectionStream) ReconcileChecks

func (cs *EleConnectionStream) ReconcileChecks(cp ChecksPrepared)

ReconcileChecks routes the ChecksPreparation to its schedulers.

func (*EleConnectionStream) RegisterConnection

func (cs *EleConnectionStream) RegisterConnection(qry string, conn Connection) error

RegisterConnection sets up a new connection and adds it to connection stream If no connection list has been initialized, this method will return an InvalidConnectionStreamError. If that's the case, please instantiate a new connection stream via NewConnectionStream function

func (*EleConnectionStream) SendMetrics

func (cs *EleConnectionStream) SendMetrics(crs *check.ResultSet) error

SendMetrics sends a CheckResultSet via the first connection it can retrieve in the connection list

func (*EleConnectionStream) Stop

func (cs *EleConnectionStream) Stop()

Stop explicitly stops all connections in the stream and notifies the channel

func (*EleConnectionStream) StopNotify

func (cs *EleConnectionStream) StopNotify() chan struct{}

StopNotify returns a stop channel

func (*EleConnectionStream) ValidateChecks

func (cs *EleConnectionStream) ValidateChecks(cp ChecksPreparing) error

func (*EleConnectionStream) WaitCh

func (cs *EleConnectionStream) WaitCh() <-chan struct{}

WaitCh provides a channel for waiting on connection establishment

type EleScheduler

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

EleScheduler implements Scheduler interface. See Scheduler for more information.

func (*EleScheduler) Close

func (s *EleScheduler) Close()

Close cancels the context and closes the connection

func (*EleScheduler) Execute

func (s *EleScheduler) Execute(ch check.Check)

Execute perform the default CheckExecutor behavior by running the check and sending its results via SendMetrics.

func (*EleScheduler) GetContext

func (s *EleScheduler) GetContext() (ctx context.Context, cancel context.CancelFunc)

GetContext retrieves cancelable context

func (*EleScheduler) GetScheduledChecks

func (s *EleScheduler) GetScheduledChecks() []check.Check

func (*EleScheduler) GetZoneID

func (s *EleScheduler) GetZoneID() string

GetZoneID retrieves zone id

func (*EleScheduler) ReconcileChecks

func (s *EleScheduler) ReconcileChecks(cp ChecksPrepared)

func (*EleScheduler) Schedule

func (s *EleScheduler) Schedule(ch check.Check)

Schedule is the default implementation of CheckScheduler that kicks off a go routine to run a check's timer.

func (*EleScheduler) SendMetrics

func (s *EleScheduler) SendMetrics(crs *check.ResultSet)

SendMetrics sends metrics passed in crs parameter via the stream

func (*EleScheduler) ValidateChecks

func (s *EleScheduler) ValidateChecks(cp ChecksPreparing) error

type EleSession

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

EleSession implements Session interface See Session for more information

func (*EleSession) Auth

func (s *EleSession) Auth()

Auth sends a handshake request with token, agent id, name, and process version

func (*EleSession) Close

func (s *EleSession) Close()

Close shuts down session's context and closes session

func (*EleSession) GetClockOffset

func (s *EleSession) GetClockOffset() int64

func (*EleSession) GetError

func (s *EleSession) GetError() error

func (*EleSession) GetLatency

func (s *EleSession) GetLatency() int64

func (*EleSession) Respond

func (s *EleSession) Respond(msg protocol.Frame)

Respond is equivalent to Send but improves readability by emphasizing this is the poller responding to a request from the server.

func (*EleSession) Send

func (s *EleSession) Send(msg protocol.Frame)

Send stages a frame for sending after setting the target and source. NOTE: If the message's ID is not initialized an ID will be allocated.

func (*EleSession) String

func (cp *EleSession) String() string

func (*EleSession) Wait

func (s *EleSession) Wait()

Wait waits for the context to complete

type Scheduler

type Scheduler interface {
	ChecksReconciler

	Close()
	SendMetrics(crs *check.ResultSet)
	GetZoneID() string
	GetContext() (ctx context.Context, cancel context.CancelFunc)
	GetScheduledChecks() []check.Check
}

Scheduler interface wraps the methods that schedule metric setup and sending

func NewCustomScheduler

func NewCustomScheduler(zoneID string, stream ConnectionStream, checkScheduler CheckScheduler, checkExecutor CheckExecutor) Scheduler

NewCustomScheduler instantiates a new Scheduler using NewScheduler but allows for more customization. Nil can be passed to either checkScheduler and/or checkExecutor to enable the default behavior.

func NewScheduler

func NewScheduler(zoneID string, stream ConnectionStream) Scheduler

NewScheduler instantiates a new Scheduler with standard scheduling and executor behaviors. It sets up checks, context, and passed in zoneid

type Session

type Session interface {
	ConnectionHealthProvider

	Auth()
	Send(msg protocol.Frame)
	Respond(msg protocol.Frame)
	Close()
	Wait()
	GetError() error
}

Session interface wraps the methods required to manage a session in a connection. It includes authentication, request/ response timeout management, and transferring data

func NewSession

func NewSession(ctx context.Context, connection Connection, checksReconciler ChecksReconciler, config *config.Config) Session

Jump to

Keyboard shortcuts

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