diff --git a/CHANGES.txt b/CHANGES.txt index 67dc3058..aee83d31 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,9 @@ +6.1.8 (Sep 9, 2022) +- Updated BooleanMatcher logging: demoted the log message to "warning". + +6.1.7 (Sep 8, 2022) +- Replaced murmur3 32 library. + 6.1.6 (June 21, 2022) - Updated the synchronization flow to be more reliable in the event of an edge case generating delay in cache purge propagation, keeping the SDK cache properly synced. diff --git a/go.mod b/go.mod index 325f4fec..2a5a0ce7 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/splitio/go-client/v6 go 1.13 require ( - github.com/splitio/go-split-commons/v4 v4.1.0 - github.com/splitio/go-toolkit/v5 v5.2.0 + github.com/splitio/go-split-commons/v4 v4.1.3 + github.com/splitio/go-toolkit/v5 v5.2.1 ) diff --git a/go.sum b/go.sum index 8af83dc2..fc61266e 100644 --- a/go.sum +++ b/go.sum @@ -47,10 +47,10 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/splitio/go-split-commons/v4 v4.1.0 h1:bERGPdxHbjPFRy0SCiwqZzPRo51hleP3yHpzuPimlDQ= -github.com/splitio/go-split-commons/v4 v4.1.0/go.mod h1:ycM23TPERljz7Anp6W4nwxPNoaIqY2d4n/UWYV0V0PE= -github.com/splitio/go-toolkit/v5 v5.2.0 h1:9bej4sMHVdcc+aB8IXQYEK9OjJ44H/jYFYRkbRwKsu4= -github.com/splitio/go-toolkit/v5 v5.2.0/go.mod h1:SYi/svhhtEgdMSb5tNcDcMjOSUH/7XVkvjp5dPL+nBE= +github.com/splitio/go-split-commons/v4 v4.1.3 h1:Aal1SF4GvmSP25P29oSLL6N9UMUhvFN/LURIxX2rACk= +github.com/splitio/go-split-commons/v4 v4.1.3/go.mod h1:E6yZiXwcjOdV5B7pHrBDbCsl4ju1YgYokRISZ9bYjgY= +github.com/splitio/go-toolkit/v5 v5.2.1 h1:WiAu7DD4Rl+Ly7Yz/8IDjhqAIySnlXlH6d7cG9KgoOY= +github.com/splitio/go-toolkit/v5 v5.2.1/go.mod h1:SYi/svhhtEgdMSb5tNcDcMjOSUH/7XVkvjp5dPL+nBE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/splitio/conf/sdkconf.go b/splitio/conf/sdkconf.go index 094d825f..0a0c0005 100644 --- a/splitio/conf/sdkconf.go +++ b/splitio/conf/sdkconf.go @@ -143,7 +143,7 @@ func Default() *SplitSdkConfig { SdkURL: "", StreamingServiceURL: "", TelemetryServiceURL: "", - HTTPTimeout: 0, + HTTPTimeout: defaultHTTPTimeout, ImpressionListener: nil, SegmentQueueSize: 500, SegmentWorkers: 10, diff --git a/splitio/engine/engine.go b/splitio/engine/engine.go index 01d2889d..a52a7495 100644 --- a/splitio/engine/engine.go +++ b/splitio/engine/engine.go @@ -7,6 +7,7 @@ import ( "github.com/splitio/go-client/v6/splitio/engine/evaluator/impressionlabels" "github.com/splitio/go-client/v6/splitio/engine/grammar" "github.com/splitio/go-client/v6/splitio/engine/hash" + "github.com/splitio/go-toolkit/v5/hasher" "github.com/splitio/go-toolkit/v5/logging" ) @@ -53,7 +54,7 @@ func (e *Engine) calculateBucket(algo int, bucketingKey string, seed int64) int var hashedKey uint32 switch algo { case grammar.SplitAlgoMurmur: - hashedKey = hash.Murmur3_32([]byte(bucketingKey), uint32(seed)) + hashedKey = hasher.Sum32WithSeed([]byte(bucketingKey), uint32(seed)) case grammar.SplitAlgoLegacy: fallthrough default: diff --git a/splitio/engine/engine_test.go b/splitio/engine/engine_test.go index e915dd00..56c3d7a4 100644 --- a/splitio/engine/engine_test.go +++ b/splitio/engine/engine_test.go @@ -10,13 +10,14 @@ import ( "github.com/splitio/go-client/v6/splitio/engine/grammar" "github.com/splitio/go-client/v6/splitio/engine/hash" "github.com/splitio/go-split-commons/v4/dtos" + "github.com/splitio/go-toolkit/v5/hasher" "github.com/splitio/go-toolkit/v5/logging" ) func TestProperHashFunctionIsUsed(t *testing.T) { eng := Engine{} - murmurHash := hash.Murmur3_32([]byte("SOME_TEST"), 12345) + murmurHash := hasher.Sum32WithSeed([]byte("SOME_TEST"), 12345) murmurBucket := int(math.Abs(float64(murmurHash%100)) + 1) if murmurBucket != eng.calculateBucket(2, "SOME_TEST", 12345) { t.Error("Incorrect hash!") @@ -32,7 +33,7 @@ func TestProperHashFunctionIsUsed(t *testing.T) { func TestProperHashFunctionIsUsedWithConstants(t *testing.T) { eng := Engine{} - murmurHash := hash.Murmur3_32([]byte("SOME_TEST"), 12345) + murmurHash := hasher.Sum32WithSeed([]byte("SOME_TEST"), 12345) murmurBucket := int(math.Abs(float64(murmurHash%100)) + 1) if murmurBucket != eng.calculateBucket(grammar.SplitAlgoMurmur, "SOME_TEST", 12345) { t.Error("Incorrect hash!") diff --git a/splitio/engine/grammar/matchers/boolean.go b/splitio/engine/grammar/matchers/boolean.go index 187d5f23..e5fb17a0 100644 --- a/splitio/engine/grammar/matchers/boolean.go +++ b/splitio/engine/grammar/matchers/boolean.go @@ -1,6 +1,7 @@ package matchers import ( + "fmt" "reflect" "strconv" "strings" @@ -16,7 +17,7 @@ type BooleanMatcher struct { func (m *BooleanMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { matchingKey, err := m.matchingKey(key, attributes) if err != nil { - m.logger.Error("BooleanMatcher: Couldn't parse matching key to a boolean") + m.logger.Warning(fmt.Sprintf("BooleanMatcher: %s", err.Error())) return false } diff --git a/splitio/engine/hash/murmur.go b/splitio/engine/hash/murmur.go deleted file mode 100644 index 01fb4b15..00000000 --- a/splitio/engine/hash/murmur.go +++ /dev/null @@ -1,66 +0,0 @@ -package hash - -// Murmur calculates the bucket for the key and seed provided using the legacy algorithm -// © Copyright 2014 Lawrence E. Bakst All Rights Reserved -// THIS SOURCE CODE IS THE PROPRIETARY INTELLECTUAL PROPERTY AND CONFIDENTIAL -// INFORMATION OF LAWRENCE E. BAKST AND IS PROTECTED UNDER U.S. AND -// INTERNATIONAL LAW. ANY USE OF THIS SOURCE CODE WITHOUT THE -// AUTHORIZATION OF LAWRENCE E. BAKST IS STRICTLY PROHIBITED. - -// This package implements the 32 bit version of the MurmurHash3 hash code. -// With the exception of the interface check, this version was developed independtly. -// However, the "spaolacci" implementation with it's bmixer interface is da bomb, although -// this version is slightly faster. -// -// https://en.wikipedia.org/wiki/MurmurHash -// https://github.com/spaolacci/murmur3 - -const ( - c1 uint32 = 0xcc9e2d51 - c2 uint32 = 0x1b873593 - r1 uint32 = 15 - r2 uint32 = 13 - m uint32 = 5 - n uint32 = 0xe6546b64 -) - -// Murmur3_32 returns the 32 bit hash of data given the seed. -// This is code is what I started with before I added the hash.Hash and hash.Hash32 interfaces. -func Murmur3_32(data []byte, seed uint32) uint32 { - hash := seed - nblocks := len(data) / 4 - for i := 0; i < nblocks; i++ { - // k := *(*uint32)(unsafe.Pointer(&data[i*4])) - k := uint32(data[i*4+0])<<0 | uint32(data[i*4+1])<<8 | uint32(data[i*4+2])<<16 | uint32(data[i*4+3])<<24 - k *= c1 - k = (k << r1) | (k >> (32 - r1)) - k *= c2 - hash ^= k - hash = ((hash<>(32-r2)))*m + n - } - - l := nblocks * 4 - k1 := uint32(0) - switch len(data) & 3 { - case 3: - k1 ^= uint32(data[l+2]) << 16 - fallthrough - case 2: - k1 ^= uint32(data[l+1]) << 8 - fallthrough - case 1: - k1 ^= uint32(data[l+0]) - k1 *= c1 - k1 = (k1 << r1) | (k1 >> (32 - r1)) - k1 *= c2 - hash ^= k1 - } - - hash ^= uint32(len(data)) - hash ^= hash >> 16 - hash *= 0x85ebca6b - hash ^= hash >> 13 - hash *= 0xc2b2ae35 - hash ^= hash >> 16 - return hash -} diff --git a/splitio/engine/hash/murmur_test.go b/splitio/engine/hash/murmur_test.go deleted file mode 100644 index a2dd793d..00000000 --- a/splitio/engine/hash/murmur_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package hash - -import ( - "bufio" - "encoding/csv" - "io" - "os" - "strconv" - "testing" -) - -func TestMurmurHashOnAlphanumericData(t *testing.T) { - inFile, _ := os.Open("../../../testdata/murmur3-sample-data-v2.csv") - defer inFile.Close() - - reader := csv.NewReader(bufio.NewReader(inFile)) - - var arr []string - var err error - line := 0 - for err != io.EOF { - line++ - arr, err = reader.Read() - if len(arr) < 4 { - continue // Skip empty lines - } - seed, _ := strconv.ParseInt(arr[0], 10, 32) - str := arr[1] - digest, _ := strconv.ParseUint(arr[2], 10, 32) - - calculated := Murmur3_32([]byte(str), uint32(seed)) - if calculated != uint32(digest) { - t.Errorf("%d: Murmur hash calculation failed for string %s. Should be %d and was %d", line, str, digest, calculated) - break - } - } -} - -func TestMurmurHashOnNonAlphanumericData(t *testing.T) { - inFile, _ := os.Open("../../../testdata/murmur3-sample-data-non-alpha-numeric-v2.csv") - defer inFile.Close() - - reader := csv.NewReader(bufio.NewReader(inFile)) - - var arr []string - var err error - line := 0 - for err != io.EOF { - line++ - arr, err = reader.Read() - if len(arr) < 4 { - continue // Skip empty lines - } - seed, _ := strconv.ParseInt(arr[0], 10, 32) - str := arr[1] - digest, _ := strconv.ParseUint(arr[2], 10, 32) - - calculated := Murmur3_32([]byte(str), uint32(seed)) - if calculated != uint32(digest) { - t.Errorf("%d: Murmur hash calculation failed for string %s. Should be %d and was %d", line, str, digest, calculated) - break - } - } -} diff --git a/splitio/version.go b/splitio/version.go index 93b77340..5b4c6860 100644 --- a/splitio/version.go +++ b/splitio/version.go @@ -1,4 +1,4 @@ package splitio // Version contains a string with the split sdk version -const Version = "6.1.6" +const Version = "6.1.8"