Skip to content

Commit

Permalink
Merge branch 'semver' of github.com:splitio/split-synchronizer into s…
Browse files Browse the repository at this point in the history
…pec-version
  • Loading branch information
ldecheverz-split committed May 2, 2024
2 parents d2d839f + 8cba4a9 commit 5909b59
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 34 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUu
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -138,8 +138,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -149,8 +149,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
2 changes: 1 addition & 1 deletion splitio/commitversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ This file is created automatically, please do not edit
*/

// CommitVersion is the version of the last commit previous to release
const CommitVersion = "765bffc"
const CommitVersion = "59410e1"
30 changes: 16 additions & 14 deletions splitio/proxy/caching/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,25 @@ func MakeProxyCache() *gincache.Middleware {
return gincache.New(&gincache.Options{
SuccessfulOnly: true, // we're not interested in caching non-200 responses
Size: cacheSize,
KeyFactory: func(ctx *gin.Context) string {

var encodingPrefix string
if strings.Contains(ctx.Request.Header.Get("Accept-Encoding"), "gzip") {
encodingPrefix = "gzip::"
}

if strings.HasPrefix(ctx.Request.URL.Path, "/api/auth") || strings.HasPrefix(ctx.Request.URL.Path, "/api/v2/auth") {
// For auth requests, since we don't support streaming yet, we only need a single entry in the table,
// so we strip the query-string which contains the user-list
return encodingPrefix + ctx.Request.URL.Path
}
return encodingPrefix + ctx.Request.URL.Path + ctx.Request.URL.RawQuery
},
KeyFactory: keyFactoryFN,
// we make each request handler responsible for generating the surrogates.
// this way we can use segment names as surrogates for mysegments & segment changes
// with a lot less work
SurrogateFactory: func(ctx *gin.Context) []string { return ctx.GetStringSlice(SurrogateContextKey) },
})
}

func keyFactoryFN(ctx *gin.Context) string {

var encodingPrefix string
if strings.Contains(ctx.Request.Header.Get("Accept-Encoding"), "gzip") {
encodingPrefix = "gzip::"
}

if strings.HasPrefix(ctx.Request.URL.Path, "/api/auth") || strings.HasPrefix(ctx.Request.URL.Path, "/api/v2/auth") {
// For auth requests, since we don't support streaming yet, we only need a single entry in the table,
// so we strip the query-string which contains the user-list
return encodingPrefix + ctx.Request.URL.Path
}
return encodingPrefix + ctx.Request.URL.Path + ctx.Request.URL.RawQuery
}
14 changes: 14 additions & 0 deletions splitio/proxy/caching/caching_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package caching

import (
"net/http"
"net/url"
"testing"

"github.com/gin-gonic/gin"
"github.com/splitio/go-split-commons/v5/dtos"
"github.com/stretchr/testify/assert"
)

func TestCacheKeysDoNotOverlap(t *testing.T) {

url1, _ := url.Parse("http://proxy.split.io/api/spitChanges?since=-1")
c1 := &gin.Context{Request: &http.Request{URL: url1}}

url2, _ := url.Parse("http://proxy.split.io/api/spitChanges?s=1.1&since=-1")
c2 := &gin.Context{Request: &http.Request{URL: url2}}

assert.NotEqual(t, keyFactoryFN(c1), keyFactoryFN(c2))
}

func TestSegmentSurrogates(t *testing.T) {
assert.Equal(t, segmentPrefix+"segment1", MakeSurrogateForSegmentChanges("segment1"))
assert.NotEqual(t, MakeSurrogateForSegmentChanges("segment1"), MakeSurrogateForSegmentChanges("segment2"))
Expand Down
34 changes: 34 additions & 0 deletions splitio/proxy/controllers/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (

"github.com/gin-gonic/gin"
"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/grammar/matchers"
"github.com/splitio/go-split-commons/v5/service"
"github.com/splitio/go-split-commons/v5/service/api/specs"
"github.com/splitio/go-toolkit/v5/logging"
"golang.org/x/exp/slices"

Expand All @@ -18,13 +21,18 @@ import (
"github.com/splitio/split-synchronizer/v5/splitio/proxy/storage"
)

const (
labelUnsupportedMatcher = "targeting rule type unsupported by sdk"
)

// SdkServerController bundles all request handler for sdk-server apis
type SdkServerController struct {
logger logging.LoggerInterface
fetcher service.SplitFetcher
proxySplitStorage storage.ProxySplitStorage
proxySegmentStorage storage.ProxySegmentStorage
fsmatcher flagsets.FlagSetMatcher
versionFilter specs.SplitVersionFilter
}

// NewSdkServerController instantiates a new sdk server controller
Expand All @@ -42,6 +50,7 @@ func NewSdkServerController(
proxySplitStorage: proxySplitStorage,
proxySegmentStorage: proxySegmentStorage,
fsmatcher: fsmatcher,
versionFilter: specs.NewSplitVersionFilter(),
}
}

Expand Down Expand Up @@ -77,6 +86,13 @@ func (c *SdkServerController) SplitChanges(ctx *gin.Context) {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

spec, _ := ctx.GetQuery("s")
if spec != specs.FLAG_V1_1 {
spec = specs.FLAG_V1_0
}
splits.Splits = c.patchUnsupportedMatchers(splits.Splits, spec)

ctx.JSON(http.StatusOK, splits)
ctx.Set(caching.SurrogateContextKey, []string{caching.SplitSurrogate})
ctx.Set(caching.StickyContextKey, true)
Expand Down Expand Up @@ -143,3 +159,21 @@ func (c *SdkServerController) fetchSplitChangesSince(since int64, sets []string)
fetchOptions := service.MakeFlagRequestParams().WithChangeNumber(since).WithFlagSetsFilter(strings.Join(sets, ",")) // at this point the sets have been sanitized & sorted
return c.fetcher.Fetch(fetchOptions)
}

func (c *SdkServerController) patchUnsupportedMatchers(splits []dtos.SplitDTO, version string) []dtos.SplitDTO {
for si := range splits {
for ci := range splits[si].Conditions {
for mi := range splits[si].Conditions[ci].MatcherGroup.Matchers {
if c.versionFilter.ShouldFilter(splits[si].Conditions[ci].MatcherGroup.Matchers[mi].MatcherType, version) {
splits[si].Conditions[ci].ConditionType = grammar.ConditionTypeWhitelist
splits[si].Conditions[ci].MatcherGroup.Matchers[mi].MatcherType = matchers.MatcherTypeAllKeys
splits[si].Conditions[ci].MatcherGroup.Matchers[mi].String = nil
splits[si].Conditions[ci].Label = labelUnsupportedMatcher
splits[si].Conditions[ci].Partitions = []dtos.PartitionDTO{{Treatment: "control", Size: 100}}
}
}
}
}

return splits
}
Loading

0 comments on commit 5909b59

Please sign in to comment.