Documentation ¶
Index ¶
- Variables
- type CheckState
- type Config
- type ServiceState
- type State
- func (l *State) AddAliasCheck(checkID structs.CheckID, srcServiceID structs.ServiceID, ...) error
- func (l *State) AddCheck(check *structs.HealthCheck, token string, isLocallyDefined bool) error
- func (l *State) AddServiceWithChecks(service *structs.NodeService, checks []*structs.HealthCheck, token string, ...) error
- func (l *State) AllCheckStates() map[structs.CheckID]*CheckState
- func (l *State) AllChecks() map[structs.CheckID]*structs.HealthCheck
- func (l *State) AllCriticalCheckStates() map[structs.CheckID]*CheckState
- func (l *State) AllServices() map[structs.ServiceID]*structs.NodeService
- func (l *State) Check(id structs.CheckID) *structs.HealthCheck
- func (l *State) CheckState(id structs.CheckID) *CheckState
- func (l *State) CheckStates(entMeta *acl.EnterpriseMeta) map[structs.CheckID]*CheckState
- func (l *State) CheckToken(id structs.CheckID) string
- func (l *State) Checks(entMeta *acl.EnterpriseMeta) map[structs.CheckID]*structs.HealthCheck
- func (l *State) ChecksForService(serviceID structs.ServiceID, includeNodeChecks bool) map[structs.CheckID]*structs.HealthCheck
- func (l *State) CriticalCheckStates(entMeta *acl.EnterpriseMeta) map[structs.CheckID]*CheckState
- func (l *State) LoadMetadata(data map[string]string) error
- func (l *State) Metadata() map[string]string
- func (l *State) Notify(ch chan<- struct{})
- func (l *State) RemoveAliasCheck(checkID structs.CheckID, srcServiceID structs.ServiceID)
- func (l *State) RemoveCheck(id structs.CheckID) error
- func (l *State) RemoveService(id structs.ServiceID) error
- func (l *State) RemoveServiceWithChecks(serviceID structs.ServiceID, checkIDs []structs.CheckID) error
- func (l *State) Service(id structs.ServiceID) *structs.NodeService
- func (l *State) ServiceExists(serviceID structs.ServiceID) bool
- func (l *State) ServiceState(id structs.ServiceID) *ServiceState
- func (l *State) ServiceStates(entMeta *acl.EnterpriseMeta) map[structs.ServiceID]*ServiceState
- func (l *State) ServiceToken(id structs.ServiceID) string
- func (l *State) Services(entMeta *acl.EnterpriseMeta) map[structs.ServiceID]*structs.NodeService
- func (l *State) ServicesByName(sn structs.ServiceName) []*structs.NodeService
- func (l *State) SetCheckState(c *CheckState)
- func (l *State) SetDiscardCheckOutput(b bool)
- func (l *State) SetServiceState(s *ServiceState)
- func (l *State) Stats() map[string]string
- func (l *State) StopNotify(ch chan<- struct{})
- func (l *State) SyncChanges() error
- func (l *State) SyncFull() error
- func (l *State) UnloadMetadata()
- func (l *State) UpdateCheck(id structs.CheckID, status, output string)
Constants ¶
This section is empty.
Variables ¶
var StateCounters = []prometheus.CounterDefinition{ { Name: []string{"acl", "blocked", "service", "registration"}, Help: "Increments whenever a registration fails for a service (blocked by an ACL)", }, { Name: []string{"acl", "blocked", "service", "deregistration"}, Help: "Increments whenever a deregistration fails for a service (blocked by an ACL)", }, { Name: []string{"acl", "blocked", "check", "registration"}, Help: "Increments whenever a registration fails for a check (blocked by an ACL)", }, { Name: []string{"acl", "blocked", "check", "deregistration"}, Help: "Increments whenever a deregistration fails for a check (blocked by an ACL)", }, { Name: []string{"acl", "blocked", "node", "registration"}, Help: "Increments whenever a registration fails for a node (blocked by an ACL)", }, }
Functions ¶
This section is empty.
Types ¶
type CheckState ¶
type CheckState struct { // Check is the local copy of the health check record. // // Must Clone() the overall CheckState before mutating this. After mutation // reinstall into the checks map. If Deleted is true, this field can be nil. 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 // IsLocallyDefined indicates whether the check was defined locally in config // as opposed to being registered through the Agent API. IsLocallyDefined 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 defer timer still points to the original value 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 NodeLocality *structs.Locality Partition string // this defaults if empty TaggedAddresses map[string]string }
Config is the configuration for the State.
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 // IsLocallyDefined indicates whether the service was defined locally in config // as opposed to being registered through the Agent API. IsLocallyDefined bool // WatchCh is closed when the service state changes. Suitable for use in a // memdb.WatchSet when watching agent local changes with hash-based blocking. WatchCh chan struct{} }
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. The WatchCh is also still pointing to the original so the clone will be update when the original is.
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 TestState ¶ added in v1.2.0
func TestState(_ testing.T) *State
TestState returns a configured *State for testing.
func (*State) AddAliasCheck ¶ added in v1.2.2
func (l *State) AddAliasCheck(checkID structs.CheckID, srcServiceID structs.ServiceID, notifyCh chan<- struct{}) error
AddAliasCheck creates an alias check. When any check for the srcServiceID is changed, checkID will reflect that using the same semantics as checks.CheckAlias.
This is a local optimization so that the Alias check doesn't need to use blocking queries against the remote server for check updates for local services.
func (*State) AddCheck ¶
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. The isLocallyDefined parameter indicates whether the checks are sourced from local agent configuration files.
func (*State) AddServiceWithChecks ¶ added in v1.4.3
func (l *State) AddServiceWithChecks(service *structs.NodeService, checks []*structs.HealthCheck, token string, isLocallyDefined bool) error
AddServiceWithChecks adds a service entry and its checks to the local state atomically This entry is persistent and the agent will make a best effort to ensure it is registered. The isLocallyDefined parameter indicates whether the service and checks are sourced from local agent configuration files.
func (*State) AllCheckStates ¶ added in v1.16.100
func (l *State) AllCheckStates() map[structs.CheckID]*CheckState
AllCheckStates returns a shallow copy of all health check state records. The map contains a shallow copy of the current check states.
The defer timers still point to the original values and must not be modified.
func (*State) AllChecks ¶ added in v1.16.100
func (l *State) AllChecks() map[structs.CheckID]*structs.HealthCheck
AllChecks returns the locally registered checks that the agent is aware of and are being kept in sync with the server
func (*State) AllCriticalCheckStates ¶ added in v1.16.100
func (l *State) AllCriticalCheckStates() map[structs.CheckID]*CheckState
AllCriticalCheckStates 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.
The defer timers still point to the original values and must not be modified.
func (*State) AllServices ¶ added in v1.16.100
func (l *State) AllServices() map[structs.ServiceID]*structs.NodeService
AllServices returns the locally registered services that the agent is aware of and are being kept in sync with the server
func (*State) Check ¶
func (l *State) Check(id structs.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 structs.CheckID) *CheckState
CheckState returns a shallow copy of the current health check state record.
The defer timer still points to the original value and must not be modified.
func (*State) CheckStates ¶
func (l *State) CheckStates(entMeta *acl.EnterpriseMeta) map[structs.CheckID]*CheckState
CheckStates returns a shallow copy of all health check state records. The map contains a shallow copy of the current check states.
The defer timers still point to the original values and must not be modified.
Results are scoped to the provided namespace and partition.
func (*State) CheckToken ¶
CheckToken returns the ACL token associated with the check. If the check is not found, or does not have a token, the empty string is returned.
func (*State) Checks ¶
func (l *State) Checks(entMeta *acl.EnterpriseMeta) map[structs.CheckID]*structs.HealthCheck
Checks returns the locally registered checks that the agent is aware of and are being kept in sync with the server
Results are scoped to the provided namespace and partition.
func (*State) ChecksForService ¶ added in v1.16.100
func (*State) CriticalCheckStates ¶
func (l *State) CriticalCheckStates(entMeta *acl.EnterpriseMeta) map[structs.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.
The defer timers still point to the original values and must not be modified.
Results are scoped to the provided namespace and partition.
func (*State) LoadMetadata ¶
LoadMetadata loads node metadata fields from the agent config and updates them on the local agent.
func (*State) Metadata ¶
Metadata returns the local node metadata fields that the agent is aware of and are being kept in sync with the server
func (*State) Notify ¶ added in v1.3.0
func (l *State) Notify(ch chan<- struct{})
Notify will register a channel to receive messages when the local state changes. Only service add/remove are supported for now. See notes on l.notifyHandlers for more details.
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.
func (*State) RemoveAliasCheck ¶ added in v1.2.2
RemoveAliasCheck removes the mapping for the alias check.
func (*State) RemoveCheck ¶
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-existent service. RemoveCheck should as well. todo(fs): Check code that calls this to handle the error.
func (*State) RemoveService ¶
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) RemoveServiceWithChecks ¶ added in v1.4.3
func (l *State) RemoveServiceWithChecks(serviceID structs.ServiceID, checkIDs []structs.CheckID) error
RemoveServiceWithChecks removes a service and its check from the local state atomically
func (*State) Service ¶
func (l *State) Service(id structs.ServiceID) *structs.NodeService
Service returns the locally registered service that the agent is aware of with this ID and are being kept in sync with the server.
func (*State) ServiceExists ¶ added in v1.16.100
ServiceExists return true if the given service does exists
func (*State) ServiceState ¶
func (l *State) ServiceState(id structs.ServiceID) *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. The WatchCh for the copy returned will also be closed when the actual service state is changed.
func (*State) ServiceStates ¶
func (l *State) ServiceStates(entMeta *acl.EnterpriseMeta) map[structs.ServiceID]*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 ¶
ServiceToken returns the ACL token associated with the service. If the service is not found, or does not have a token, the empty string is returned.
func (*State) Services ¶
func (l *State) Services(entMeta *acl.EnterpriseMeta) map[structs.ServiceID]*structs.NodeService
Services returns the locally registered services that the agent is aware of and are being kept in sync with the server
Results are scoped to the provided namespace and partition.
func (*State) ServicesByName ¶ added in v1.16.100
func (l *State) ServicesByName(sn structs.ServiceName) []*structs.NodeService
ServicesByName returns all the locally registered service instances that the agent is aware of with this name 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 ¶
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) StopNotify ¶ added in v1.3.0
func (l *State) StopNotify(ch chan<- struct{})
StopNotify will deregister a channel receiving state change notifications. Pair this with all calls to Notify to clean up state.
func (*State) SyncChanges ¶
SyncChanges pushes checks, services and node info data which has been marked out of sync or deleted to the server.
func (*State) SyncFull ¶
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