From 7149fa2c4b57d16dc5e660195afadb2e39f4effe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Mon, 20 Nov 2023 13:22:56 +0100 Subject: [PATCH 1/4] Revert "upgrade: 4.0.0 release (#147)" This reverts commit 0efdcc8d2b5707fec2fde8fcb7df0bffe1fb85a2. --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 837cae6..dadabc4 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ import ( const ( deprecatedSuffix = "/features" clientName = "unleash-client-go" - clientVersion = "4.0.0" + clientVersion = "4.0.0-beta.1" ) var defaultStrategies = []strategy.Strategy{ From 136d193bd9b8bc6a57582219b494af86ec180238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Mon, 20 Nov 2023 13:22:59 +0100 Subject: [PATCH 2/4] Revert "fix: new variant hashing (#145)" This reverts commit b86393806c9e30c385eb440d90cf66e43b478b8b. --- .github/workflows/build.yml | 2 +- api/feature.go | 9 +++++++-- api/variant_test.go | 6 +++--- client.go | 2 +- internal/strategies/flexible_rollout.go | 2 +- internal/strategies/gradual_rollout_session_id.go | 2 +- .../strategies/gradual_rollout_session_id_test.go | 4 ++-- internal/strategies/gradual_rollout_user_id.go | 2 +- .../strategies/gradual_rollout_user_id_test.go | 4 ++-- internal/strategies/helpers.go | 12 +++--------- internal/strategies/helpers_test.go | 15 +++++---------- 11 files changed, 27 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9f1f2c..95aab20 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: name: Checkout client specifications with: repository: Unleash/client-specification - ref: refs/tags/v5.0.2 + ref: refs/tags/v4.5.2 path: testdata/client-specification - uses: actions/setup-go@v2 name: Setup go diff --git a/api/feature.go b/api/feature.go index 58cbbfa..085d4bb 100644 --- a/api/feature.go +++ b/api/feature.go @@ -1,12 +1,13 @@ package api import ( + "fmt" "math/rand" "strconv" "time" "github.com/Unleash/unleash-client-go/v3/context" - "github.com/Unleash/unleash-client-go/v3/internal/strategies" + "github.com/twmb/murmur3" ) type ParameterMap map[string]interface{} @@ -104,7 +105,7 @@ func (vc VariantCollection) getVariantFromWeights(ctx *context.Context) *Variant } stickiness := vc.Variants[0].Stickiness - target := strategies.NormalizedVariantValue(getSeed(ctx, stickiness), vc.GroupId, totalWeight, strategies.VariantNormalizationSeed) + target := getNormalizedNumber(getSeed(ctx, stickiness), vc.GroupId, totalWeight) counter := uint32(0) for _, variant := range vc.Variants { counter += uint32(variant.Weight) @@ -147,3 +148,7 @@ func getSeed(ctx *context.Context, stickiness string) string { } return strconv.Itoa(rand.Intn(10000)) } + +func getNormalizedNumber(identifier, groupId string, normalizer int) uint32 { + return (murmur3.Sum32([]byte(fmt.Sprintf("%s:%s", groupId, identifier))) % uint32(normalizer)) + 1 +} diff --git a/api/variant_test.go b/api/variant_test.go index 2bce29d..47c6761 100644 --- a/api/variant_test.go +++ b/api/variant_test.go @@ -221,7 +221,7 @@ func (suite *VariantTestSuite) TestGetVariant_ShouldReturnVarD() { GroupId: mockFeature.Name, Variants: mockFeature.Variants, }.GetVariant(mockContext) - suite.Equal("VarE", variantSetup.Name, "Should return VarE") + suite.Equal("VarD", variantSetup.Name, "Should return VarD") suite.Equal(true, variantSetup.Enabled, "Should be equal") } @@ -238,7 +238,7 @@ func (suite *VariantTestSuite) TestGetVariant_ShouldReturnVarE() { GroupId: mockFeature.Name, Variants: mockFeature.Variants, }.GetVariant(mockContext) - suite.Equal("VarF", variantSetup.Name, "Should return VarF") + suite.Equal("VarE", variantSetup.Name, "Should return VarE") suite.Equal(true, variantSetup.Enabled, "Should be equal") } @@ -255,7 +255,7 @@ func (suite *VariantTestSuite) TestGetVariant_ShouldReturnVarF() { GroupId: mockFeature.Name, Variants: mockFeature.Variants, }.GetVariant(mockContext) - suite.Equal("VarE", variantSetup.Name, "Should return VarE") + suite.Equal("VarF", variantSetup.Name, "Should return VarF") suite.Equal(true, variantSetup.Enabled, "Should be equal") } diff --git a/client.go b/client.go index dadabc4..a2190eb 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ import ( const ( deprecatedSuffix = "/features" clientName = "unleash-client-go" - clientVersion = "4.0.0-beta.1" + clientVersion = "3.9.0" ) var defaultStrategies = []strategy.Strategy{ diff --git a/internal/strategies/flexible_rollout.go b/internal/strategies/flexible_rollout.go index e07ad90..5d2cebb 100644 --- a/internal/strategies/flexible_rollout.go +++ b/internal/strategies/flexible_rollout.go @@ -62,6 +62,6 @@ func (s flexibleRolloutStrategy) IsEnabled(params map[string]interface{}, ctx *c return false } - normalizedID := normalizedRolloutValue(stickinessID, groupID) + normalizedID := normalizedValue(stickinessID, groupID) return percentage > 0 && float64(normalizedID) <= percentage } diff --git a/internal/strategies/gradual_rollout_session_id.go b/internal/strategies/gradual_rollout_session_id.go index 66536bc..18541d9 100644 --- a/internal/strategies/gradual_rollout_session_id.go +++ b/internal/strategies/gradual_rollout_session_id.go @@ -38,7 +38,7 @@ func (s gradualRolloutSessionId) IsEnabled(params map[string]interface{}, ctx *c return false } - normalizedId := normalizedRolloutValue(ctx.SessionId, groupId) + normalizedId := normalizedValue(ctx.SessionId, groupId) return percentage > 0.0 && float64(normalizedId) <= percentage } diff --git a/internal/strategies/gradual_rollout_session_id_test.go b/internal/strategies/gradual_rollout_session_id_test.go index 6cc9744..b402872 100644 --- a/internal/strategies/gradual_rollout_session_id_test.go +++ b/internal/strategies/gradual_rollout_session_id_test.go @@ -42,7 +42,7 @@ func TestGradualRolloutSessionId_IsEnabled(t *testing.T) { t.Run("p1=p2", func(t *testing.T) { sessionId := "123123" groupId := "group1" - percentage := normalizedRolloutValue(sessionId, groupId) + percentage := normalizedValue(sessionId, groupId) params := map[string]interface{}{ strategy.ParamPercentage: percentage, @@ -57,7 +57,7 @@ func TestGradualRolloutSessionId_IsEnabled(t *testing.T) { t.Run("p1 0.0 && float64(normalizedId) <= percentage } diff --git a/internal/strategies/gradual_rollout_user_id_test.go b/internal/strategies/gradual_rollout_user_id_test.go index 8674796..ac8cadf 100644 --- a/internal/strategies/gradual_rollout_user_id_test.go +++ b/internal/strategies/gradual_rollout_user_id_test.go @@ -43,7 +43,7 @@ func TestGradualRolloutUserId_IsEnabled(t *testing.T) { t.Run("p1=p2", func(t *testing.T) { userId := "123123" groupId := "group1" - percentage := normalizedRolloutValue(userId, groupId) + percentage := normalizedValue(userId, groupId) params := map[string]interface{}{ strategy.ParamPercentage: percentage, @@ -58,7 +58,7 @@ func TestGradualRolloutUserId_IsEnabled(t *testing.T) { t.Run("p1 Date: Mon, 20 Nov 2023 13:49:29 +0100 Subject: [PATCH 3/4] Update version --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index a2190eb..7e6160e 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ import ( const ( deprecatedSuffix = "/features" clientName = "unleash-client-go" - clientVersion = "3.9.0" + clientVersion = "3.9.1" ) var defaultStrategies = []strategy.Strategy{ From 92bcbeb3c2ebb03d7a2d9b2a7b10a98df3001044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Tue, 21 Nov 2023 15:52:24 +0100 Subject: [PATCH 4/4] Don't wait 10 minutes to fail on timeout --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 95aab20..802b75a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,7 @@ jobs: - name: Go vet run: go vet ./... - name: Run all tests + timeout-minutes: 1 run: go test -race -covermode atomic -coverprofile=profile.cov -v ./... - name: Send coverage uses: shogo82148/actions-goveralls@v1