MM-28859 Add feature flag managment system using split.io and remove viper. (#15954)

* Add feature flag managment system using split.io and remove viper.

* Fixing tests.

* Attempt to fix postgres tests.

* Fix watch filepath for advanced logging.

* Review fixes.

* Some error wrapping.

* Remove unessisary store interface.

* Desanitize SplitKey

* Simplify.

* Review feedback.

* Rename split mlog adatper to split logger.

* fsInner

* Style.

* Restore oldcfg test.

* Downgrading non-actionable feature flag errors to warnings.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Christopher Speller
2020-10-29 15:54:39 -07:00
коммит произвёл GitHub
родитель 8bb772638c
Коммит 1aadd36644
423 изменённых файлов: 37646 добавлений и 20257 удалений

67
vendor/github.com/splitio/go-toolkit/v3/common/iterutil.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,67 @@
package common
import (
"errors"
"math"
"time"
)
// WithAttempts executes a function N times or until no error is returned
func WithAttempts(attempts int, main func() error) error {
err := errors.New("")
remaining := attempts
for err != nil && remaining > 0 {
remaining--
err = main()
}
return err
}
// WithBackoff wraps the function to add Exponential backoff
func WithBackoff(duration time.Duration, main func() error) func() error {
var count time.Duration = 1
return func() error {
err := main()
if err != nil {
time.Sleep(count * duration)
count++
} else {
count = 0
}
return main()
}
}
// WithBackoffCancelling wraps the function to add Exponential backoff
func WithBackoffCancelling(unit time.Duration, max time.Duration, main func() bool) func() {
cancel := make(chan struct{})
go func() {
attempts := 0
isDone := main()
// Create timeout timer for backoff
backoffTimer := time.NewTimer(MinDuration(time.Duration(math.Pow(2, float64(attempts)))*unit, max))
defer backoffTimer.Stop()
for !isDone {
attempts++
// Setting timer considerint attempts
backoffTimer.Reset(MinDuration(time.Duration(math.Pow(2, float64(attempts)))*unit, max))
select {
case <-cancel:
return
case <-backoffTimer.C: // Timedout
isDone = main()
}
}
}()
return func() {
select {
case cancel <- struct{}{}:
return
default:
}
}
}

105
vendor/github.com/splitio/go-toolkit/v3/common/refutil.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,105 @@
package common
// StringRef returns ref
func StringRef(str string) *string {
return &str
}
// IntRef returns ref
func IntRef(number int) *int {
return &number
}
// Int64Ref returns ref
func Int64Ref(number int64) *int64 {
return &number
}
// Float64Ref returns ref
func Float64Ref(number float64) *float64 {
return &number
}
// Int64Value returns value
func Int64Value(number *int64) int64 {
if number == nil {
return 0
}
return *number
}
// IntRefOrNil returns ref
func IntRefOrNil(number int) *int {
if number == 0 {
return nil
}
return IntRef(number)
}
// Int64RefOrNil returns ref
func Int64RefOrNil(number int64) *int64 {
if number == 0 {
return nil
}
return Int64Ref(number)
}
// StringRefOrNil returns ref
func StringRefOrNil(str string) *string {
if str == "" {
return nil
}
return StringRef(str)
}
// AsIntOrNil returns ref
func AsIntOrNil(data interface{}) *int {
if data == nil {
return nil
}
number, ok := data.(int)
if !ok {
return nil
}
return IntRef(number)
}
// AsInt64OrNil returns ref
func AsInt64OrNil(data interface{}) *int64 {
if data == nil {
return nil
}
number, ok := data.(int64)
if !ok {
return nil
}
return Int64Ref(number)
}
// AsFloat64OrNil return ref
func AsFloat64OrNil(data interface{}) *float64 {
if data == nil {
return nil
}
number, ok := data.(float64)
if !ok {
return nil
}
return Float64Ref(number)
}
// AsStringOrNil returns ref
func AsStringOrNil(data interface{}) *string {
if data == nil {
return nil
}
str, ok := data.(string)
if !ok {
return nil
}
return StringRef(str)
}

18
vendor/github.com/splitio/go-toolkit/v3/common/sliceutil.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,18 @@
package common
// Partition create partitions considering the passed amount
func Partition(items []string, maxItems int) [][]string {
var splitted [][]string
for i := 0; i < len(items); i += maxItems {
end := i + maxItems
if end > len(items) {
end = len(items)
}
splitted = append(splitted, items[i:end])
}
return splitted
}

9
vendor/github.com/splitio/go-toolkit/v3/common/strutil.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,9 @@
package common
// StringValueOrDefault returns original value if not empty. Default otherwise.
func StringValueOrDefault(str string, def string) string {
if str != "" {
return str
}
return def
}

25
vendor/github.com/splitio/go-toolkit/v3/common/timeutil.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,25 @@
package common
import "time"
// MinDuration returns the min duration among them
func MinDuration(d1, d2 time.Duration, ds ...time.Duration) time.Duration {
min := d1
for _, d := range append(ds, d2) {
if d < min {
min = d
}
}
return min
}
// MaxDuration returns the max duration among them
func MaxDuration(d1, d2 time.Duration, ds ...time.Duration) time.Duration {
max := d1
for _, d := range append(ds, d2) {
if d > max {
max = d
}
}
return max
}