6a57c7fec5
This endpoint aggregates all checks related to <service id> on the agent and return an appropriate http code + the string describing the worst check. This allows to cleanly expose service status to other component, hiding complexity of multiple checks. This is especially useful to use consul to feed a load balancer which would delegate health checking to consul agent. Exposing this endpoint on the agent is necessary to avoid a hit on consul servers and avoid decreasing resiliency (this endpoint will work even if there is no consul leader in the cluster).
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package structs
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
errNoLeader = "No cluster leader"
|
|
errNoDCPath = "No path to datacenter"
|
|
errNoServers = "No known Consul servers"
|
|
errNotReadyForConsistentReads = "Not ready to serve consistent reads"
|
|
errSegmentsNotSupported = "Network segments are not supported in this version of Consul"
|
|
errRPCRateExceeded = "RPC rate limit exceeded"
|
|
errServiceNotFound = "Service not found: "
|
|
)
|
|
|
|
var (
|
|
ErrNoLeader = errors.New(errNoLeader)
|
|
ErrNoDCPath = errors.New(errNoDCPath)
|
|
ErrNoServers = errors.New(errNoServers)
|
|
ErrNotReadyForConsistentReads = errors.New(errNotReadyForConsistentReads)
|
|
ErrSegmentsNotSupported = errors.New(errSegmentsNotSupported)
|
|
ErrRPCRateExceeded = errors.New(errRPCRateExceeded)
|
|
)
|
|
|
|
func IsErrNoLeader(err error) bool {
|
|
return err != nil && strings.Contains(err.Error(), errNoLeader)
|
|
}
|
|
|
|
func IsErrRPCRateExceeded(err error) bool {
|
|
return err != nil && strings.Contains(err.Error(), errRPCRateExceeded)
|
|
}
|
|
|
|
func IsErrServiceNotFound(err error) bool {
|
|
return err != nil && strings.Contains(err.Error(), errServiceNotFound)
|
|
}
|