discovery

package
v0.0.0-...-8018142 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MPL-2.0 Imports: 16 Imported by: 16

README

discovery

GoDoc

Documentation

Overview

Package discovery manages the configuration of the Consul clients and the functions used to update/query Consul with service discovery data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	CheckForUpstreamChanges(service, tag, dc string) (bool, bool)
	CheckRegister(check *api.AgentCheckRegistration) error
	UpdateTTL(checkID, output, status string) error
	ServiceDeregister(serviceID string) error
	ServiceRegister(service *api.AgentServiceRegistration) error
}

Backend is an interface which all service discovery backends must implement

type ByServiceID

type ByServiceID []*api.ServiceEntry

ByServiceID implements the Sort interface because Go can't sort without it.

func (ByServiceID) Len

func (se ByServiceID) Len() int

func (ByServiceID) Less

func (se ByServiceID) Less(i, j int) bool

func (ByServiceID) Swap

func (se ByServiceID) Swap(i, j int)

type Consul

type Consul struct {
	api.Client
	// contains filtered or unexported fields
}

Consul wraps the service discovery backend for the Hashicorp Consul client and tracks the state of all watched dependencies.

func NewConsul

func NewConsul(config interface{}) (*Consul, error)

NewConsul creates a new service discovery backend for Consul

func (*Consul) CheckForUpstreamChanges

func (c *Consul) CheckForUpstreamChanges(backendName, backendTag, dc string) (didChange, isHealthy bool)

CheckForUpstreamChanges requests the set of healthy instances of a service from Consul and checks whether there has been a change since the last check.

func (*Consul) CheckRegister

func (c *Consul) CheckRegister(check *api.AgentCheckRegistration) error

CheckRegister wraps the Consul.Agent's CheckRegister method, is used to register a new service with the local agent

func (*Consul) ServiceDeregister

func (c *Consul) ServiceDeregister(serviceID string) error

ServiceDeregister wraps the Consul.Agent's ServiceDeregister method, and is used to deregister a service from the local agent

func (*Consul) ServiceRegister

func (c *Consul) ServiceRegister(service *api.AgentServiceRegistration) error

ServiceRegister wraps the Consul.Agent's ServiceRegister method, is used to register a new service with the local agent

func (*Consul) UpdateTTL

func (c *Consul) UpdateTTL(checkID, output, status string) error

UpdateTTL wraps the Consul.Agent's UpdateTTL method, and is used to set a TTL check to the passing state

type ServiceDefinition

type ServiceDefinition struct {
	ID                             string
	Name                           string
	Port                           int
	TTL                            int
	Tags                           []string
	InitialStatus                  string
	IPAddress                      string
	EnableTagOverride              bool
	DeregisterCriticalServiceAfter string
	Consul                         Backend
	// contains filtered or unexported fields
}

ServiceDefinition is how a job communicates with the Consul service discovery backend.

func (*ServiceDefinition) Deregister

func (service *ServiceDefinition) Deregister()

Deregister removes the service from Consul.

func (*ServiceDefinition) MarkForMaintenance

func (service *ServiceDefinition) MarkForMaintenance()

MarkForMaintenance removes the service from Consul.

func (*ServiceDefinition) RegisterWithInitialStatus

func (service *ServiceDefinition) RegisterWithInitialStatus()

RegisterWithInitialStatus registers the service with its configured initial status.

func (*ServiceDefinition) SendHeartbeat

func (service *ServiceDefinition) SendHeartbeat() error

SendHeartbeat writes a TTL check status=ok to the Consul store.

type TestServer

type TestServer struct {
	HTTPAddr string
	// contains filtered or unexported fields
}

TestServer represents a Consul server we can run our tests against. Depends on a local `consul` binary installed into our environ's PATH.

func NewTestServer

func NewTestServer(httpPort int) (*TestServer, error)

NewTestServer constructs a new TestServer by including the httpPort as well.

func (*TestServer) Stop

func (s *TestServer) Stop() error

Stop stops a TestServer

func (*TestServer) WaitForAPI

func (s *TestServer) WaitForAPI() error

WaitForAPI waits for only the agent HTTP endpoint to start responding. This is an indication that the agent has started, but will likely return before a leader is elected.

Jump to

Keyboard shortcuts

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