Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy support for splitchanges sepcs #272

Merged
merged 6 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "94c6f52"
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