mirror of https://github.com/status-im/consul.git
parent
3e00e36f41
commit
3403cd4372
|
@ -23,17 +23,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Do not allow for a interval below this value.
|
// MinInterval is the minimal interval between
|
||||||
|
// two checks. Do not allow for a interval below this value.
|
||||||
// Otherwise we risk fork bombing a system.
|
// Otherwise we risk fork bombing a system.
|
||||||
MinInterval = time.Second
|
MinInterval = time.Second
|
||||||
|
|
||||||
// Limit the size of a check's output to the
|
// CheckBufSize is the maximum size of the captured
|
||||||
// last CheckBufSize. Prevents an enormous buffer
|
// check output. Prevents an enormous buffer
|
||||||
// from being captured
|
// from being captured
|
||||||
CheckBufSize = 4 * 1024 // 4KB
|
CheckBufSize = 4 * 1024 // 4KB
|
||||||
|
|
||||||
// Use this user agent when doing requests for
|
// UserAgent is the value of the User-Agent header
|
||||||
// HTTP health checks.
|
// for HTTP health checks.
|
||||||
UserAgent = "Consul Health Check"
|
UserAgent = "Consul Health Check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -90,6 +91,7 @@ func (c *CheckType) IsTCP() bool {
|
||||||
return c.TCP != "" && c.Interval != 0
|
return c.TCP != "" && c.Interval != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDocker returns true when checking a docker container.
|
||||||
func (c *CheckType) IsDocker() bool {
|
func (c *CheckType) IsDocker() bool {
|
||||||
return c.DockerContainerID != "" && c.Script != "" && c.Interval != 0
|
return c.DockerContainerID != "" && c.Script != "" && c.Interval != 0
|
||||||
}
|
}
|
||||||
|
@ -550,8 +552,8 @@ func (c *CheckTCP) check() {
|
||||||
c.Notify.UpdateCheck(c.CheckID, api.HealthPassing, fmt.Sprintf("TCP connect %s: Success", c.TCP))
|
c.Notify.UpdateCheck(c.CheckID, api.HealthPassing, fmt.Sprintf("TCP connect %s: Success", c.TCP))
|
||||||
}
|
}
|
||||||
|
|
||||||
// A custom interface since go-dockerclient doesn't have one
|
// DockerClient defines an interface for a docker client
|
||||||
// We will use this interface in our test to inject a fake client
|
// which is used for injecting a fake client during tests.
|
||||||
type DockerClient interface {
|
type DockerClient interface {
|
||||||
CreateExec(docker.CreateExecOptions) (*docker.Exec, error)
|
CreateExec(docker.CreateExecOptions) (*docker.Exec, error)
|
||||||
StartExec(string, docker.StartExecOptions) error
|
StartExec(string, docker.StartExecOptions) error
|
||||||
|
@ -578,9 +580,8 @@ type CheckDocker struct {
|
||||||
stopLock sync.Mutex
|
stopLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
//Initializes the Docker Client
|
// Init initializes the Docker Client
|
||||||
func (c *CheckDocker) Init() error {
|
func (c *CheckDocker) Init() error {
|
||||||
//create the docker client
|
|
||||||
var err error
|
var err error
|
||||||
c.dockerClient, err = docker.NewClientFromEnv()
|
c.dockerClient, err = docker.NewClientFromEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
// config structure and merge it in a clean-ish way. If this ends up being a
|
// config structure and merge it in a clean-ish way. If this ends up being a
|
||||||
// good pattern we should pull this out into a reusable library.
|
// good pattern we should pull this out into a reusable library.
|
||||||
|
|
||||||
// configDecodeHook should be passed to mapstructure in order to decode into
|
// ConfigDecodeHook should be passed to mapstructure in order to decode into
|
||||||
// the *Value objects here.
|
// the *Value objects here.
|
||||||
var ConfigDecodeHook = mapstructure.ComposeDecodeHookFunc(
|
var ConfigDecodeHook = mapstructure.ComposeDecodeHookFunc(
|
||||||
BoolToBoolValueFunc(),
|
BoolToBoolValueFunc(),
|
||||||
|
@ -32,7 +32,9 @@ type BoolValue struct {
|
||||||
v *bool
|
v *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// IsBoolFlag is an optional method of the flag.Value
|
||||||
|
// interface which marks this value as boolean when
|
||||||
|
// the return value is true. See flag.Value for details.
|
||||||
func (b *BoolValue) IsBoolFlag() bool {
|
func (b *BoolValue) IsBoolFlag() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -44,7 +46,7 @@ func (b *BoolValue) Merge(onto *bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// Set implements the flag.Value interface.
|
||||||
func (b *BoolValue) Set(v string) error {
|
func (b *BoolValue) Set(v string) error {
|
||||||
if b.v == nil {
|
if b.v == nil {
|
||||||
b.v = new(bool)
|
b.v = new(bool)
|
||||||
|
@ -54,7 +56,7 @@ func (b *BoolValue) Set(v string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// String implements the flag.Value interface.
|
||||||
func (b *BoolValue) String() string {
|
func (b *BoolValue) String() string {
|
||||||
var current bool
|
var current bool
|
||||||
if b.v != nil {
|
if b.v != nil {
|
||||||
|
@ -97,7 +99,7 @@ func (d *DurationValue) Merge(onto *time.Duration) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// Set implements the flag.Value interface.
|
||||||
func (d *DurationValue) Set(v string) error {
|
func (d *DurationValue) Set(v string) error {
|
||||||
if d.v == nil {
|
if d.v == nil {
|
||||||
d.v = new(time.Duration)
|
d.v = new(time.Duration)
|
||||||
|
@ -107,7 +109,7 @@ func (d *DurationValue) Set(v string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// String implements the flag.Value interface.
|
||||||
func (d *DurationValue) String() string {
|
func (d *DurationValue) String() string {
|
||||||
var current time.Duration
|
var current time.Duration
|
||||||
if d.v != nil {
|
if d.v != nil {
|
||||||
|
@ -150,7 +152,7 @@ func (s *StringValue) Merge(onto *string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// Set implements the flag.Value interface.
|
||||||
func (s *StringValue) Set(v string) error {
|
func (s *StringValue) Set(v string) error {
|
||||||
if s.v == nil {
|
if s.v == nil {
|
||||||
s.v = new(string)
|
s.v = new(string)
|
||||||
|
@ -159,7 +161,7 @@ func (s *StringValue) Set(v string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// String implements the flag.Value interface.
|
||||||
func (s *StringValue) String() string {
|
func (s *StringValue) String() string {
|
||||||
var current string
|
var current string
|
||||||
if s.v != nil {
|
if s.v != nil {
|
||||||
|
@ -201,7 +203,7 @@ func (u *UintValue) Merge(onto *uint) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// Set implements the flag.Value interface.
|
||||||
func (u *UintValue) Set(v string) error {
|
func (u *UintValue) Set(v string) error {
|
||||||
if u.v == nil {
|
if u.v == nil {
|
||||||
u.v = new(uint)
|
u.v = new(uint)
|
||||||
|
@ -211,7 +213,7 @@ func (u *UintValue) Set(v string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// See flag.Value.
|
// String implements the flag.Value interface.
|
||||||
func (u *UintValue) String() string {
|
func (u *UintValue) String() string {
|
||||||
var current uint
|
var current uint
|
||||||
if u.v != nil {
|
if u.v != nil {
|
||||||
|
@ -258,7 +260,7 @@ func Float64ToUintValueFunc() mapstructure.DecodeHookFunc {
|
||||||
// traversal with visit().
|
// traversal with visit().
|
||||||
type VisitFn func(path string) error
|
type VisitFn func(path string) error
|
||||||
|
|
||||||
// visit will call the visitor function on the path if it's a file, or for each
|
// Visit will call the visitor function on the path if it's a file, or for each
|
||||||
// file in the path if it's a directory. Directories will not be recursed into,
|
// file in the path if it's a directory. Directories will not be recursed into,
|
||||||
// and files in the directory will be visited in alphabetical order.
|
// and files in the directory will be visited in alphabetical order.
|
||||||
func Visit(path string, visitor VisitFn) error {
|
func Visit(path string, visitor VisitFn) error {
|
||||||
|
@ -303,17 +305,6 @@ func Visit(path string, visitor VisitFn) error {
|
||||||
// dirEnts applies sort.Interface to directory entries for sorting by name.
|
// dirEnts applies sort.Interface to directory entries for sorting by name.
|
||||||
type dirEnts []os.FileInfo
|
type dirEnts []os.FileInfo
|
||||||
|
|
||||||
// See sort.Interface.
|
func (d dirEnts) Len() int { return len(d) }
|
||||||
func (d dirEnts) Len() int {
|
func (d dirEnts) Less(i, j int) bool { return d[i].Name() < d[j].Name() }
|
||||||
return len(d)
|
func (d dirEnts) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
|
||||||
}
|
|
||||||
|
|
||||||
// See sort.Interface.
|
|
||||||
func (d dirEnts) Less(i, j int) bool {
|
|
||||||
return d[i].Name() < d[j].Name()
|
|
||||||
}
|
|
||||||
|
|
||||||
// See sort.Interface.
|
|
||||||
func (d dirEnts) Swap(i, j int) {
|
|
||||||
d[i], d[j] = d[j], d[i]
|
|
||||||
}
|
|
||||||
|
|
|
@ -52,54 +52,44 @@ const (
|
||||||
// that new commands can be added in a way that won't cause
|
// that new commands can be added in a way that won't cause
|
||||||
// old servers to crash when the FSM attempts to process them.
|
// old servers to crash when the FSM attempts to process them.
|
||||||
IgnoreUnknownTypeFlag MessageType = 128
|
IgnoreUnknownTypeFlag MessageType = 128
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// NodeMaint is the special key set by a node in maintenance mode.
|
// NodeMaint is the special key set by a node in maintenance mode.
|
||||||
NodeMaint = "_node_maintenance"
|
NodeMaint = "_node_maintenance"
|
||||||
|
|
||||||
// ServiceMaintPrefix is the prefix for a service in maintenance mode.
|
// ServiceMaintPrefix is the prefix for a service in maintenance mode.
|
||||||
ServiceMaintPrefix = "_service_maintenance:"
|
ServiceMaintPrefix = "_service_maintenance:"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// The meta key prefix reserved for Consul's internal use
|
// The meta key prefix reserved for Consul's internal use
|
||||||
metaKeyReservedPrefix = "consul-"
|
metaKeyReservedPrefix = "consul-"
|
||||||
|
|
||||||
// The maximum number of metadata key pairs allowed to be registered
|
// metaMaxKeyPairs is maximum number of metadata key pairs allowed to be registered
|
||||||
metaMaxKeyPairs = 64
|
metaMaxKeyPairs = 64
|
||||||
|
|
||||||
// The maximum allowed length of a metadata key
|
// metaKeyMaxLength is the maximum allowed length of a metadata key
|
||||||
metaKeyMaxLength = 128
|
metaKeyMaxLength = 128
|
||||||
|
|
||||||
// The maximum allowed length of a metadata value
|
// metaValueMaxLength is the maximum allowed length of a metadata value
|
||||||
metaValueMaxLength = 512
|
metaValueMaxLength = 512
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// metaKeyFormat checks if a metadata key string is valid
|
|
||||||
metaKeyFormat = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString
|
|
||||||
)
|
|
||||||
|
|
||||||
func ValidStatus(s string) bool {
|
|
||||||
return s == api.HealthPassing || s == api.HealthWarning || s == api.HealthCritical
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Client tokens have rules applied
|
// Client tokens have rules applied
|
||||||
ACLTypeClient = "client"
|
ACLTypeClient = "client"
|
||||||
|
|
||||||
// Management tokens have an always allow policy.
|
// Management tokens have an always allow policy.
|
||||||
// They are used for token management.
|
// They are used for token management.
|
||||||
ACLTypeManagement = "management"
|
ACLTypeManagement = "management"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// MaxLockDelay provides a maximum LockDelay value for
|
// MaxLockDelay provides a maximum LockDelay value for
|
||||||
// a session. Any value above this will not be respected.
|
// a session. Any value above this will not be respected.
|
||||||
MaxLockDelay = 60 * time.Second
|
MaxLockDelay = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// metaKeyFormat checks if a metadata key string is valid
|
||||||
|
var metaKeyFormat = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString
|
||||||
|
|
||||||
|
func ValidStatus(s string) bool {
|
||||||
|
return s == api.HealthPassing || s == api.HealthWarning || s == api.HealthCritical
|
||||||
|
}
|
||||||
|
|
||||||
// RPCInfo is used to describe common information about query
|
// RPCInfo is used to describe common information about query
|
||||||
type RPCInfo interface {
|
type RPCInfo interface {
|
||||||
RequestDatacenter() string
|
RequestDatacenter() string
|
||||||
|
@ -130,7 +120,7 @@ type QueryOptions struct {
|
||||||
RequireConsistent bool
|
RequireConsistent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryOption only applies to reads, so always true
|
// IsRead is always true for QueryOption.
|
||||||
func (q QueryOptions) IsRead() bool {
|
func (q QueryOptions) IsRead() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func DurationMinusBufferDomain(intv time.Duration, buffer time.Duration, jitter
|
||||||
return min, max
|
return min, max
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a random stagger interval between 0 and the duration
|
// RandomStagger returns an interval between 0 and the duration
|
||||||
func RandomStagger(intv time.Duration) time.Duration {
|
func RandomStagger(intv time.Duration) time.Duration {
|
||||||
if intv == 0 {
|
if intv == 0 {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package testutil
|
package testutil
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
type WrappedServer struct {
|
type WrappedServer struct {
|
||||||
s *TestServer
|
s *TestServer
|
||||||
|
@ -19,78 +17,45 @@ type WrappedServer struct {
|
||||||
// This is useful when you are calling multiple functions and save the wrapped
|
// This is useful when you are calling multiple functions and save the wrapped
|
||||||
// value as another variable to reduce the inclusion of "t".
|
// value as another variable to reduce the inclusion of "t".
|
||||||
func (s *TestServer) Wrap(t *testing.T) *WrappedServer {
|
func (s *TestServer) Wrap(t *testing.T) *WrappedServer {
|
||||||
return &WrappedServer{
|
return &WrappedServer{s, t}
|
||||||
s: s,
|
|
||||||
t: t,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.JoinLAN()
|
|
||||||
func (w *WrappedServer) JoinLAN(addr string) {
|
func (w *WrappedServer) JoinLAN(addr string) {
|
||||||
w.s.JoinLAN(w.t, addr)
|
w.s.JoinLAN(w.t, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.JoinWAN()
|
|
||||||
func (w *WrappedServer) JoinWAN(addr string) {
|
func (w *WrappedServer) JoinWAN(addr string) {
|
||||||
w.s.JoinWAN(w.t, addr)
|
w.s.JoinWAN(w.t, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.SetKV()
|
|
||||||
func (w *WrappedServer) SetKV(key string, val []byte) {
|
func (w *WrappedServer) SetKV(key string, val []byte) {
|
||||||
w.s.SetKV(w.t, key, val)
|
w.s.SetKV(w.t, key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.SetKVString()
|
|
||||||
func (w *WrappedServer) SetKVString(key string, val string) {
|
func (w *WrappedServer) SetKVString(key string, val string) {
|
||||||
w.s.SetKVString(w.t, key, val)
|
w.s.SetKVString(w.t, key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.GetKV()
|
|
||||||
func (w *WrappedServer) GetKV(key string) []byte {
|
func (w *WrappedServer) GetKV(key string) []byte {
|
||||||
return w.s.GetKV(w.t, key)
|
return w.s.GetKV(w.t, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.GetKVString()
|
|
||||||
func (w *WrappedServer) GetKVString(key string) string {
|
func (w *WrappedServer) GetKVString(key string) string {
|
||||||
return w.s.GetKVString(w.t, key)
|
return w.s.GetKVString(w.t, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.PopulateKV()
|
|
||||||
func (w *WrappedServer) PopulateKV(data map[string][]byte) {
|
func (w *WrappedServer) PopulateKV(data map[string][]byte) {
|
||||||
w.s.PopulateKV(w.t, data)
|
w.s.PopulateKV(w.t, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.ListKV()
|
|
||||||
func (w *WrappedServer) ListKV(prefix string) []string {
|
func (w *WrappedServer) ListKV(prefix string) []string {
|
||||||
return w.s.ListKV(w.t, prefix)
|
return w.s.ListKV(w.t, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.AddService()
|
|
||||||
func (w *WrappedServer) AddService(name, status string, tags []string) {
|
func (w *WrappedServer) AddService(name, status string, tags []string) {
|
||||||
w.s.AddService(w.t, name, status, tags)
|
w.s.AddService(w.t, name, status, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// See Also
|
|
||||||
//
|
|
||||||
// TestServer.AddCheck()
|
|
||||||
func (w *WrappedServer) AddCheck(name, serviceID, status string) {
|
func (w *WrappedServer) AddCheck(name, serviceID, status string) {
|
||||||
w.s.AddCheck(w.t, name, serviceID, status)
|
w.s.AddCheck(w.t, name, serviceID, status)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue