parent
9de4555c0c
commit
9e2332f6a1
|
@ -23,17 +23,18 @@ import (
|
|||
)
|
||||
|
||||
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.
|
||||
MinInterval = time.Second
|
||||
|
||||
// Limit the size of a check's output to the
|
||||
// last CheckBufSize. Prevents an enormous buffer
|
||||
// CheckBufSize is the maximum size of the captured
|
||||
// check output. Prevents an enormous buffer
|
||||
// from being captured
|
||||
CheckBufSize = 4 * 1024 // 4KB
|
||||
|
||||
// Use this user agent when doing requests for
|
||||
// HTTP health checks.
|
||||
// UserAgent is the value of the User-Agent header
|
||||
// for HTTP health checks.
|
||||
UserAgent = "Consul Health Check"
|
||||
)
|
||||
|
||||
|
@ -90,6 +91,7 @@ func (c *CheckType) IsTCP() bool {
|
|||
return c.TCP != "" && c.Interval != 0
|
||||
}
|
||||
|
||||
// IsDocker returns true when checking a docker container.
|
||||
func (c *CheckType) IsDocker() bool {
|
||||
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))
|
||||
}
|
||||
|
||||
// A custom interface since go-dockerclient doesn't have one
|
||||
// We will use this interface in our test to inject a fake client
|
||||
// DockerClient defines an interface for a docker client
|
||||
// which is used for injecting a fake client during tests.
|
||||
type DockerClient interface {
|
||||
CreateExec(docker.CreateExecOptions) (*docker.Exec, error)
|
||||
StartExec(string, docker.StartExecOptions) error
|
||||
|
@ -578,9 +580,8 @@ type CheckDocker struct {
|
|||
stopLock sync.Mutex
|
||||
}
|
||||
|
||||
//Initializes the Docker Client
|
||||
// Init initializes the Docker Client
|
||||
func (c *CheckDocker) Init() error {
|
||||
//create the docker client
|
||||
var err error
|
||||
c.dockerClient, err = docker.NewClientFromEnv()
|
||||
if err != nil {
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
// 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.
|
||||
|
||||
// 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.
|
||||
var ConfigDecodeHook = mapstructure.ComposeDecodeHookFunc(
|
||||
BoolToBoolValueFunc(),
|
||||
|
@ -32,7 +32,9 @@ type BoolValue struct {
|
|||
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 {
|
||||
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 {
|
||||
if b.v == nil {
|
||||
b.v = new(bool)
|
||||
|
@ -54,7 +56,7 @@ func (b *BoolValue) Set(v string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// See flag.Value.
|
||||
// String implements the flag.Value interface.
|
||||
func (b *BoolValue) String() string {
|
||||
var current bool
|
||||
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 {
|
||||
if d.v == nil {
|
||||
d.v = new(time.Duration)
|
||||
|
@ -107,7 +109,7 @@ func (d *DurationValue) Set(v string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// See flag.Value.
|
||||
// String implements the flag.Value interface.
|
||||
func (d *DurationValue) String() string {
|
||||
var current time.Duration
|
||||
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 {
|
||||
if s.v == nil {
|
||||
s.v = new(string)
|
||||
|
@ -159,7 +161,7 @@ func (s *StringValue) Set(v string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// See flag.Value.
|
||||
// String implements the flag.Value interface.
|
||||
func (s *StringValue) String() string {
|
||||
var current string
|
||||
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 {
|
||||
if u.v == nil {
|
||||
u.v = new(uint)
|
||||
|
@ -211,7 +213,7 @@ func (u *UintValue) Set(v string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// See flag.Value.
|
||||
// String implements the flag.Value interface.
|
||||
func (u *UintValue) String() string {
|
||||
var current uint
|
||||
if u.v != nil {
|
||||
|
@ -258,7 +260,7 @@ func Float64ToUintValueFunc() mapstructure.DecodeHookFunc {
|
|||
// traversal with visit().
|
||||
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,
|
||||
// and files in the directory will be visited in alphabetical order.
|
||||
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.
|
||||
type dirEnts []os.FileInfo
|
||||
|
||||
// See sort.Interface.
|
||||
func (d dirEnts) Len() int {
|
||||
return len(d)
|
||||
}
|
||||
|
||||
// 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]
|
||||
}
|
||||
func (d dirEnts) Len() int { return len(d) }
|
||||
func (d dirEnts) Less(i, j int) bool { return d[i].Name() < d[j].Name() }
|
||||
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
|
||||
// old servers to crash when the FSM attempts to process them.
|
||||
IgnoreUnknownTypeFlag MessageType = 128
|
||||
)
|
||||
|
||||
const (
|
||||
// NodeMaint is the special key set by a node in maintenance mode.
|
||||
NodeMaint = "_node_maintenance"
|
||||
|
||||
// ServiceMaintPrefix is the prefix for a service in maintenance mode.
|
||||
ServiceMaintPrefix = "_service_maintenance:"
|
||||
)
|
||||
|
||||
const (
|
||||
// The meta key prefix reserved for Consul's internal use
|
||||
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
|
||||
|
||||
// The maximum allowed length of a metadata key
|
||||
// metaKeyMaxLength is the maximum allowed length of a metadata key
|
||||
metaKeyMaxLength = 128
|
||||
|
||||
// The maximum allowed length of a metadata value
|
||||
// metaValueMaxLength is the maximum allowed length of a metadata value
|
||||
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
|
||||
ACLTypeClient = "client"
|
||||
|
||||
// Management tokens have an always allow policy.
|
||||
// They are used for token management.
|
||||
ACLTypeManagement = "management"
|
||||
)
|
||||
|
||||
const (
|
||||
// MaxLockDelay provides a maximum LockDelay value for
|
||||
// a session. Any value above this will not be respected.
|
||||
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
|
||||
type RPCInfo interface {
|
||||
RequestDatacenter() string
|
||||
|
@ -130,7 +120,7 @@ type QueryOptions struct {
|
|||
RequireConsistent bool
|
||||
}
|
||||
|
||||
// QueryOption only applies to reads, so always true
|
||||
// IsRead is always true for QueryOption.
|
||||
func (q QueryOptions) IsRead() bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func DurationMinusBufferDomain(intv time.Duration, buffer time.Duration, jitter
|
|||
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 {
|
||||
if intv == 0 {
|
||||
return 0
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
type WrappedServer struct {
|
||||
s *TestServer
|
||||
|
@ -19,78 +17,45 @@ type WrappedServer struct {
|
|||
// This is useful when you are calling multiple functions and save the wrapped
|
||||
// value as another variable to reduce the inclusion of "t".
|
||||
func (s *TestServer) Wrap(t *testing.T) *WrappedServer {
|
||||
return &WrappedServer{
|
||||
s: s,
|
||||
t: t,
|
||||
}
|
||||
return &WrappedServer{s, t}
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.JoinLAN()
|
||||
func (w *WrappedServer) JoinLAN(addr string) {
|
||||
w.s.JoinLAN(w.t, addr)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.JoinWAN()
|
||||
func (w *WrappedServer) JoinWAN(addr string) {
|
||||
w.s.JoinWAN(w.t, addr)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.SetKV()
|
||||
func (w *WrappedServer) SetKV(key string, val []byte) {
|
||||
w.s.SetKV(w.t, key, val)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.SetKVString()
|
||||
func (w *WrappedServer) SetKVString(key string, val string) {
|
||||
w.s.SetKVString(w.t, key, val)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.GetKV()
|
||||
func (w *WrappedServer) GetKV(key string) []byte {
|
||||
return w.s.GetKV(w.t, key)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.GetKVString()
|
||||
func (w *WrappedServer) GetKVString(key string) string {
|
||||
return w.s.GetKVString(w.t, key)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.PopulateKV()
|
||||
func (w *WrappedServer) PopulateKV(data map[string][]byte) {
|
||||
w.s.PopulateKV(w.t, data)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.ListKV()
|
||||
func (w *WrappedServer) ListKV(prefix string) []string {
|
||||
return w.s.ListKV(w.t, prefix)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.AddService()
|
||||
func (w *WrappedServer) AddService(name, status string, tags []string) {
|
||||
w.s.AddService(w.t, name, status, tags)
|
||||
}
|
||||
|
||||
// See Also
|
||||
//
|
||||
// TestServer.AddCheck()
|
||||
func (w *WrappedServer) AddCheck(name, serviceID, status string) {
|
||||
w.s.AddCheck(w.t, name, serviceID, status)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue