Skip to content

Commit

Permalink
Merge pull request #159 from splitio/semver-matcher
Browse files Browse the repository at this point in the history
SDK semver matchers filter
  • Loading branch information
mmelograno authored May 14, 2024
2 parents 3d1c075 + e1253a2 commit 21bef6d
Show file tree
Hide file tree
Showing 197 changed files with 3,083 additions and 774 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"
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
6.0.0 (May 14, 2024)
- BREAKING CHANGE:
- Changed FetchOptions and Fetch API.
- Added support for targeting rules based on semantic versions (https://semver.org/).
- Added the logic to handle correctly when the SDK receives an unsupported Matcher type.

5.2.2 (Apr 26, 2024)
- Added split version filter to be used on semver matchers logic.

5.2.1 (Jan 25, 2024)
- Implemented GetAllFlagSetNames method that returns all flag set names
- Updated GetAllSplitKeys method to use scan command instead of keys.
Expand Down
2 changes: 2 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ type AdvancedConfig struct {
SplitsRefreshRate int
SegmentsRefreshRate int
FlagSetsFilter []string
AuthSpecVersion string
FlagsSpecVersion string
}
7 changes: 7 additions & 0 deletions dtos/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type MatcherDTO struct {
Whitelist *WhitelistMatcherDataDTO `json:"whitelistMatcherData"`
UnaryNumeric *UnaryNumericMatcherDataDTO `json:"unaryNumericMatcherData"`
Between *BetweenMatcherDataDTO `json:"betweenMatcherData"`
BetweenString *BetweenStringMatcherDataDTO `json:"betweenStringMatcherData"`
Dependency *DependencyMatcherDataDTO `json:"dependencyMatcherData"`
Boolean *bool `json:"booleanMatcherData"`
String *string `json:"stringMatcherData"`
Expand All @@ -77,6 +78,12 @@ type BetweenMatcherDataDTO struct {
End int64 `json:"end"`
}

// BetweenStringMatcherDataDTO structure to map a Matcher definition fetched from JSON message.
type BetweenStringMatcherDataDTO struct {
Start *string `json:"start"`
End *string `json:"end"`
}

// UnaryNumericMatcherDataDTO structure to map a Matcher definition fetched from JSON message.
type UnaryNumericMatcherDataDTO struct {
DataType string `json:"dataType"` //NUMBER or DATETIME
Expand Down
6 changes: 3 additions & 3 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"math"

"github.com/splitio/go-split-commons/v5/engine/evaluator/impressionlabels"
"github.com/splitio/go-split-commons/v5/engine/grammar"
"github.com/splitio/go-split-commons/v5/engine/hash"
"github.com/splitio/go-split-commons/v6/engine/evaluator/impressionlabels"
"github.com/splitio/go-split-commons/v6/engine/grammar"
"github.com/splitio/go-split-commons/v6/engine/hash"

"github.com/splitio/go-toolkit/v5/hasher"
"github.com/splitio/go-toolkit/v5/logging"
Expand Down
6 changes: 3 additions & 3 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"os"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/engine/grammar"
"github.com/splitio/go-split-commons/v5/engine/hash"
"github.com/splitio/go-split-commons/v6/dtos"
"github.com/splitio/go-split-commons/v6/engine/grammar"
"github.com/splitio/go-split-commons/v6/engine/hash"

"github.com/splitio/go-toolkit/v5/hasher"
"github.com/splitio/go-toolkit/v5/logging"
Expand Down
10 changes: 5 additions & 5 deletions engine/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"time"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/engine"
"github.com/splitio/go-split-commons/v5/engine/evaluator/impressionlabels"
"github.com/splitio/go-split-commons/v5/engine/grammar"
"github.com/splitio/go-split-commons/v5/storage"
"github.com/splitio/go-split-commons/v6/dtos"
"github.com/splitio/go-split-commons/v6/engine"
"github.com/splitio/go-split-commons/v6/engine/evaluator/impressionlabels"
"github.com/splitio/go-split-commons/v6/engine/grammar"
"github.com/splitio/go-split-commons/v6/storage"

"github.com/splitio/go-toolkit/v5/injection"
"github.com/splitio/go-toolkit/v5/logging"
Expand Down
8 changes: 4 additions & 4 deletions engine/evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package evaluator
import (
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/flagsets"
"github.com/splitio/go-split-commons/v5/storage/inmemory/mutexmap"
"github.com/splitio/go-split-commons/v5/storage/mocks"
"github.com/splitio/go-split-commons/v6/dtos"
"github.com/splitio/go-split-commons/v6/flagsets"
"github.com/splitio/go-split-commons/v6/storage/inmemory/mutexmap"
"github.com/splitio/go-split-commons/v6/storage/mocks"

"github.com/splitio/go-toolkit/v5/datastructures/set"
"github.com/splitio/go-toolkit/v5/logging"
Expand Down
3 changes: 3 additions & 0 deletions engine/evaluator/impressionlabels/impression_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ const Exception = "exception"

// ClientNotReady label will be returned when the client is not ready
const ClientNotReady = "not ready"

// UnsupportedMatcherType label will be returned when a matcher is not supported
const UnsupportedMatcherType = "targeting rule type unsupported by sdk"
2 changes: 1 addition & 1 deletion engine/evaluator/mocks/mocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mocks

import "github.com/splitio/go-split-commons/v5/engine/evaluator"
import "github.com/splitio/go-split-commons/v6/engine/evaluator"

// MockEvaluator mock evaluator
type MockEvaluator struct {
Expand Down
33 changes: 24 additions & 9 deletions engine/grammar/condition.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package grammar

import (
"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/engine/grammar/matchers"
"github.com/splitio/go-split-commons/v6/dtos"
"github.com/splitio/go-split-commons/v6/engine/grammar/matchers"
"github.com/splitio/go-split-commons/v6/engine/grammar/matchers/datatypes"
"github.com/splitio/go-toolkit/v5/injection"
"github.com/splitio/go-toolkit/v5/logging"
)
Expand All @@ -17,17 +18,15 @@ type Condition struct {
}

// NewCondition instantiates a new Condition struct with appropriate wrappers around dtos and returns it.
func NewCondition(cond *dtos.ConditionDTO, ctx *injection.Context, logger logging.LoggerInterface) *Condition {
func NewCondition(cond *dtos.ConditionDTO, ctx *injection.Context, logger logging.LoggerInterface) (*Condition, error) {
partitions := make([]Partition, 0)
for _, part := range cond.Partitions {
partitions = append(partitions, Partition{partitionData: part})
}
matcherObjs := make([]matchers.MatcherInterface, 0)
for _, matcher := range cond.MatcherGroup.Matchers {
m, err := matchers.BuildMatcher(&matcher, ctx, logger)
if err == nil {
matcherObjs = append(matcherObjs, m)
}
matcherObjs, err := processMatchers(cond.MatcherGroup.Matchers, ctx, logger)
if err != nil {
// At this point the only error forwarded is UnsupportedMatcherError
return nil, err
}

return &Condition{
Expand All @@ -36,7 +35,23 @@ func NewCondition(cond *dtos.ConditionDTO, ctx *injection.Context, logger loggin
partitions: partitions,
label: cond.Label,
conditionType: cond.ConditionType,
}, nil
}

func processMatchers(condMatchers []dtos.MatcherDTO, ctx *injection.Context, logger logging.LoggerInterface) ([]matchers.MatcherInterface, error) {
matcherObjs := make([]matchers.MatcherInterface, 0)
for _, matcher := range condMatchers {
m, err := matchers.BuildMatcher(&matcher, ctx, logger)
if err == nil {
matcherObjs = append(matcherObjs, m)
} else {
logger.Debug("error in BuildMatcher, reason: ", err.Error())
if _, ok := err.(datatypes.UnsupportedMatcherError); ok {
return nil, err
}
}
}
return matcherObjs, nil
}

// Partition struct with added logic that wraps around a DTO
Expand Down
106 changes: 103 additions & 3 deletions engine/grammar/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package grammar
import (
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"
"github.com/splitio/go-split-commons/v6/engine/grammar/matchers"
"github.com/splitio/go-split-commons/v6/engine/grammar/matchers/datatypes"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down Expand Up @@ -46,7 +48,11 @@ func TestConditionWrapperObject(t *testing.T) {
},
}

wrapped := NewCondition(&condition1, nil, logger)
wrapped, err := NewCondition(&condition1, nil, logger)

if err != nil {
t.Error("err should be nil")
}

if wrapped.Label() != "Label1" {
t.Error("Label not set properly")
Expand Down Expand Up @@ -113,7 +119,10 @@ func TestAnotherWrapper(t *testing.T) {
},
}

wrapped := NewCondition(&condition1, nil, logger)
wrapped, err := NewCondition(&condition1, nil, logger)
if err != nil {
t.Error("err should be nil")
}

if wrapped.Label() != "Label2" {
t.Error("Label not set properly")
Expand Down Expand Up @@ -141,3 +150,94 @@ func TestAnotherWrapper(t *testing.T) {
t.Error("CalculateTreatment returned incorrect treatment")
}
}

func TestConditionUnsupportedMatcherWrapperObject(t *testing.T) {
logger := logging.NewLogger(&logging.LoggerOptions{})
condition1 := dtos.ConditionDTO{
ConditionType: "WHITELIST",
Label: "Label1",
MatcherGroup: dtos.MatcherGroupDTO{
Combiner: "AND",
Matchers: []dtos.MatcherDTO{
{
Negate: false,
MatcherType: "UNSUPPORTED",
KeySelector: &dtos.KeySelectorDTO{
Attribute: nil,
TrafficType: "something",
},
},
{
Negate: true,
MatcherType: "ALL_KEYS",
KeySelector: &dtos.KeySelectorDTO{
Attribute: nil,
TrafficType: "something",
},
},
},
},
Partitions: []dtos.PartitionDTO{
{
Size: 75,
Treatment: "on",
},
{
Size: 25,
Treatment: "off",
},
},
}

_, err := NewCondition(&condition1, nil, logger)

if err == nil {
t.Error("err should not be nil")
}

if _, ok := err.(datatypes.UnsupportedMatcherError); !ok {
t.Error("err should be UnsupportedMatcherError")
}
}

func TestConditionMatcherWithNilStringWrapperObject(t *testing.T) {
logger := logging.NewLogger(&logging.LoggerOptions{})
condition1 := dtos.ConditionDTO{
ConditionType: "WHITELIST",
Label: "Label1",
MatcherGroup: dtos.MatcherGroupDTO{
Combiner: "AND",
Matchers: []dtos.MatcherDTO{
{
Negate: false,
MatcherType: matchers.MatcherTypeStartsWith,
KeySelector: &dtos.KeySelectorDTO{
Attribute: nil,
TrafficType: "something",
},
Whitelist: nil,
},
},
},
Partitions: []dtos.PartitionDTO{
{
Size: 75,
Treatment: "on",
},
{
Size: 25,
Treatment: "off",
},
},
}

condition, err := NewCondition(&condition1, nil, logger)

if err != nil {
t.Error("err should be nil")
}

if len(condition.matchers) != 0 {
t.Error("matchers should be empty")
}
}
2 changes: 1 addition & 1 deletion engine/grammar/matchers/allkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down
2 changes: 1 addition & 1 deletion engine/grammar/matchers/allofset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down
2 changes: 1 addition & 1 deletion engine/grammar/matchers/anyofset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down
2 changes: 1 addition & 1 deletion engine/grammar/matchers/between.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"reflect"

"github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes"
"github.com/splitio/go-split-commons/v6/engine/grammar/matchers/datatypes"
)

// BetweenMatcher will match if two numbers or two datetimes are equal
Expand Down
2 changes: 1 addition & 1 deletion engine/grammar/matchers/between_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down
2 changes: 1 addition & 1 deletion engine/grammar/matchers/boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down
2 changes: 1 addition & 1 deletion engine/grammar/matchers/contains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v6/dtos"

"github.com/splitio/go-toolkit/v5/logging"
)
Expand Down
Loading

0 comments on commit 21bef6d

Please sign in to comment.