Skip to content

Commit

Permalink
added support to specVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelograno committed May 3, 2024
1 parent 877c5a6 commit edff2c1
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 33 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
version: 2

updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "splitio/sdk"
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go version
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.18.0'

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/update-license-year.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -24,7 +24,7 @@ jobs:
run: "echo PREVIOUS=$(($CURRENT-1)) >> $GITHUB_ENV"

- name: Update LICENSE
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@v3
with:
find: ${{ env.PREVIOUS }}
replace: ${{ env.CURRENT }}
Expand All @@ -38,7 +38,7 @@ jobs:
git commit -m "Updated License Year" -a
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: Update License Year
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/splitio/go-client/v6
go 1.18

require (
github.com/splitio/go-split-commons/v5 v5.1.1
github.com/splitio/go-toolkit/v5 v5.3.2
github.com/splitio/go-split-commons/v5 v5.2.2-0.20240503193749-9f5d15fc9441
github.com/splitio/go-toolkit/v5 v5.4.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/redis/go-redis/v9 v9.0.4 h1:FC82T+CHJ/Q/PdyLW++GeCO+Ol59Y4T7R4jbgjvktgc=
github.com/redis/go-redis/v9 v9.0.4/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/splitio/go-split-commons/v5 v5.1.1 h1:lLOqNQMdZA5Z7FBBh4YODWdE2QFgxSPMptX9ty14x4c=
github.com/splitio/go-split-commons/v5 v5.1.1/go.mod h1:9vAZrlhKvhensyRC11hyVFdgLIBrkX9D5vdYc9qB13w=
github.com/splitio/go-toolkit/v5 v5.3.2 h1:Yy9YBcHRmK5WVZjeA/klLGEdF38xpsL1ejnC3ro8a2M=
github.com/splitio/go-toolkit/v5 v5.3.2/go.mod h1:xYhUvV1gga9/1029Wbp5pjnR6Cy8nvBpjw99wAbsMko=
github.com/splitio/go-split-commons/v5 v5.2.2-0.20240503193749-9f5d15fc9441 h1:9Dp10MSERhK1vuKiCCN4m5S45Hpqpmh4nqpV0SgOgoY=
github.com/splitio/go-split-commons/v5 v5.2.2-0.20240503193749-9f5d15fc9441/go.mod h1:344KP05ULARzjRfnC4VtGSyu5l3kmIM375WUIzrURs0=
github.com/splitio/go-toolkit/v5 v5.4.0 h1:g5WFpRhQomnXCmvfsNOWV4s5AuUrWIZ+amM68G8NBKM=
github.com/splitio/go-toolkit/v5 v5.4.0/go.mod h1:xYhUvV1gga9/1029Wbp5pjnR6Cy8nvBpjw99wAbsMko=
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
github.com/twmb/murmur3 v1.1.6/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
Expand Down
6 changes: 1 addition & 5 deletions splitio/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ func (c *SplitClient) processResult(result evaluator.Results, operation string,

// doTreatmentsCall retrieves treatments of an specific array of feature flag names with configurations object if it is present for a certain key and set of attributes
func (c *SplitClient) doTreatmentsCall(key interface{}, featureFlagNames []string, attributes map[string]interface{}, operation string, metricsLabel string) (t map[string]TreatmentResult) {
treatments := make(map[string]TreatmentResult)

// Set up a guard deferred function to recover if the SDK starts panicking
defer func() {
if r := recover(); r != nil {
Expand Down Expand Up @@ -275,9 +273,7 @@ func (c *SplitClient) doTreatmentsCall(key interface{}, featureFlagNames []strin

evaluationsResult := c.getEvaluationsResult(matchingKey, bucketingKey, filteredFeatures, attributes, operation)

treatments = c.processResult(evaluationsResult, operation, bucketingKey, matchingKey, attributes, metricsLabel)

return treatments
return c.processResult(evaluationsResult, operation, bucketingKey, matchingKey, attributes, metricsLabel)
}

// doTreatmentsCallByFlagSets retrieves treatments of a specific array of feature flag names, that belong to flag sets, with configurations object if it is present for a certain key and set of attributes
Expand Down
11 changes: 6 additions & 5 deletions splitio/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ func compareListener(ilTest map[string]interface{}, f string, k string, l string
if ilTest["Version"] != v {
return false
}
if ilTest["InstanceName"] != i {
return false
}
attr1, _ := ilTest["Attributes"].(map[string]interface{})
return attr1["One"] == a
}
Expand Down Expand Up @@ -679,15 +682,14 @@ func getClientForListener() SplitClient {
}
func TestImpressionListener(t *testing.T) {
client := getClientForListener()
cfg := conf.Default()

attributes := make(map[string]interface{})
attributes["One"] = "test"

expectedTreatment(client.Treatment("user1", "feature", attributes), "TreatmentA", t)
expectedVersion := "go-" + splitio.Version

if !compareListener(ilResult["feature"].(map[string]interface{}), "feature", "user1", "aLabel", "TreatmentA", int64(123), "", "test", cfg.InstanceName, expectedVersion) {
if !compareListener(ilResult["feature"].(map[string]interface{}), "feature", "user1", "aLabel", "TreatmentA", int64(123), "", "test", "ip-123-123-123-123", expectedVersion) {
t.Error("Impression should match")
}
ilResult = make(map[string]interface{})
Expand All @@ -697,7 +699,6 @@ func TestImpressionListener(t *testing.T) {

func TestImpressionListenerForTreatments(t *testing.T) {
client := getClientForListener()
cfg := conf.Default()

attributes := make(map[string]interface{})
attributes["One"] = "test"
Expand All @@ -713,11 +714,11 @@ func TestImpressionListenerForTreatments(t *testing.T) {

expectedVersion := "go-" + splitio.Version

if !compareListener(ilResult["feature"].(map[string]interface{}), "feature", "user1", "aLabel", "TreatmentA", int64(123), "", "test", cfg.InstanceName, expectedVersion) {
if !compareListener(ilResult["feature"].(map[string]interface{}), "feature", "user1", "aLabel", "TreatmentA", int64(123), "", "test", "ip-123-123-123-123", expectedVersion) {
t.Error("Impression should match")
}

if !compareListener(ilResult["feature2"].(map[string]interface{}), "feature2", "user1", "bLabel", "TreatmentB", int64(123), "", "test", cfg.InstanceName, expectedVersion) {
if !compareListener(ilResult["feature2"].(map[string]interface{}), "feature2", "user1", "bLabel", "TreatmentB", int64(123), "", "test", "ip-123-123-123-123", expectedVersion) {
t.Error("Impression should match")
}
ilResult = make(map[string]interface{})
Expand Down
12 changes: 7 additions & 5 deletions splitio/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/splitio/go-split-commons/v5/provisional"
"github.com/splitio/go-split-commons/v5/provisional/strategy"
"github.com/splitio/go-split-commons/v5/service/api"
"github.com/splitio/go-split-commons/v5/service/api/specs"
"github.com/splitio/go-split-commons/v5/service/local"
"github.com/splitio/go-split-commons/v5/storage"
"github.com/splitio/go-split-commons/v5/storage/filter"
Expand Down Expand Up @@ -204,7 +205,7 @@ func (f *SplitFactory) subscribe(name int, subscriptor chan int) {
}

// removes a particular subscriptor from the list
func (f *SplitFactory) unsubscribe(name int, subscriptor chan int) {
func (f *SplitFactory) unsubscribe(name int) {
f.mutex.Lock()
defer f.mutex.Unlock()
_, ok := f.readinessSubscriptors[name]
Expand Down Expand Up @@ -233,7 +234,7 @@ func (f *SplitFactory) BlockUntilReady(timer int) error {
defer func() {
// Unsubscription will happen only if a block channel has been created
if block != nil {
f.unsubscribe(subscriptorName, block)
f.unsubscribe(subscriptorName)
close(block)
}
}()
Expand Down Expand Up @@ -287,6 +288,8 @@ func setupInMemoryFactory(
metadata dtos.Metadata,
) (*SplitFactory, error) {
advanced, warnings := conf.NormalizeSDKConf(cfg.Advanced)
advanced.AuthSpecVersion = specs.FLAG_V1_1
advanced.FlagsSpecVersion = specs.FLAG_V1_1
printWarnings(logger, warnings)
flagSetsInvalid := int64(len(cfg.Advanced.FlagSetsFilter) - len(advanced.FlagSetsFilter))
if strings.TrimSpace(cfg.SplitSyncProxyURL) != "" {
Expand Down Expand Up @@ -336,7 +339,7 @@ func setupInMemoryFactory(
cfg.ImpressionsMode = config.ImpressionsModeOptimized
}

impressionManager, err := buildImpressionManager(cfg, advanced, logger, true, &splitTasks, &workers, storages, metadata, splitAPI, nil)
impressionManager, err := buildImpressionManager(cfg, advanced, logger, true, &splitTasks, &workers, storages, metadata, splitAPI)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -430,7 +433,7 @@ func setupRedisFactory(apikey string, cfg *conf.SplitSdkConfig, logger logging.L
cfg.ImpressionsMode = config.ImpressionsModeDebug
}

impressionManager, err := buildImpressionManager(cfg, advanced, logger, false, &splitTasks, &workers, storages, metadata, nil, impressionStorage)
impressionManager, err := buildImpressionManager(cfg, advanced, logger, false, &splitTasks, &workers, storages, metadata, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -600,7 +603,6 @@ func buildImpressionManager(
storages sdkStorages,
metadata dtos.Metadata,
splitAPI *api.SplitAPI,
impressionRedisStorage storage.ImpressionStorageProducer,
) (provisional.ImpressionManager, error) {
listenerEnabled := cfg.Advanced.ImpressionListener != nil
switch cfg.ImpressionsMode {
Expand Down
5 changes: 2 additions & 3 deletions splitio/client/input_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,11 @@ func (i *inputValidation) validateTrackProperties(properties map[string]interfac
size := 1024 // Average event size is ~750 bytes. Using 1kbyte as a starting point.
for name, value := range properties {
size += len(name)
switch value.(type) {
switch value := value.(type) {
case int, int32, int64, uint, uint32, uint64, float32, float64, bool, nil:
processed[name] = value
case string:
asStr := value.(string)
size += len(asStr)
size += len(value)
processed[name] = value
default:
i.logger.Warning("Property %s is of invalid type. Setting value to nil")
Expand Down
5 changes: 2 additions & 3 deletions splitio/client/input_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/splitio/go-client/v6/splitio/conf"
commonsCfg "github.com/splitio/go-split-commons/v5/conf"
spConf "github.com/splitio/go-split-commons/v5/conf"
"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/flagsets"
"github.com/splitio/go-split-commons/v5/healthcheck/application"
Expand Down Expand Up @@ -359,7 +358,7 @@ func TestValidatorOnDestroy(t *testing.T) {
sync, _ := synchronizer.NewSynchronizerManager(
synchronizer.NewLocal(localConfig, &api.SplitAPI{}, mocks.MockSplitStorage{}, mocks.MockSegmentStorage{}, logger, telemetryMockedStorage, &application.Dummy{}),
logger,
spConf.AdvancedConfig{},
commonsCfg.AdvancedConfig{},
authMocks.MockAuthClient{},
mocks.MockSplitStorage{},
make(chan int, 1),
Expand Down Expand Up @@ -534,7 +533,7 @@ func TestInMemoryFactoryFlagSets(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/splitChanges":
if r.RequestURI != "/splitChanges?sets=a%2Cc%2Cd&since=-1" {
if r.RequestURI != "/splitChanges?s=1.1&since=-1&sets=a%2Cc%2Cd" {
t.Error("wrong RequestURI for flag sets")
}
fmt.Fprintln(w, fmt.Sprintf(string(splitsMock), splitMock))
Expand Down
2 changes: 1 addition & 1 deletion splitio/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package splitio

// Version contains a string with the split sdk version
const Version = "6.5.2"
const Version = "6.6.0-rc1"

0 comments on commit edff2c1

Please sign in to comment.