discovery

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CACHE_DRAIN_INTERVAL = 10 * time.Minute // Drain the cache every 10 mins
)
View Source
const (
	SLEEP_INTERVAL = 1 * time.Second
)

Variables

This section is empty.

Functions

func RandomHex

func RandomHex(count int) ([]byte, error)

Return a defined number of random bytes as a slice

Types

type Discoverer

type Discoverer interface {
	// Returns a slice of services that we discovered
	Services() []service.Service
	// Get the health check and health check args for a service
	HealthCheck(svc *service.Service) (string, string)
	// A non-blocking method that runs a discovery loop.
	// The controlling process kicks it off to start discovery.
	Run(director.Looper)
}

A Discoverer is responsible for findind services that we care about. It must have a method to return the list of services, and a Run() method that will be invoked when the discovery mechanism(s) is/are started.

type DockerClient

type DockerClient interface {
	InspectContainer(id string) (*docker.Container, error)
	ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)
	AddEventListener(listener chan<- *docker.APIEvents) error
	RemoveEventListener(listener chan *docker.APIEvents) error
	Ping() error
}

type DockerDiscovery

type DockerDiscovery struct {
	ClientProvider func() (DockerClient, error) // Return the client we'll use to connect

	sync.RWMutex // Reader/Writer lock
	// contains filtered or unexported fields
}

func NewDockerDiscovery

func NewDockerDiscovery(endpoint string, svcNamer ServiceNamer) *DockerDiscovery

func (*DockerDiscovery) HealthCheck

func (d *DockerDiscovery) HealthCheck(svc *service.Service) (string, string)

HealthCheck looks up a health check using Docker container labels to pass the type of check and the arguments to pass to it.

func (*DockerDiscovery) Run

func (d *DockerDiscovery) Run(looper director.Looper)

The main loop, poll for containers continuously.

func (*DockerDiscovery) Services

func (d *DockerDiscovery) Services() []service.Service

type DockerLabelNamer

type DockerLabelNamer struct {
	Label string
}

A ServiceNamer that uses a name provided in a Docker label as the name for the service.

func (*DockerLabelNamer) ServiceName

func (d *DockerLabelNamer) ServiceName(container *docker.APIContainers) string

Return the value of the configured Docker label, or default to the image name.

type MultiDiscovery

type MultiDiscovery struct {
	Discoverers []Discoverer
}

A MultiDiscovery is a wrapper around zero or more Discoverers. It allows the use of potentially multiple Discoverers in place of one.

func (*MultiDiscovery) HealthCheck

func (d *MultiDiscovery) HealthCheck(svc *service.Service) (string, string)

Get the health check and health check args for a service

func (*MultiDiscovery) Run

func (d *MultiDiscovery) Run(looper director.Looper)

Kicks off the Run() method for all the discoverers.

func (*MultiDiscovery) Services

func (d *MultiDiscovery) Services() []service.Service

Aggregates all the service slices from the discoverers

type RegexpNamer

type RegexpNamer struct {
	ServiceNameMatch string
	// contains filtered or unexported fields
}

A ServiceNamer that uses a regex to match against the service name or else uses the image as the service name.

func (*RegexpNamer) ServiceName

func (r *RegexpNamer) ServiceName(container *docker.APIContainers) string

Return a properly regex-matched name for the service, or failing that, the Image ID which we use to stand in for the name of the service.

type ServiceNamer

type ServiceNamer interface {
	ServiceName(*docker.APIContainers) string
}

type StaticCheck

type StaticCheck struct {
	Type string
	Args string
}

type StaticDiscovery

type StaticDiscovery struct {
	Targets    []*Target
	ConfigFile string
	Hostname   string
}

func NewStaticDiscovery

func NewStaticDiscovery(filename string) *StaticDiscovery

func (*StaticDiscovery) HealthCheck

func (d *StaticDiscovery) HealthCheck(svc *service.Service) (string, string)

func (*StaticDiscovery) ParseConfig

func (d *StaticDiscovery) ParseConfig(filename string) ([]*Target, error)

Parses a JSON config file containing an array of Targets. These are then augmented with a random hex ID and stamped with the current UTC time as the creation time. The same hex ID is applied to the Check and the Service to make sure that they are matched by the healthy package later on.

func (*StaticDiscovery) Run

func (d *StaticDiscovery) Run(looper director.Looper)

Causes the configuration to be parsed and loaded. There is no background processing needed on an ongoing basis.

func (*StaticDiscovery) Services

func (d *StaticDiscovery) Services() []service.Service

Returns the list of services derived from the targets that were parsed out of the config file.

type Target

type Target struct {
	Service service.Service
	Check   StaticCheck
}

Jump to

Keyboard shortcuts

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