Update vendor'ed version of hashicorp/consul/lib
Note: Godeps.json not updated
This commit is contained in:
parent
230b59f34c
commit
2060766107
36
vendor/github.com/hashicorp/consul/lib/cluster.go
generated
vendored
Normal file
36
vendor/github.com/hashicorp/consul/lib/cluster.go
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DurationMinusBuffer returns a duration, minus a buffer and jitter
|
||||||
|
// subtracted from the duration. This function is used primarily for
|
||||||
|
// servicing Consul TTL Checks in advance of the TTL.
|
||||||
|
func DurationMinusBuffer(intv time.Duration, buffer time.Duration, jitter int64) time.Duration {
|
||||||
|
d := intv - buffer
|
||||||
|
d -= RandomStagger(time.Duration(int64(d) / jitter))
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a random stagger interval between 0 and the duration
|
||||||
|
func RandomStagger(intv time.Duration) time.Duration {
|
||||||
|
return time.Duration(uint64(rand.Int63()) % uint64(intv))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RateScaledInterval is used to choose an interval to perform an action in
|
||||||
|
// order to target an aggregate number of actions per second across the whole
|
||||||
|
// cluster.
|
||||||
|
func RateScaledInterval(rate float64, min time.Duration, n int) time.Duration {
|
||||||
|
const minRate = 1 / 86400 // 1/(1 * time.Day)
|
||||||
|
if rate <= minRate {
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
interval := time.Duration(float64(time.Second) * float64(n) / rate)
|
||||||
|
if interval < min {
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
|
||||||
|
return interval
|
||||||
|
}
|
22
vendor/github.com/hashicorp/consul/lib/math.go
generated
vendored
Normal file
22
vendor/github.com/hashicorp/consul/lib/math.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
func AbsInt(a int) int {
|
||||||
|
if a > 0 {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return a * -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func MaxInt(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func MinInt(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
18
vendor/github.com/hashicorp/consul/lib/rand.go
generated
vendored
Normal file
18
vendor/github.com/hashicorp/consul/lib/rand.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
|
// SeedMathRand provides weak, but guaranteed seeding, which is better than
|
||||||
|
// running with Go's default seed of 1. A call to SeedMathRand() is expected
|
||||||
|
// to be called via init(), but never a second time.
|
||||||
|
func SeedMathRand() {
|
||||||
|
once.Do(func() { rand.Seed(time.Now().UTC().UnixNano()) })
|
||||||
|
}
|
11
vendor/github.com/hashicorp/consul/lib/string.go
generated
vendored
Normal file
11
vendor/github.com/hashicorp/consul/lib/string.go
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
// StrContains checks if a list contains a string
|
||||||
|
func StrContains(l []string, s string) bool {
|
||||||
|
for _, v := range l {
|
||||||
|
if v == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
Loading…
Reference in a new issue