consul

package
v0.5.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2016 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package consul is used by Nomad to register all services both static services and dynamic via allocations.

Consul Service IDs have the following format: ${nomadServicePrefix}-${groupName}-${serviceKey} groupName takes on one of the following values: - server - client - executor-${alloc-id}-${task-name}

serviceKey should be generated by service registrators. If the serviceKey is being generated by the executor for a Nomad Task.Services the following helper should be used:

NOTE: Executor should interpolate the service prior to calling
func GenerateTaskServiceKey(service *structs.Service) string

The Nomad Client reaps services registered from dead allocations that were not properly cleaned up by the executor (this is not the expected case).

TODO fix this comment The Consul ServiceIDs generated by the executor will contain the allocation ID. Thus the client can generate the list of Consul ServiceIDs to keep by calling the following method on all running allocations the client is aware of: func GenerateExecutorServiceKeyPrefixFromAlloc(allocID string) string

Index

Constants

View Source
const (

	// DefaultQueryWaitDuration is the max duration the Consul Agent will
	// spend waiting for a response from a Consul Query.
	DefaultQueryWaitDuration = 2 * time.Second

	// ServiceTagHTTP is the tag assigned to HTTP services
	ServiceTagHTTP = "http"

	// ServiceTagRPC is the tag assigned to RPC services
	ServiceTagRPC = "rpc"

	// ServiceTagSerf is the tag assigned to Serf services
	ServiceTagSerf = "serf"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check interface {
	Run() *cstructs.CheckResult
	ID() string
	Interval() time.Duration
	Timeout() time.Duration
}

Check is an interface which check providers can implement for Nomad to run

type CheckRunner

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

CheckRunner runs a given check in a specific interval and update a corresponding Consul TTL check

func NewCheckRunner

func NewCheckRunner(check Check, runCheck func(Check), logger *log.Logger) *CheckRunner

NewCheckRunner configures and returns a CheckRunner

func (*CheckRunner) Start

func (r *CheckRunner) Start()

Start is used to start the check. The check runs until stop is called

func (*CheckRunner) Started added in v0.5.0

func (r *CheckRunner) Started() bool

Started returns if the check runner has started running

func (*CheckRunner) Stop

func (r *CheckRunner) Stop()

Stop is used to stop the check.

type ServiceDomain

type ServiceDomain string

ServiceDomain is the domain of services registered by Nomad

const (
	ClientDomain ServiceDomain = "client"
	ServerDomain ServiceDomain = "server"
)

func NewExecutorDomain

func NewExecutorDomain(allocID, task string) ServiceDomain

NewExecutorDomain returns a domain specific to the alloc ID and task

type ServiceKey

type ServiceKey string

ServiceKey is the generated service key that is used to build the Consul ServiceID

func GenerateServiceKey

func GenerateServiceKey(service *structs.Service) ServiceKey

GenerateServiceKey should be called to generate a serviceKey based on the Service.

type Syncer

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

Syncer allows syncing of services and checks with Consul

func NewSyncer

func NewSyncer(consulConfig *config.ConsulConfig, shutdownCh chan struct{}, logger *log.Logger) (*Syncer, error)

NewSyncer returns a new consul.Syncer

func (*Syncer) AddPeriodicHandler

func (c *Syncer) AddPeriodicHandler(name string, fn types.PeriodicCallback) bool

AddPeriodicHandler adds a uniquely named callback. Returns true if successful, false if a handler with the same name already exists.

func (*Syncer) ConsulClient

func (c *Syncer) ConsulClient() *consul.Client

ConsulClient returns the Consul client used by the Syncer.

func (*Syncer) NumHandlers

func (c *Syncer) NumHandlers() int

NumHandlers returns the number of callbacks registered with the syncer

func (*Syncer) ReapUnmatched

func (c *Syncer) ReapUnmatched(domains []ServiceDomain) error

ReapUnmatched prunes all services that do not exist in the passed domains

func (*Syncer) RemovePeriodicHandler

func (c *Syncer) RemovePeriodicHandler(name string)

RemovePeriodicHandler removes a handler with a given name.

func (*Syncer) Run

func (c *Syncer) Run()

Run triggers periodic syncing of services and checks with Consul. This is a long lived go-routine which is stopped during shutdown.

func (*Syncer) RunHandlers

func (c *Syncer) RunHandlers() error

RunHandlers executes each handler (randomly)

func (*Syncer) SetAddrFinder

func (c *Syncer) SetAddrFinder(addrFinder func(string) (string, int)) *Syncer

SetAddrFinder sets a function to find the host and port for a Service given its port label

func (*Syncer) SetDelegatedChecks

func (c *Syncer) SetDelegatedChecks(delegateChecks map[string]struct{}, createDelegatedCheckFn func(*structs.ServiceCheck, string) (Check, error)) *Syncer

SetDelegatedChecks sets the checks that nomad is going to run and report the result back to consul

func (*Syncer) SetServices

func (c *Syncer) SetServices(domain ServiceDomain, services map[ServiceKey]*structs.Service) error

SetServices stores the map of Nomad Services to the provided service domain name.

func (*Syncer) Shutdown

func (c *Syncer) Shutdown() error

Shutdown de-registers the services and checks and shuts down periodic syncing

func (*Syncer) SyncNow

func (c *Syncer) SyncNow()

SyncNow expires the current timer forcing the list of periodic callbacks to be synced immediately.

func (*Syncer) SyncServices

func (c *Syncer) SyncServices() error

SyncServices sync the services with the Consul Agent

Jump to

Keyboard shortcuts

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