local

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckState

type CheckState struct {
	// Check is the local copy of the health check record.
	Check *structs.HealthCheck

	// Token is the ACL record to update or delete the health check
	// record on the server.
	Token string

	// CriticalTime is the last time the health check status went
	// from non-critical to critical. When the health check is not
	// in critical state the value is the zero value.
	CriticalTime time.Time

	// DeferCheck is used to delay the sync of a health check when
	// only the output has changed. This rate limits changes which
	// do not affect the state of the node and/or service.
	DeferCheck *time.Timer

	// InSync contains whether the local state of the health check
	// record is in sync with the remote state on the server.
	InSync bool

	// Deleted is true when the health check record has been marked as
	// deleted but has not been removed on the server yet.
	Deleted bool
}

CheckState describes the state of a health check record.

func (*CheckState) Clone

func (c *CheckState) Clone() *CheckState

Clone returns a shallow copy of the object. The check record and the defer timer still point to the original values and must not be modified.

func (*CheckState) Critical

func (c *CheckState) Critical() bool

Critical returns true when the health check is in critical state.

func (*CheckState) CriticalFor

func (c *CheckState) CriticalFor() time.Duration

CriticalFor returns the amount of time the service has been in critical state. Its value is undefined when the service is not in critical state.

type Config

type Config struct {
	AdvertiseAddr       string
	CheckUpdateInterval time.Duration
	Datacenter          string
	DiscardCheckOutput  bool
	NodeID              types.NodeID
	NodeName            string
	TaggedAddresses     map[string]string
	ProxyBindMinPort    int
	ProxyBindMaxPort    int
}

Config is the configuration for the State.

type ManagedProxy added in v1.2.0

type ManagedProxy struct {
	Proxy *structs.ConnectManagedProxy

	// ProxyToken is a special local-only security token that grants the bearer
	// access to the proxy's config as well as allowing it to request certificates
	// on behalf of the target service. Certain connect endpoints will validate
	// against this token and if it matches will then use the target service's
	// registration token to actually authenticate the upstream RPC on behalf of
	// the service. This token is passed securely to the proxy process via ENV
	// vars and should never be exposed any other way. Unmanaged proxies will
	// never see this and need to use service-scoped ACL tokens distributed
	// externally. It is persisted in the local state to allow authenticating
	// running proxies after the agent restarts.
	//
	// TODO(banks): In theory we only need to persist this at all to _validate_
	// which means we could keep only a hash in memory and on disk and only pass
	// the actual token to the process on startup. That would require a bit of
	// refactoring though to have the required interaction with the proxy manager.
	ProxyToken string

	// WatchCh is a close-only chan that is closed when the proxy is removed or
	// updated.
	WatchCh chan struct{}
}

ManagedProxy represents the local state for a registered proxy instance.

type ServiceState

type ServiceState struct {
	// Service is the local copy of the service record.
	Service *structs.NodeService

	// Token is the ACL to update or delete the service record on the
	// server.
	Token string

	// InSync contains whether the local state of the service record
	// is in sync with the remote state on the server.
	InSync bool

	// Deleted is true when the service record has been marked as deleted
	// but has not been removed on the server yet.
	Deleted bool
}

ServiceState describes the state of a service record.

func (*ServiceState) Clone

func (s *ServiceState) Clone() *ServiceState

Clone returns a shallow copy of the object. The service record still points to the original service record and must not be modified.

type State

type State struct {
	sync.RWMutex

	// Delegate the RPC interface to the consul server or agent.
	//
	// It is set after both the state and the consul server/agent have
	// been created.
	Delegate rpc

	// TriggerSyncChanges is used to notify the state syncer that a
	// partial sync should be performed.
	//
	// It is set after both the state and the state syncer have been
	// created.
	TriggerSyncChanges func()
	// contains filtered or unexported fields
}

State is used to represent the node's services, and checks. We use it to perform anti-entropy with the catalog representation

func NewState

func NewState(c Config, lg *log.Logger, tokens *token.Store) *State

NewState creates a new local state for the agent.

func TestState added in v1.2.0

func TestState(t testing.T) *State

TestState returns a configured *State for testing.

func (*State) AddCheck

func (l *State) AddCheck(check *structs.HealthCheck, token string) error

AddCheck is used to add a health check to the local state. This entry is persistent and the agent will make a best effort to ensure it is registered

func (*State) AddProxy added in v1.2.0

func (l *State) AddProxy(proxy *structs.ConnectManagedProxy, token,
	restoredProxyToken string) (*ManagedProxy, error)

AddProxy is used to add a connect proxy entry to the local state. This assumes the proxy's NodeService is already registered via Agent.AddService (since that has to do other book keeping). The token passed here is the ACL token the service used to register itself so must have write on service record. AddProxy returns the newly added proxy and an error.

The restoredProxyToken argument should only be used when restoring proxy definitions from disk; new proxies must leave it blank to get a new token assigned. We need to restore from disk to enable to continue authenticating running proxies that already had that credential injected.

func (*State) AddService

func (l *State) AddService(service *structs.NodeService, token string) error

AddService is used to add a service entry to the local state. This entry is persistent and the agent will make a best effort to ensure it is registered

func (*State) Check

func (l *State) Check(id types.CheckID) *structs.HealthCheck

Check returns the locally registered check that the agent is aware of and are being kept in sync with the server

func (*State) CheckState

func (l *State) CheckState(id types.CheckID) *CheckState

CheckState returns a shallow copy of the current health check state record. The health check record and the deferred check still point to the original values and must not be modified.

func (*State) CheckStates

func (l *State) CheckStates() map[types.CheckID]*CheckState

CheckStates returns a shallow copy of all health check state records. The health check records and the deferred checks still point to the original values and must not be modified.

func (*State) CheckToken

func (l *State) CheckToken(checkID types.CheckID) string

CheckToken is used to return the configured health check token for a Check, or if none is configured, the default agent ACL token.

func (*State) Checks

func (l *State) Checks() map[types.CheckID]*structs.HealthCheck

Checks returns the locally registered checks that the agent is aware of and are being kept in sync with the server

func (*State) CriticalCheckStates

func (l *State) CriticalCheckStates() map[types.CheckID]*CheckState

CriticalCheckStates returns the locally registered checks that the agent is aware of and are being kept in sync with the server. The map contains a shallow copy of the current check states but references to the actual check definition which must not be modified.

func (*State) LoadMetadata

func (l *State) LoadMetadata(data map[string]string) error

LoadMetadata loads node metadata fields from the agent config and updates them on the local agent.

func (*State) Metadata

func (l *State) Metadata() map[string]string

Metadata returns the local node metadata fields that the agent is aware of and are being kept in sync with the server

func (*State) NotifyProxy added in v1.2.0

func (l *State) NotifyProxy(ch chan<- struct{})

NotifyProxy will register a channel to receive messages when the configuration or set of proxies changes. This will not block on channel send so ensure the channel has a buffer. Note that any buffer size is generally fine since actual data is not sent over the channel, so a dropped send due to a full buffer does not result in any loss of data. The fact that a buffer already contains a notification means that the receiver will still be notified that changes occurred.

NOTE(mitchellh): This could be more generalized but for my use case I only needed proxy events. In the future if it were to be generalized I would add a new Notify method and remove the proxy-specific ones.

func (*State) Proxies added in v1.2.0

func (l *State) Proxies() map[string]*ManagedProxy

Proxies returns the locally registered proxies.

func (*State) Proxy added in v1.2.0

func (l *State) Proxy(id string) *ManagedProxy

Proxy returns the local proxy state.

func (*State) RemoveCheck

func (l *State) RemoveCheck(id types.CheckID) error

RemoveCheck is used to remove a health check from the local state. The agent will make a best effort to ensure it is deregistered todo(fs): RemoveService returns an error for a non-existant service. RemoveCheck should as well. todo(fs): Check code that calls this to handle the error.

func (*State) RemoveProxy added in v1.2.0

func (l *State) RemoveProxy(id string) (*ManagedProxy, error)

RemoveProxy is used to remove a proxy entry from the local state. This returns the proxy that was removed.

func (*State) RemoveService

func (l *State) RemoveService(id string) error

RemoveService is used to remove a service entry from the local state. The agent will make a best effort to ensure it is deregistered.

func (*State) Service

func (l *State) Service(id string) *structs.NodeService

Service returns the locally registered service that the agent is aware of and are being kept in sync with the server

func (*State) ServiceState

func (l *State) ServiceState(id string) *ServiceState

ServiceState returns a shallow copy of the current service state record. The service record still points to the original service record and must not be modified.

func (*State) ServiceStates

func (l *State) ServiceStates() map[string]*ServiceState

ServiceStates returns a shallow copy of all service state records. The service record still points to the original service record and must not be modified.

func (*State) ServiceToken

func (l *State) ServiceToken(id string) string

ServiceToken returns the configured ACL token for the given service ID. If none is present, the agent's token is returned.

func (*State) Services

func (l *State) Services() map[string]*structs.NodeService

Services returns the locally registered services that the agent is aware of and are being kept in sync with the server

func (*State) SetCheckState

func (l *State) SetCheckState(c *CheckState)

SetCheckState is used to overwrite a raw check state with the given state. This method is safe to be called concurrently but should only be used during testing. You should most likely call AddCheck instead.

func (*State) SetDiscardCheckOutput

func (l *State) SetDiscardCheckOutput(b bool)

SetDiscardCheckOutput configures whether the check output is discarded. This can be changed at runtime.

func (*State) SetServiceState

func (l *State) SetServiceState(s *ServiceState)

SetServiceState is used to overwrite a raw service state with the given state. This method is safe to be called concurrently but should only be used during testing. You should most likely call AddService instead.

func (*State) Stats

func (l *State) Stats() map[string]string

Stats is used to get various debugging state from the sub-systems

func (*State) StopNotifyProxy added in v1.2.0

func (l *State) StopNotifyProxy(ch chan<- struct{})

StopNotifyProxy will deregister a channel receiving proxy notifications. Pair this with all calls to NotifyProxy to clean up state.

func (*State) SyncChanges

func (l *State) SyncChanges() error

SyncChanges pushes checks, services and node info data which has been marked out of sync or deleted to the server.

func (*State) SyncFull

func (l *State) SyncFull() error

SyncFull determines the delta between the local and remote state and synchronizes the changes.

func (*State) UnloadMetadata

func (l *State) UnloadMetadata()

UnloadMetadata resets the local metadata state

func (*State) UpdateCheck

func (l *State) UpdateCheck(id types.CheckID, status, output string)

UpdateCheck is used to update the status of a check

Jump to

Keyboard shortcuts

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