From 2a8801b64f44cb6f6bb9f02787ac1af97899d64b Mon Sep 17 00:00:00 2001 From: Lucas Echeverz Date: Fri, 26 Apr 2024 11:40:19 -0300 Subject: [PATCH 01/56] SDK semver matchers filter --- CHANGES | 3 +++ engine/grammar/matchers/matchers.go | 10 +++++++++ sdk/specs/splitversionfilter.go | 33 ++++++++++++++++++++++++++++ sdk/specs/splitversionfilter_test.go | 24 ++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 sdk/specs/splitversionfilter.go create mode 100644 sdk/specs/splitversionfilter_test.go diff --git a/CHANGES b/CHANGES index dc1f42f0..d6fa8c17 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +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. diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index ee7e8813..306c61b1 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -45,6 +45,16 @@ const ( MatcherTypeEqualToBoolean = "EQUAL_TO_BOOLEAN" // MatcherTypeMatchesString string value MatcherTypeMatchesString = "MATCHES_STRING" + // MatcherEqualToSemver string value + MatcherEqualToSemver = "EQUAL_TO_SEMVER" + // MatcherTypeGreaterThanOrEqualToSemver string value + MatcherTypeGreaterThanOrEqualToSemver = "GREATER_THAN_OR_EQUAL_TO_SEMVER" + // MatcherTypeLessThanOrEqualToSemver string value + MatcherTypeLessThanOrEqualToSemver = "LESS_THAN_OR_EQUAL_TO_SEMVER" + // MatcherTypeBetweenSemver string value + MatcherTypeBetweenSemver = "BETWEEN_SEMVER" + // MatcherTypeInListSemver string value + MatcherTypeInListSemver = "IN_LIST_SEMVER" ) // MatcherInterface should be implemented by all matchers diff --git a/sdk/specs/splitversionfilter.go b/sdk/specs/splitversionfilter.go new file mode 100644 index 00000000..eac705c9 --- /dev/null +++ b/sdk/specs/splitversionfilter.go @@ -0,0 +1,33 @@ +package specs + +import "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" + +const ( + v1 = "1.0" +) + +type SplitVersionFilter struct { + excluded map[mkey]struct{} +} + +type mkey struct { + api string + matcher string +} + +func NewSplitVersionFilter() SplitVersionFilter { + matchersToExclude := map[mkey]struct{}{ + mkey{v1, matchers.MatcherEqualToSemver}: {}, + mkey{v1, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, + mkey{v1, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, + mkey{v1, matchers.MatcherTypeBetweenSemver}: {}, + mkey{v1, matchers.MatcherTypeInListSemver}: {}, + } + + return SplitVersionFilter{excluded: matchersToExclude} +} + +func (s *SplitVersionFilter) ShouldFilter(matcher string, apiVersion string) bool { + _, ok := s.excluded[mkey{apiVersion, matcher}] + return ok +} diff --git a/sdk/specs/splitversionfilter_test.go b/sdk/specs/splitversionfilter_test.go new file mode 100644 index 00000000..5e195ae2 --- /dev/null +++ b/sdk/specs/splitversionfilter_test.go @@ -0,0 +1,24 @@ +package specs + +import ( + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" + "testing" +) + +func Test_splitVersionFilter(t *testing.T) { + filter := NewSplitVersionFilter() + shouldFilter := filter.ShouldFilter(matchers.MatcherTypeBetweenSemver, "1.0") + if !shouldFilter { + t.Error("It should filtered") + } + + shouldFilter = filter.ShouldFilter(matchers.MatcherTypeEqualTo, "1.0") + if shouldFilter { + t.Error("It should not filtered") + } + + shouldFilter = filter.ShouldFilter(matchers.MatcherTypeBetweenSemver, "1.1") + if shouldFilter { + t.Error("It should not filtered") + } +} From cb5c97951bfe9c60f9c8c6e63d7a69d2ccc58fc6 Mon Sep 17 00:00:00 2001 From: Lucas Echeverz Date: Fri, 26 Apr 2024 15:40:20 -0300 Subject: [PATCH 02/56] Adding spec versions --- sdk/specs/specversion.go | 6 ++++++ sdk/specs/splitversionfilter.go | 14 +++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 sdk/specs/specversion.go diff --git a/sdk/specs/specversion.go b/sdk/specs/specversion.go new file mode 100644 index 00000000..a4af5bed --- /dev/null +++ b/sdk/specs/specversion.go @@ -0,0 +1,6 @@ +package specs + +const ( + V0 = "1.0" + V1 = "1.1" +) diff --git a/sdk/specs/splitversionfilter.go b/sdk/specs/splitversionfilter.go index eac705c9..d10d8aca 100644 --- a/sdk/specs/splitversionfilter.go +++ b/sdk/specs/splitversionfilter.go @@ -2,10 +2,6 @@ package specs import "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" -const ( - v1 = "1.0" -) - type SplitVersionFilter struct { excluded map[mkey]struct{} } @@ -17,11 +13,11 @@ type mkey struct { func NewSplitVersionFilter() SplitVersionFilter { matchersToExclude := map[mkey]struct{}{ - mkey{v1, matchers.MatcherEqualToSemver}: {}, - mkey{v1, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, - mkey{v1, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, - mkey{v1, matchers.MatcherTypeBetweenSemver}: {}, - mkey{v1, matchers.MatcherTypeInListSemver}: {}, + mkey{V0, matchers.MatcherEqualToSemver}: {}, + mkey{V0, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, + mkey{V0, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, + mkey{V0, matchers.MatcherTypeBetweenSemver}: {}, + mkey{V0, matchers.MatcherTypeInListSemver}: {}, } return SplitVersionFilter{excluded: matchersToExclude} From 77f3af03a811967844e3dc675adab9842334ba93 Mon Sep 17 00:00:00 2001 From: Lucas Echeverz Date: Fri, 26 Apr 2024 15:44:53 -0300 Subject: [PATCH 03/56] Change consts names --- sdk/specs/specversion.go | 4 ++-- sdk/specs/splitversionfilter.go | 10 +++++----- sdk/specs/splitversionfilter_test.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/specs/specversion.go b/sdk/specs/specversion.go index a4af5bed..15aa429e 100644 --- a/sdk/specs/specversion.go +++ b/sdk/specs/specversion.go @@ -1,6 +1,6 @@ package specs const ( - V0 = "1.0" - V1 = "1.1" + FLAG_V1_0 = "1.0" + FLAG_V1_1 = "1.1" ) diff --git a/sdk/specs/splitversionfilter.go b/sdk/specs/splitversionfilter.go index d10d8aca..974a466e 100644 --- a/sdk/specs/splitversionfilter.go +++ b/sdk/specs/splitversionfilter.go @@ -13,11 +13,11 @@ type mkey struct { func NewSplitVersionFilter() SplitVersionFilter { matchersToExclude := map[mkey]struct{}{ - mkey{V0, matchers.MatcherEqualToSemver}: {}, - mkey{V0, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, - mkey{V0, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, - mkey{V0, matchers.MatcherTypeBetweenSemver}: {}, - mkey{V0, matchers.MatcherTypeInListSemver}: {}, + mkey{FLAG_V1_0, matchers.MatcherEqualToSemver}: {}, + mkey{FLAG_V1_0, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, + mkey{FLAG_V1_0, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, + mkey{FLAG_V1_0, matchers.MatcherTypeBetweenSemver}: {}, + mkey{FLAG_V1_0, matchers.MatcherTypeInListSemver}: {}, } return SplitVersionFilter{excluded: matchersToExclude} diff --git a/sdk/specs/splitversionfilter_test.go b/sdk/specs/splitversionfilter_test.go index 5e195ae2..f7503dd2 100644 --- a/sdk/specs/splitversionfilter_test.go +++ b/sdk/specs/splitversionfilter_test.go @@ -7,17 +7,17 @@ import ( func Test_splitVersionFilter(t *testing.T) { filter := NewSplitVersionFilter() - shouldFilter := filter.ShouldFilter(matchers.MatcherTypeBetweenSemver, "1.0") + shouldFilter := filter.ShouldFilter(matchers.MatcherTypeBetweenSemver, FLAG_V1_0) if !shouldFilter { t.Error("It should filtered") } - shouldFilter = filter.ShouldFilter(matchers.MatcherTypeEqualTo, "1.0") + shouldFilter = filter.ShouldFilter(matchers.MatcherTypeEqualTo, FLAG_V1_0) if shouldFilter { t.Error("It should not filtered") } - shouldFilter = filter.ShouldFilter(matchers.MatcherTypeBetweenSemver, "1.1") + shouldFilter = filter.ShouldFilter(matchers.MatcherTypeBetweenSemver, FLAG_V1_1) if shouldFilter { t.Error("It should not filtered") } From 3cbd54b5caadda48b28889ea097435aa2ccb9efc Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 30 Apr 2024 13:56:12 -0300 Subject: [PATCH 04/56] updated FetchOptions to be used on all the Get calls, added skeleton of specVersion --- .github/dependabot.yaml | 10 ++ service/api/auth.go | 5 +- service/api/auth_test.go | 23 ++- service/api/client.go | 20 ++- service/api/client_test.go | 81 +++++++++- service/api/http_fetchers.go | 24 +-- service/api/http_fetchers_test.go | 74 ++++----- service/api/mocks/client.go | 10 +- service/commons.go | 163 +++++++++++++++++--- service/commons_test.go | 73 +++++++++ service/interfaces.go | 4 +- service/local/segmentFetcher.go | 4 +- service/local/segmentFetcher_test.go | 20 +-- service/local/splitFetcher.go | 8 +- service/local/splitFetcher_test.go | 30 ++-- service/mocks/segment.go | 6 +- service/mocks/split.go | 6 +- spec/spec.go | 4 + synchronizer/local_test.go | 12 +- synchronizer/synchronizer_test.go | 38 ++--- synchronizer/worker/segment/segment.go | 16 +- synchronizer/worker/segment/segment_test.go | 33 ++-- synchronizer/worker/split/split.go | 17 +- synchronizer/worker/split/split_test.go | 54 +++---- tasks/segmentsync_test.go | 2 +- tasks/splitsync_test.go | 4 +- 26 files changed, 498 insertions(+), 243 deletions(-) create mode 100644 .github/dependabot.yaml create mode 100644 service/commons_test.go create mode 100644 spec/spec.go diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 00000000..075ff531 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,10 @@ +--- +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + reviewers: + - "splitio/sdk" diff --git a/service/api/auth.go b/service/api/auth.go index 60ac18e1..f97dcb5b 100644 --- a/service/api/auth.go +++ b/service/api/auth.go @@ -5,6 +5,9 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v5/spec" + "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) @@ -24,7 +27,7 @@ func NewAuthAPIClient(apikey string, cfg conf.AdvancedConfig, logger logging.Log // Authenticate performs authentication for push services func (a *AuthAPIClient) Authenticate() (*dtos.Token, error) { - raw, err := a.client.Get("/api/v2/auth", map[string]string{CacheControlHeader: CacheControlNoCache}) + raw, err := a.client.Get("/api/v2/auth", service.MakeAuthFetchOptions(common.StringRef(spec.FlagSpec))) if err != nil { a.logger.Error("Error while authenticating for streaming", err) return nil, err diff --git a/service/api/auth_test.go b/service/api/auth_test.go index a0a8c66b..fcda3fde 100644 --- a/service/api/auth_test.go +++ b/service/api/auth_test.go @@ -8,6 +8,7 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/service" "github.com/splitio/go-split-commons/v5/service/api/mocks" "github.com/splitio/go-toolkit/v5/logging" ) @@ -17,8 +18,8 @@ func TestAuthErr(t *testing.T) { mockedAuth := AuthAPIClient{ client: mocks.ClientMock{ - GetCall: func(service string, headers map[string]string) ([]byte, error) { - if service != "/api/v2/auth" { + GetCall: func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + if endpoint != "/api/v2/auth" { t.Error("Wrong service passed") } return nil, errors.New("Some") @@ -41,8 +42,8 @@ func TestAuthPushEnabledFalse(t *testing.T) { mockedAuth := AuthAPIClient{ client: mocks.ClientMock{ - GetCall: func(service string, headers map[string]string) ([]byte, error) { - if service != "/api/v2/auth" { + GetCall: func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + if endpoint != "/api/v2/auth" { t.Error("Wrong service passed") } return []byte("{\"pushEnabled\":false,\"token\":\"\"}"), nil @@ -55,11 +56,8 @@ func TestAuthPushEnabledFalse(t *testing.T) { if err != nil { t.Error("It should not return err") } - if token == nil { - t.Error("It should not return nil") - } - if token.PushEnabled { + if token == nil || token.PushEnabled { t.Error("It should be false") } if len(token.Token) != 0 { @@ -72,8 +70,8 @@ func TestAuthPushEnabledTrue(t *testing.T) { mockedAuth := AuthAPIClient{ client: mocks.ClientMock{ - GetCall: func(service string, headers map[string]string) ([]byte, error) { - if service != "/api/v2/auth" { + GetCall: func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + if endpoint != "/api/v2/auth" { t.Error("Wrong service passed") } return []byte("{\"pushEnabled\":true,\"token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6IjVZOU05US45QnJtR0EiLCJ0eXAiOiJKV1QifQ.eyJ4LWFibHktY2FwYWJpbGl0eSI6IntcIk56TTJNREk1TXpjMF9NVGd5TlRnMU1UZ3dOZz09X3NlZ21lbnRzXCI6W1wic3Vic2NyaWJlXCJdLFwiTnpNMk1ESTVNemMwX01UZ3lOVGcxTVRnd05nPT1fc3BsaXRzXCI6W1wic3Vic2NyaWJlXCJdLFwiY29udHJvbF9wcmlcIjpbXCJzdWJzY3JpYmVcIixcImNoYW5uZWwtbWV0YWRhdGE6cHVibGlzaGVyc1wiXSxcImNvbnRyb2xfc2VjXCI6W1wic3Vic2NyaWJlXCIsXCJjaGFubmVsLW1ldGFkYXRhOnB1Ymxpc2hlcnNcIl19IiwieC1hYmx5LWNsaWVudElkIjoiY2xpZW50SWQiLCJleHAiOjE1OTE3NDQzOTksImlhdCI6MTU5MTc0MDc5OX0.EcWYtI0rlA7LCVJ5tYldX-vpfMRIc_1HT68-jhXseCo\"}"), nil @@ -86,11 +84,8 @@ func TestAuthPushEnabledTrue(t *testing.T) { if err != nil { t.Error("It should not return err") } - if token == nil { - t.Error("It should not return nil") - } - if !token.PushEnabled { + if token == nil || !token.PushEnabled { t.Error("It should be true") } if len(token.Token) == 0 { diff --git a/service/api/client.go b/service/api/client.go index 7e4a7edc..d02259ad 100644 --- a/service/api/client.go +++ b/service/api/client.go @@ -11,6 +11,7 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/service" "github.com/splitio/go-toolkit/v5/logging" ) @@ -22,8 +23,8 @@ const ( // Client interface for HTTPClient type Client interface { - Get(service string, headers map[string]string) ([]byte, error) - Post(service string, body []byte, headers map[string]string) error + Get(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) + Post(endpoint string, body []byte, headers map[string]string) error } // HTTPClient structure to wrap up the net/http.Client @@ -55,16 +56,15 @@ func NewHTTPClient( } // Get method is a get call to an url -func (c *HTTPClient) Get(service string, headers map[string]string) ([]byte, error) { - serviceURL := c.url + service +func (c *HTTPClient) Get(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + serviceURL := c.url + endpoint c.logger.Debug("[GET] ", serviceURL) req, _ := http.NewRequest("GET", serviceURL, nil) - authorization := c.apikey c.logger.Debug("Authorization [ApiKey]: ", logging.ObfuscateAPIKey(authorization)) req.Header.Add("Accept-Encoding", "gzip") req.Header.Add("Content-Type", "application/json") - parsedHeaders := AddMetadataToHeaders(c.metadata, headers, nil) + parsedHeaders := AddMetadataToHeaders(c.metadata, make(map[string]string), nil) for headerName, headerValue := range parsedHeaders { req.Header.Add(headerName, headerValue) @@ -74,6 +74,10 @@ func (c *HTTPClient) Get(service string, headers map[string]string) ([]byte, err req.Header.Add("Authorization", "Bearer "+authorization) + if fetchOptions != nil { + fetchOptions.Apply(req) + } + resp, err := c.httpClient.Do(req) if err != nil { c.logger.Error("Error requesting data to API: ", req.URL.String(), err.Error()) @@ -114,9 +118,9 @@ func (c *HTTPClient) Get(service string, headers map[string]string) ([]byte, err } // Post performs a HTTP POST request -func (c *HTTPClient) Post(service string, body []byte, headers map[string]string) error { +func (c *HTTPClient) Post(endpoint string, body []byte, headers map[string]string) error { - serviceURL := c.url + service + serviceURL := c.url + endpoint c.logger.Debug("[POST] ", serviceURL) req, _ := http.NewRequest("POST", serviceURL, bytes.NewBuffer(body)) //**************** diff --git a/service/api/client_test.go b/service/api/client_test.go index 400990de..ffeeb5c6 100644 --- a/service/api/client_test.go +++ b/service/api/client_test.go @@ -10,13 +10,15 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) func TestGet(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello, client") - if r.Header.Get("h1") != "v1" { + if r.Header.Get(CacheControlHeader) != CacheControlNoCache { t.Error("wrong header") } })) @@ -24,7 +26,82 @@ func TestGet(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) - txt, errg := httpClient.Get("/", map[string]string{"h1": "v1"}) + txt, errg := httpClient.Get("/", service.MakeSplitFetchOptions(nil)) + if errg != nil { + t.Error(errg) + } + + if string(txt) != "Hello, client\n" { + t.Error("Given message failed ") + } +} + +func TestGetSplitFetchOptions(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Hello, client") + if r.Header.Get(CacheControlHeader) != CacheControlNoCache { + t.Error("wrong header") + } + expected := "/test?s=v1.1&since=123456&sets=filter&till=2345" + if r.URL.String() != expected { + t.Error("wrong query params, expected ", expected, "got", r.URL.String()) + } + })) + defer ts.Close() + + logger := logging.NewLogger(&logging.LoggerOptions{}) + httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) + txt, errg := httpClient.Get("/test", service.MakeSplitFetchOptions(common.StringRef("v1.1")).WithChangeNumber(123456).WithTill(2345).WithFlagSetsFilter("filter")) + if errg != nil { + t.Error(errg) + } + + if string(txt) != "Hello, client\n" { + t.Error("Given message failed ") + } +} + +func TestGetSegmentFetchOptions(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Hello, client") + if r.Header.Get(CacheControlHeader) != CacheControlNoCache { + t.Error("wrong header") + } + expected := "/test?s=v1.1&since=123456&till=2345" + if r.URL.String() != expected { + t.Error("wrong query params, expected ", expected, "got", r.URL.String()) + } + })) + defer ts.Close() + + logger := logging.NewLogger(&logging.LoggerOptions{}) + httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) + txt, errg := httpClient.Get("/test", service.MakeSegmentFetchOptions(common.StringRef("v1.1")).WithChangeNumber(123456).WithTill(2345)) + if errg != nil { + t.Error(errg) + } + + if string(txt) != "Hello, client\n" { + t.Error("Given message failed ") + } +} + +func TestGetAuthOptions(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Hello, client") + if r.Header.Get(CacheControlHeader) != CacheControlNoCache { + t.Error("wrong header") + } + expected := "/test?s=v1.1" + if r.URL.String() != expected { + t.Error("wrong query params, expected ", expected, "got", r.URL.String()) + } + })) + defer ts.Close() + + logger := logging.NewLogger(&logging.LoggerOptions{}) + httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) + txt, errg := httpClient.Get("/test", service.MakeAuthFetchOptions(common.StringRef("v1.1"))) if errg != nil { t.Error(errg) } diff --git a/service/api/http_fetchers.go b/service/api/http_fetchers.go index afe0c8e0..105cb122 100644 --- a/service/api/http_fetchers.go +++ b/service/api/http_fetchers.go @@ -3,7 +3,6 @@ package api import ( "bytes" "encoding/json" - "net/url" "strings" "github.com/splitio/go-split-commons/v5/conf" @@ -17,17 +16,8 @@ type httpFetcherBase struct { logger logging.LoggerInterface } -func (h *httpFetcherBase) fetchRaw(endpoint string, since int64, fetchOptions *service.FetchOptions) ([]byte, error) { - queryParams, headers := service.BuildFetch(since, fetchOptions) - if len(queryParams) > 0 { - params := url.Values{} - for key, value := range queryParams { - params.Add(key, value) - } - endpoint = endpoint + "?" + params.Encode() - } - - data, err := h.client.Get(endpoint, headers) +func (h *httpFetcherBase) fetchRaw(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + data, err := h.client.Get(endpoint, fetchOptions) if err != nil { return nil, err } @@ -52,9 +42,9 @@ func NewHTTPSplitFetcher(apikey string, cfg conf.AdvancedConfig, logger logging. } // Fetch makes an http call to the split backend and returns the list of updated splits -func (f *HTTPSplitFetcher) Fetch(since int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { - fetchOptions.SetFlagSetsFilter(f.flagSetsFilter) - data, err := f.fetchRaw("/splitChanges", since, fetchOptions) +func (f *HTTPSplitFetcher) Fetch(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + fetchOptions.WithFlagSetsFilter(f.flagSetsFilter) + data, err := f.fetchRaw("/splitChanges", fetchOptions) if err != nil { f.logger.Error("Error fetching split changes ", err) return nil, err @@ -86,12 +76,12 @@ func NewHTTPSegmentFetcher(apikey string, cfg conf.AdvancedConfig, logger loggin } // Fetch issues a GET request to the split backend and returns the contents of a particular segment -func (f *HTTPSegmentFetcher) Fetch(segmentName string, since int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { +func (f *HTTPSegmentFetcher) Fetch(segmentName string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { var bufferQuery bytes.Buffer bufferQuery.WriteString("/segmentChanges/") bufferQuery.WriteString(segmentName) - data, err := f.fetchRaw(bufferQuery.String(), since, fetchOptions) + data, err := f.fetchRaw(bufferQuery.String(), fetchOptions) if err != nil { f.logger.Error(err.Error()) return nil, err diff --git a/service/api/http_fetchers_test.go b/service/api/http_fetchers_test.go index 73eb0a35..53af3159 100644 --- a/service/api/http_fetchers_test.go +++ b/service/api/http_fetchers_test.go @@ -13,6 +13,7 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) @@ -27,6 +28,9 @@ func TestSpitChangesFetch(t *testing.T) { if r.Header.Get("Cache-Control") != "no-cache" { t.Error("wrong cache control header") } + if r.URL.Query().Get("since") != "123456" { + t.Error("wrong since") + } fmt.Fprintln(w, fmt.Sprintf(string(splitsMock), splitMock)) })) defer ts.Close() @@ -41,7 +45,7 @@ func TestSpitChangesFetch(t *testing.T) { dtos.Metadata{}, ) - splitChangesDTO, err := splitFetcher.Fetch(-1, &service.FetchOptions{CacheControlHeaders: true}) + splitChangesDTO, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) if err != nil { t.Error(err) } @@ -71,7 +75,7 @@ func TestSpitChangesFetchWithFlagOptions(t *testing.T) { var queryParams url.Values ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - cacheControl = r.Header.Get("Cache-Control") + cacheControl = r.Header.Get(CacheControlHeader) queryParams = r.URL.Query() fmt.Fprintln(w, fmt.Sprintf(string(splitsMock), splitMock)) })) @@ -87,41 +91,28 @@ func TestSpitChangesFetchWithFlagOptions(t *testing.T) { dtos.Metadata{}, ) - _, err := splitFetcher.Fetch(-1, &service.FetchOptions{CacheControlHeaders: true}) + _, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) if err != nil { t.Error(err) } - if cacheControl != "no-cache" { + if cacheControl != CacheControlNoCache { t.Error("Wrong header sent") } - if !queryParams.Has("since") { - t.Error("Expected to have since") - } - if queryParams.Has("till") { - t.Error("Expected to not have till") - } - _, err = splitFetcher.Fetch(-1, &service.FetchOptions{CacheControlHeaders: false}) - if err != nil { - t.Error(err) - } - if cacheControl != "" { - t.Error("Cache control should not be present") - } - if !queryParams.Has("since") { + if queryParams.Get("since") != "123456" { t.Error("Expected to have since") } if queryParams.Has("till") { t.Error("Expected to not have till") } expectedTill := int64(10000) - _, err = splitFetcher.Fetch(-1, &service.FetchOptions{CacheControlHeaders: true, ChangeNumber: &expectedTill}) + _, err = splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456).WithTill(expectedTill)) if err != nil { t.Error(err) } - if cacheControl != "no-cache" { + if cacheControl != CacheControlNoCache { t.Error("Wrong header sent") } - if !queryParams.Has("since") { + if queryParams.Get("since") != "123456" { t.Error("Expected to have since") } if queryParams.Get("till") != "10000" { @@ -136,7 +127,7 @@ func TestSpitChangesFetchWithFlagSetsFilter(t *testing.T) { var queryParams url.Values ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - cacheControl = r.Header.Get("Cache-Control") + cacheControl = r.Header.Get(CacheControlHeader) queryParams = r.URL.Query() fmt.Fprintln(w, fmt.Sprintf(string(splitsMock), splitMock)) })) @@ -153,14 +144,14 @@ func TestSpitChangesFetchWithFlagSetsFilter(t *testing.T) { dtos.Metadata{}, ) - _, err := splitFetcher.Fetch(-1, &service.FetchOptions{CacheControlHeaders: true}) + _, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) if err != nil { t.Error(err) } - if cacheControl != "no-cache" { + if cacheControl != CacheControlNoCache { t.Error("Wrong header sent") } - if !queryParams.Has("since") { + if queryParams.Get("since") != "123456" { t.Error("Expected to have since") } if queryParams.Has("till") { @@ -202,7 +193,7 @@ func TestSpitChangesFetchHTTPError(t *testing.T) { dtos.Metadata{}, ) - _, err := splitFetcher.Fetch(-1, &service.FetchOptions{CacheControlHeaders: false}) + _, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1"))) if err == nil { t.Error("Error expected but not found") } @@ -226,7 +217,7 @@ func TestSegmentChangesFetch(t *testing.T) { dtos.Metadata{}, ) - segmentFetched, err := segmentFetcher.Fetch("employees", -1, &service.FetchOptions{CacheControlHeaders: false}) + segmentFetched, err := segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1"))) if err != nil { t.Error("Error fetching segment", err) return @@ -255,7 +246,7 @@ func TestSegmentChangesFetchHTTPError(t *testing.T) { dtos.Metadata{}, ) - _, err := segmentFetcher.Fetch("employees", -1, &service.FetchOptions{CacheControlHeaders: false}) + _, err := segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1"))) if err == nil { t.Error("Error expected but not found") } @@ -268,7 +259,7 @@ func TestSegmentChangesFetchWithFlagOptions(t *testing.T) { var queryParams url.Values ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - cacheControl = r.Header.Get("Cache-Control") + cacheControl = r.Header.Get(CacheControlHeader) queryParams = r.URL.Query() fmt.Fprintln(w, string(segmentMock)) })) @@ -284,41 +275,28 @@ func TestSegmentChangesFetchWithFlagOptions(t *testing.T) { dtos.Metadata{}, ) - _, err := segmentFetcher.Fetch("employees", -1, &service.FetchOptions{CacheControlHeaders: true}) + _, err := segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) if err != nil { t.Error(err) } - if cacheControl != "no-cache" { + if cacheControl != CacheControlNoCache { t.Error("Wrong header sent") } - if !queryParams.Has("since") { - t.Error("Expected to have since") - } - if queryParams.Has("till") { - t.Error("Expected to not have till") - } - _, err = segmentFetcher.Fetch("employees", -1, &service.FetchOptions{CacheControlHeaders: false}) - if err != nil { - t.Error(err) - } - if cacheControl != "" { - t.Error("Cache control should not be present") - } - if !queryParams.Has("since") { + if queryParams.Get("since") != "123456" { t.Error("Expected to have since") } if queryParams.Has("till") { t.Error("Expected to not have till") } expectedTill := int64(10000) - _, err = segmentFetcher.Fetch("employees", -1, &service.FetchOptions{CacheControlHeaders: true, ChangeNumber: &expectedTill}) + _, err = segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1")).WithTill(expectedTill).WithChangeNumber(123456)) if err != nil { t.Error(err) } - if cacheControl != "no-cache" { + if cacheControl != CacheControlNoCache { t.Error("Wrong header sent") } - if !queryParams.Has("since") { + if queryParams.Get("since") != "123456" { t.Error("Expected to have since") } if queryParams.Get("till") != "10000" { diff --git a/service/api/mocks/client.go b/service/api/mocks/client.go index 399bc523..afbc6e54 100644 --- a/service/api/mocks/client.go +++ b/service/api/mocks/client.go @@ -1,14 +1,16 @@ package mocks +import "github.com/splitio/go-split-commons/v5/service" + // ClientMock mocks client type ClientMock struct { - GetCall func(service string, headers map[string]string) ([]byte, error) - PostCall func(service string, body []byte, headers map[string]string) error + GetCall func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) + PostCall func(endpoint string, body []byte, headers map[string]string) error } // Get mocks Get -func (c ClientMock) Get(service string, headers map[string]string) ([]byte, error) { - return c.GetCall(service, headers) +func (c ClientMock) Get(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + return c.GetCall(endpoint, fetchOptions) } // Post mocks Post diff --git a/service/commons.go b/service/commons.go index 26fdd222..f5a3f598 100644 --- a/service/commons.go +++ b/service/commons.go @@ -1,47 +1,166 @@ package service import ( + "net/http" + "net/url" "strconv" + "strings" + + "github.com/splitio/go-toolkit/v5/common" ) const ( cacheControl = "Cache-Control" cacheControlNoCache = "no-cache" + sets = "sets" + since = "since" + spec = "s" + till = "till" ) -type FetchOptions struct { +type queryParamater struct { + key string + value string +} + +type FetchOptions interface { + Apply(request *http.Request) error +} + +type BaseOptions struct { CacheControlHeaders bool - ChangeNumber *int64 - FlagSetsFilter string + SpecVersion *string +} + +type SplitFetchOptions struct { + BaseOptions + ChangeNumber int64 + FlagSetsFilter string + Till *int64 +} + +func MakeSplitFetchOptions(specVersion *string) *SplitFetchOptions { + return &SplitFetchOptions{ + BaseOptions: BaseOptions{ + CacheControlHeaders: true, + SpecVersion: specVersion, + }, + } +} + +func (s *SplitFetchOptions) WithChangeNumber(changeNumber int64) *SplitFetchOptions { + s.ChangeNumber = changeNumber + return s +} + +func (s *SplitFetchOptions) WithFlagSetsFilter(flagSetsFilter string) *SplitFetchOptions { + s.FlagSetsFilter = flagSetsFilter + return s +} + +func (s *SplitFetchOptions) WithTill(till int64) *SplitFetchOptions { + s.Till = common.Int64Ref(till) + return s +} + +func (s *SplitFetchOptions) Apply(request *http.Request) error { + request.Header.Set(cacheControl, cacheControlNoCache) + + queryParameters := []queryParamater{} + if s.SpecVersion != nil { + queryParameters = append(queryParameters, queryParamater{key: spec, value: common.StringFromRef(s.SpecVersion)}) + } + queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.ChangeNumber, 10)}) + if len(s.FlagSetsFilter) > 0 { + queryParameters = append(queryParameters, queryParamater{key: sets, value: s.FlagSetsFilter}) + } + if s.Till != nil { + queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.Till, 10)}) + } + + request.URL.RawQuery = encode(queryParameters) + return nil +} + +type SegmentFetchOptions struct { + BaseOptions + ChangeNumber int64 + Till *int64 } -func NewFetchOptions(cacheControlHeaders bool, changeNumber *int64) FetchOptions { - return FetchOptions{ - CacheControlHeaders: cacheControlHeaders, - ChangeNumber: changeNumber, +func MakeSegmentFetchOptions(specVersion *string) *SegmentFetchOptions { + return &SegmentFetchOptions{ + BaseOptions: BaseOptions{ + CacheControlHeaders: true, + SpecVersion: specVersion, + }, } } -func (f *FetchOptions) SetFlagSetsFilter(flagSetsFilter string) { - f.FlagSetsFilter = flagSetsFilter +func (s *SegmentFetchOptions) WithChangeNumber(changeNumber int64) *SegmentFetchOptions { + s.ChangeNumber = changeNumber + return s +} + +func (s *SegmentFetchOptions) WithTill(till int64) *SegmentFetchOptions { + s.Till = common.Int64Ref(till) + return s +} + +func (s *SegmentFetchOptions) Apply(request *http.Request) error { + request.Header.Set(cacheControl, cacheControlNoCache) + + queryParameters := []queryParamater{} + if s.SpecVersion != nil { + queryParameters = append(queryParameters, queryParamater{key: spec, value: common.StringFromRef(s.SpecVersion)}) + } + queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.ChangeNumber, 10)}) + if s.Till != nil { + queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.Till, 10)}) + } + + request.URL.RawQuery = encode(queryParameters) + return nil } -func BuildFetch(changeNumber int64, fetchOptions *FetchOptions) (map[string]string, map[string]string) { - queryParams := make(map[string]string) - headers := make(map[string]string) - queryParams["since"] = strconv.FormatInt(changeNumber, 10) +type AuthFetchOptions struct { + BaseOptions +} - if fetchOptions == nil { - return queryParams, headers +func MakeAuthFetchOptions(specVersion *string) *AuthFetchOptions { + return &AuthFetchOptions{ + BaseOptions: BaseOptions{ + CacheControlHeaders: true, + SpecVersion: specVersion, + }, } - if fetchOptions.CacheControlHeaders { - headers[cacheControl] = cacheControlNoCache +} + +func (s *AuthFetchOptions) Apply(request *http.Request) error { + request.Header.Set(cacheControl, cacheControlNoCache) + + queryParams := request.URL.Query() + if s.SpecVersion != nil { + queryParams.Add(spec, common.StringFromRef(s.SpecVersion)) } - if fetchOptions.ChangeNumber != nil { - queryParams["till"] = strconv.FormatInt(*fetchOptions.ChangeNumber, 10) + + request.URL.RawQuery = queryParams.Encode() + return nil +} + +func encode(v []queryParamater) string { + if v == nil { + return "" } - if len(fetchOptions.FlagSetsFilter) > 0 { - queryParams["sets"] = fetchOptions.FlagSetsFilter + var buf strings.Builder + for _, k := range v { + keyEscaped := url.QueryEscape(k.key) + if buf.Len() > 0 { + buf.WriteByte('&') + } + buf.WriteString(keyEscaped) + buf.WriteByte('=') + buf.WriteString(url.QueryEscape(k.value)) } - return queryParams, headers + return buf.String() } diff --git a/service/commons_test.go b/service/commons_test.go new file mode 100644 index 00000000..95bd871a --- /dev/null +++ b/service/commons_test.go @@ -0,0 +1,73 @@ +package service + +import ( + "net/http" + "testing" + + "github.com/splitio/go-toolkit/v5/common" +) + +func TestSplitFetchOptions(t *testing.T) { + fetchOptions := MakeSplitFetchOptions(common.StringRef("v1")).WithChangeNumber(123456).WithFlagSetsFilter("filter").WithTill(*common.Int64Ref(123)) + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + + if req.Header.Get(cacheControl) != cacheControlNoCache { + t.Error("Cache control header not set") + } + if req.URL.Query().Get(since) != "123456" { + t.Error("Change number not set") + } + if req.URL.Query().Get(spec) != "v1" { + t.Error("Spec version not set") + } + if req.URL.Query().Get(sets) != "filter" { + t.Error("Flag sets filter not set") + } + if req.URL.Query().Get(till) != "123" { + t.Error("Till not set") + } + if req.URL.String() != "test?s=v1&since=123456&sets=filter&till=123" { + t.Error("Query params not set correctly, expected: test?s=v1&since=123456&sets=filter&till=123, got:", req.URL.String()) + } +} + +func TestSegmentFetchOptions(t *testing.T) { + fetchOptions := MakeSegmentFetchOptions(common.StringRef("v1")).WithChangeNumber(123456).WithTill(*common.Int64Ref(123)) + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + + if req.Header.Get(cacheControl) != cacheControlNoCache { + t.Error("Cache control header not set") + } + + if req.URL.Query().Get(since) != "123456" { + t.Error("Change number not set") + } + if req.URL.Query().Get(spec) != "v1" { + t.Error("Spec version not set") + } + if req.URL.Query().Get(till) != "123" { + t.Error("Till not set") + } + + if req.URL.String() != "test?s=v1&since=123456&till=123" { + t.Error("Query params not set correctly, expected: test?s=v1&since=123456&till=123, got:", req.URL.String()) + } +} + +func TestAuthFetchOptions(t *testing.T) { + fetchOptions := MakeAuthFetchOptions(common.StringRef("v1")) + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + + if req.Header.Get(cacheControl) != cacheControlNoCache { + t.Error("Cache control header not set") + } + if req.URL.Query().Get(spec) != "v1" { + t.Error("Spec version not set") + } + if req.URL.String() != "test?s=v1" { + t.Error("Query params not set correctly, expected: test?s=v1, got:", req.URL.String()) + } +} diff --git a/service/interfaces.go b/service/interfaces.go index c6b8a87d..13a302aa 100644 --- a/service/interfaces.go +++ b/service/interfaces.go @@ -11,12 +11,12 @@ type AuthClient interface { // SplitFetcher interface to be implemented by Split Fetchers type SplitFetcher interface { - Fetch(changeNumber int64, fetchOptions *FetchOptions) (*dtos.SplitChangesDTO, error) + Fetch(fetchOptions *SplitFetchOptions) (*dtos.SplitChangesDTO, error) } // SegmentFetcher interface to be implemented by Split Fetchers type SegmentFetcher interface { - Fetch(name string, changeNumber int64, fetchOptions *FetchOptions) (*dtos.SegmentChangesDTO, error) + Fetch(name string, fetchOptions *SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) } // ImpressionsRecorder interface to be implemented by Impressions loggers diff --git a/service/local/segmentFetcher.go b/service/local/segmentFetcher.go index 319653e1..1c31fc93 100644 --- a/service/local/segmentFetcher.go +++ b/service/local/segmentFetcher.go @@ -78,11 +78,11 @@ func (s *FileSegmentFetcher) processSegmentJson(fileContents []byte, segmentName } // Fetch parses the file and returns the appropriate structures -func (s *FileSegmentFetcher) Fetch(segmentName string, changeNumber int64, _ *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { +func (s *FileSegmentFetcher) Fetch(segmentName string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { fileContents, err := s.reader.ReadFile(fmt.Sprintf("%v/%v.json", s.segmentDirectory, segmentName)) if err != nil { s.logger.Error(fmt.Sprintf("could not find the segmentChange file for %s. error: %v", segmentName, err)) return nil, err } - return s.processSegmentJson(fileContents, segmentName, changeNumber) + return s.processSegmentJson(fileContents, segmentName, fetchOptions.ChangeNumber) } diff --git a/service/local/segmentFetcher_test.go b/service/local/segmentFetcher_test.go index b2456e7c..8b156606 100644 --- a/service/local/segmentFetcher_test.go +++ b/service/local/segmentFetcher_test.go @@ -17,7 +17,7 @@ func TestLocalSegmentFetcherJson(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - res, err := fetcher.Fetch("segment_mock", -1, &service.FetchOptions{}) + res, err := fetcher.Fetch("segment_mock", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -44,7 +44,7 @@ func TestInvalidTill(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - res, err := fetcher.Fetch("segmentTillInvalid", -1, &service.FetchOptions{}) + res, err := fetcher.Fetch("segmentTillInvalid", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("should not fail.") } @@ -138,7 +138,7 @@ func TestFetchSomeSegments(t *testing.T) { } // 0) The CN from storage is -1, till and since are -1, and sha doesn't exist in the hash. It's going to return a segment change with updates. - segmentChange, _ := mockedFetchers.Fetch("test_1", -1, nil) + segmentChange, _ := mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if segmentChange.Since != -1 || segmentChange.Till != -1 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -151,7 +151,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 1) The CN from storage is -1, till and since are -1, and sha is different than before. It's going to return a segment change with updates. - segmentChange, _ = mockedFetchers.Fetch("test_1", -1, nil) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if segmentChange.Since != -1 || segmentChange.Till != -1 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -164,7 +164,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 2) The CN from storage is -1, till is 2323, and since is -1, and sha is the same as before. It's going to return a segment change with the same data. - segmentChange, _ = mockedFetchers.Fetch("test_1", -1, nil) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if segmentChange.Since != -1 || segmentChange.Till != -1 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -177,7 +177,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 3) The CN from storage is -1, till is 2323, and since is -1, sha is different than before. It's going to return a segment change with updates. - segmentChange, _ = mockedFetchers.Fetch("test_1", -1, nil) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if segmentChange.Since != 2323 || segmentChange.Till != 2323 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -190,7 +190,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 4) The CN from storage is 2323, till is 445345, and since is -1, and sha is the same as before. It's going to return a segment change with same data. - segmentChange, _ = mockedFetchers.Fetch("test_1", 2323, nil) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(2323)) if segmentChange.Since != 2323 || segmentChange.Till != 2323 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -203,7 +203,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 5) The CN from storage is 2323, till and since are -1, and sha is different than before. It's going to return a segment change with updates. - segmentChange, _ = mockedFetchers.Fetch("test_1", 2323, nil) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(2323)) if segmentChange.Since != 2323 || segmentChange.Till != 2323 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -221,7 +221,7 @@ func TestSegmentWithoutName(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - _, err := fetcher.Fetch("segmentWithoutName", -1, &service.FetchOptions{}) + _, err := fetcher.Fetch("segmentWithoutName", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if err == nil { t.Error("fetching should fail.") } @@ -232,7 +232,7 @@ func TestSegmentSanitization(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - res, err := fetcher.Fetch("segmentSanitization", -1, &service.FetchOptions{}) + res, err := fetcher.Fetch("segmentSanitization", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } diff --git a/service/local/splitFetcher.go b/service/local/splitFetcher.go index 1f85cee8..191ef82c 100644 --- a/service/local/splitFetcher.go +++ b/service/local/splitFetcher.go @@ -256,7 +256,7 @@ func (s *FileSplitFetcher) processSplitJson(data string, changeNumber int64) (*d } // Fetch parses the file and returns the appropriate structures -func (s *FileSplitFetcher) Fetch(changeNumber int64, _ *service.FetchOptions) (*dtos.SplitChangesDTO, error) { +func (s *FileSplitFetcher) Fetch(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { fileContents, err := s.reader.ReadFile(s.splitFile) if err != nil { return nil, err @@ -270,13 +270,13 @@ func (s *FileSplitFetcher) Fetch(changeNumber int64, _ *service.FetchOptions) (* case SplitFileFormatYAML: splits = s.parseSplitsYAML(data) case SplitFileFormatJSON: - return s.processSplitJson(data, changeNumber) + return s.processSplitJson(data, fetchOptions.ChangeNumber) default: return nil, fmt.Errorf("unsupported file format") } - till := changeNumber + till := fetchOptions.ChangeNumber // Get the SHA1 sum of the raw contents of the file, and compare it to the last one seen // if it's equal, nothing has changed, return since == till @@ -291,7 +291,7 @@ func (s *FileSplitFetcher) Fetch(changeNumber int64, _ *service.FetchOptions) (* s.lastHash = currSum return &dtos.SplitChangesDTO{ Splits: splits, - Since: changeNumber, + Since: fetchOptions.ChangeNumber, Till: till, }, nil } diff --git a/service/local/splitFetcher_test.go b/service/local/splitFetcher_test.go index 0d87fb66..ffee4c2b 100644 --- a/service/local/splitFetcher_test.go +++ b/service/local/splitFetcher_test.go @@ -40,7 +40,7 @@ func TestLocalSplitFetcher(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatClassic) - res, err := fetcher.Fetch(-1, &service.FetchOptions{}) + res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -55,7 +55,7 @@ func TestLocalSplitFetcher(t *testing.T) { // second call -- no change -- since == till - res, err = fetcher.Fetch(0, &service.FetchOptions{}) + res, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(0)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -74,7 +74,7 @@ func TestLocalSplitFetcher(t *testing.T) { // third call -- change -- till > since - res, err = fetcher.Fetch(0, &service.FetchOptions{}) + res, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(0)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -89,7 +89,7 @@ func TestLocalSplitFetcher(t *testing.T) { // fourth call -- no change -- till != since - res, err = fetcher.Fetch(1, &service.FetchOptions{}) + res, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -108,7 +108,7 @@ func TestLocalSplitFetcherJson(t *testing.T) { fetcher := NewFileSplitFetcher("../../testdata/splitChange_mock.json", logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(-1, &service.FetchOptions{}) + res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -148,7 +148,7 @@ func TestLocalSplitFetcherJsonTest1(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - _, err = fetcher.Fetch(-1, &service.FetchOptions{}) + _, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail.") @@ -184,7 +184,7 @@ func TestFetchSomeSplits(t *testing.T) { fileFormat: SplitFileFormatJSON, } // 0) The CN from storage is -1, till and since are -1, and sha doesn't exist in the hash. It's going to return a split change with updates. - splitChange, _ := mockedFetchers.Fetch(-1, &service.FetchOptions{}) + splitChange, _ := mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if splitChange.Since != -1 || splitChange.Till != -1 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -194,7 +194,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 1) The CN from storage is -1, till and since are -1, and sha is different than before. It's going to return a split change with updates. - splitChange, _ = mockedFetchers.Fetch(-1, &service.FetchOptions{}) + splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if splitChange.Since != -1 || splitChange.Till != -1 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -204,7 +204,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 2) The CN from storage is -1, till is 2323, and since is -1, and sha is the same as before. It's going to return a split change with the same data. - splitChange, _ = mockedFetchers.Fetch(-1, &service.FetchOptions{}) + splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if splitChange.Since != -1 || splitChange.Till != -1 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -214,7 +214,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 3) The CN from storage is -1, till is 2323, and since is -1, sha is different than before. It's going to return a split change with updates. - splitChange, _ = mockedFetchers.Fetch(-1, &service.FetchOptions{}) + splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if splitChange.Since != 2323 || splitChange.Till != 2323 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -224,7 +224,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 4) The CN from storage is 2323, till is 445345, and since is -1, and sha is the same as before. It's going to return a split change with same data. - splitChange, _ = mockedFetchers.Fetch(2323, &service.FetchOptions{}) + splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(2323)) if splitChange.Since != 2323 || splitChange.Till != 2323 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -234,7 +234,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 5) The CN from storage is 2323, till and since are -1, and sha is different than before. It's going to return a split change with updates. - splitChange, _ = mockedFetchers.Fetch(2323, &service.FetchOptions{}) + splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(2323)) if splitChange.Since != 2323 || splitChange.Till != 2323 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -261,7 +261,7 @@ func TestSplitWithoutName(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(-1, &service.FetchOptions{}) + res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) @@ -290,7 +290,7 @@ func TestSplitMatchersEmpty(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(-1, &service.FetchOptions{}) + res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) @@ -328,7 +328,7 @@ func TestSplitSanitization(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(-1, &service.FetchOptions{}) + res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) diff --git a/service/mocks/segment.go b/service/mocks/segment.go index 3e31baa4..87157c8a 100644 --- a/service/mocks/segment.go +++ b/service/mocks/segment.go @@ -7,10 +7,10 @@ import ( // MockSegmentFetcher mocked implementation of segment fetcher type MockSegmentFetcher struct { - FetchCall func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) + FetchCall func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) } // Fetch mock -func (m MockSegmentFetcher) Fetch(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { - return m.FetchCall(name, changeNumber, fetchOptions) +func (m MockSegmentFetcher) Fetch(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + return m.FetchCall(name, fetchOptions) } diff --git a/service/mocks/split.go b/service/mocks/split.go index 779e0829..9841b504 100644 --- a/service/mocks/split.go +++ b/service/mocks/split.go @@ -7,10 +7,10 @@ import ( // MockSplitFetcher mocked implementation of split fetcher type MockSplitFetcher struct { - FetchCall func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) + FetchCall func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) } // Fetch mock -func (m MockSplitFetcher) Fetch(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { - return m.FetchCall(changeNumber, fetchOptions) +func (m MockSplitFetcher) Fetch(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + return m.FetchCall(fetchOptions) } diff --git a/spec/spec.go b/spec/spec.go new file mode 100644 index 00000000..7a403b61 --- /dev/null +++ b/spec/spec.go @@ -0,0 +1,4 @@ +package spec + +// FlagSpec FeatureFlag Version specification +const FlagSpec = "1.1" diff --git a/synchronizer/local_test.go b/synchronizer/local_test.go index 513cb9b3..8f0762ff 100644 --- a/synchronizer/local_test.go +++ b/synchronizer/local_test.go @@ -20,9 +20,9 @@ func TestLocalSyncAllError(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return nil, errors.New("Some") @@ -54,9 +54,9 @@ func TestLocalSyncAllOk(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -103,9 +103,9 @@ func TestLocalPeriodicFetching(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index ff5f9962..9e241688 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -33,12 +33,12 @@ func TestSyncAllErrorSplits(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("no cache should be true") } atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return nil, errors.New("Some") @@ -93,12 +93,12 @@ func TestSyncAllErrorInSegments(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -109,7 +109,7 @@ func TestSyncAllErrorInSegments(t *testing.T) { }, }, SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -185,12 +185,12 @@ func TestSyncAllOk(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -201,7 +201,7 @@ func TestSyncAllOk(t *testing.T) { }, }, SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -295,12 +295,12 @@ func TestPeriodicFetching(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -311,7 +311,7 @@ func TestPeriodicFetching(t *testing.T) { }, }, SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -539,7 +539,7 @@ func TestSplitUpdateWorkerCNGreaterThanFFChange(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return nil, nil }, @@ -588,7 +588,7 @@ func TestSplitUpdateWorkerStorageCNEqualsFFCN(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return nil, nil }, @@ -644,7 +644,7 @@ func TestSplitUpdateWorkerFFPcnEqualsFFNotNil(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return nil, nil }, @@ -707,9 +707,9 @@ func TestSplitUpdateWorkerGetCNFromStorageError(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if changeNumber != 0 { + if fetchOptions.ChangeNumber != 0 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -785,7 +785,7 @@ func TestSplitUpdateWorkerFFIsNil(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return &dtos.SplitChangesDTO{ Till: 4, @@ -853,7 +853,7 @@ func TestSplitUpdateWorkerFFPcnDifferentStorageCN(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return &dtos.SplitChangesDTO{ Till: 2, @@ -949,7 +949,7 @@ func TestSplitUpdateWithReferencedSegments(t *testing.T) { var recordUpdateCall int64 logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } diff --git a/synchronizer/worker/segment/segment.go b/synchronizer/worker/segment/segment.go index 842b4ecd..e3059456 100644 --- a/synchronizer/worker/segment/segment.go +++ b/synchronizer/worker/segment/segment.go @@ -103,7 +103,7 @@ func (s *UpdaterImpl) processUpdate(segmentChanges *dtos.SegmentChangesDTO) { s.segmentStorage.Update(segmentChanges.Name, toAdd, toRemove, segmentChanges.Till) } -func (s *UpdaterImpl) fetchUntil(name string, till *int64, fetchOptions *service.FetchOptions) (*UpdateResult, error) { +func (s *UpdaterImpl) fetchUntil(name string, fetchOptions *service.SegmentFetchOptions) (*UpdateResult, error) { var updatedKeys []string var err error var currentSince int64 @@ -114,7 +114,7 @@ func (s *UpdaterImpl) fetchUntil(name string, till *int64, fetchOptions *service before := time.Now() var segmentChanges *dtos.SegmentChangesDTO - segmentChanges, err = s.segmentFetcher.Fetch(name, currentSince, fetchOptions) + segmentChanges, err = s.segmentFetcher.Fetch(name, fetchOptions.WithChangeNumber(currentSince)) if err != nil { if httpError, ok := err.(*dtos.HTTPError); ok { s.runtimeTelemetry.RecordSyncError(telemetry.SegmentSync, httpError.Code) @@ -139,12 +139,12 @@ func (s *UpdaterImpl) fetchUntil(name string, till *int64, fetchOptions *service }, err } -func (s *UpdaterImpl) attemptSegmentSync(name string, till *int64, fetchOptions *service.FetchOptions) (internalSegmentSync, error) { +func (s *UpdaterImpl) attemptSegmentSync(name string, till *int64, fetchOptions *service.SegmentFetchOptions) (internalSegmentSync, error) { internalBackoff := backoff.New(s.onDemandFetchBackoffBase, s.onDemandFetchBackoffMaxWait) remainingAttempts := onDemandFetchBackoffMaxRetries for { remainingAttempts = remainingAttempts - 1 - updateResult, err := s.fetchUntil(name, till, fetchOptions) // what we should do with err + updateResult, err := s.fetchUntil(name, fetchOptions) // what we should do with err if err != nil || remainingAttempts <= 0 { return internalSegmentSync{updateResult: updateResult, successfulSync: false, attempt: remainingAttempts}, err } @@ -158,7 +158,7 @@ func (s *UpdaterImpl) attemptSegmentSync(name string, till *int64, fetchOptions // SynchronizeSegment syncs segment func (s *UpdaterImpl) SynchronizeSegment(name string, till *int64) (*UpdateResult, error) { - fetchOptions := service.NewFetchOptions(true, nil) + fetchOptions := service.MakeSegmentFetchOptions(nil) s.hcMonitor.NotifyEvent(application.Segments) currentSince, _ := s.segmentStorage.ChangeNumber(name) @@ -166,7 +166,7 @@ func (s *UpdaterImpl) SynchronizeSegment(name string, till *int64) (*UpdateResul return &UpdateResult{}, nil } - internalSyncResult, err := s.attemptSegmentSync(name, till, &fetchOptions) + internalSyncResult, err := s.attemptSegmentSync(name, till, fetchOptions) attempts := onDemandFetchBackoffMaxRetries - internalSyncResult.attempt if err != nil { return internalSyncResult.updateResult, err @@ -175,8 +175,8 @@ func (s *UpdaterImpl) SynchronizeSegment(name string, till *int64) (*UpdateResul s.logger.Debug(fmt.Sprintf("Refresh completed in %d attempts.", attempts)) return internalSyncResult.updateResult, nil } - withCDNBypass := service.NewFetchOptions(true, &internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN - internalSyncResultCDNBypass, err := s.attemptSegmentSync(name, till, &withCDNBypass) + withCDNBypass := service.MakeSegmentFetchOptions(nil).WithTill(internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN + internalSyncResultCDNBypass, err := s.attemptSegmentSync(name, till, withCDNBypass) withoutCDNattempts := onDemandFetchBackoffMaxRetries - internalSyncResultCDNBypass.attempt if err != nil { return internalSyncResultCDNBypass.updateResult, err diff --git a/synchronizer/worker/segment/segment_test.go b/synchronizer/worker/segment/segment_test.go index 11c81c94..ff5e41b3 100644 --- a/synchronizer/worker/segment/segment_test.go +++ b/synchronizer/worker/segment/segment_test.go @@ -45,7 +45,7 @@ func TestSegmentsSynchronizerError(t *testing.T) { } segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("should have requested no cache") } @@ -149,7 +149,7 @@ func TestSegmentSynchronizer(t *testing.T) { } segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("should have requested no cache") } @@ -226,7 +226,7 @@ func TestSegmentSyncUpdate(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if name != "segment1" { t.Error("Wrong name") } @@ -340,7 +340,7 @@ func TestSegmentSyncProcess(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if name != "segment1" && name != "segment2" { t.Error("Wrong name") } @@ -425,7 +425,7 @@ func TestSegmentTill(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { atomic.AddInt64(&call, 1) return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil }, @@ -489,22 +489,22 @@ func TestSegmentCDNBypass(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 1, Till: 2}, nil case called >= 2 && called <= 11: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil case called == 12: - if fetchOptions.ChangeNumber == nil || *fetchOptions.ChangeNumber != 2 { - t.Error("ChangeNumber flag should be set with value 2") + if fetchOptions.Till == nil || *fetchOptions.Till != 2 { + t.Error("Till flag should be set with value 2") } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 3, Till: 3}, nil } @@ -568,22 +568,22 @@ func TestSegmentCDNBypassLimit(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 1, Till: 2}, nil case called > 1 && called <= 11: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil case called >= 12: - if fetchOptions.ChangeNumber == nil || *fetchOptions.ChangeNumber != 2 { - t.Error("ChangeNumber flag should be set with value 2") + if fetchOptions.Till == nil || *fetchOptions.Till != 2 { + t.Error("Till flag should be set with value 2") } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil } @@ -618,7 +618,6 @@ func TestSegmentCDNBypassLimit(t *testing.T) { } func TestSegmentSyncConcurrencyLimit(t *testing.T) { - splitStorage := &mocks.MockSplitStorage{ SegmentNamesCall: func() *set.ThreadUnsafeSet { ss := set.NewSet() @@ -634,7 +633,7 @@ func TestSegmentSyncConcurrencyLimit(t *testing.T) { var done sync.Map var inProgress int32 segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if current := atomic.AddInt32(&inProgress, 1); current > maxConcurrency { t.Errorf("throguhput exceeded max expected concurrency of %d. Is: %d", maxConcurrency, current) } diff --git a/synchronizer/worker/split/split.go b/synchronizer/worker/split/split.go index 318406cf..a0e6ee0c 100644 --- a/synchronizer/worker/split/split.go +++ b/synchronizer/worker/split/split.go @@ -8,6 +8,7 @@ import ( "github.com/splitio/go-split-commons/v5/flagsets" "github.com/splitio/go-split-commons/v5/healthcheck/application" "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v5/spec" "github.com/splitio/go-split-commons/v5/storage" "github.com/splitio/go-split-commons/v5/telemetry" "github.com/splitio/go-toolkit/v5/backoff" @@ -89,7 +90,7 @@ func (s *UpdaterImpl) processUpdate(featureFlags *dtos.SplitChangesDTO) { } // fetchUntil Hit endpoint, update storage and return when since==till. -func (s *UpdaterImpl) fetchUntil(fetchOptions *service.FetchOptions, till *int64) (*UpdateResult, error) { +func (s *UpdaterImpl) fetchUntil(fetchOptions *service.SplitFetchOptions) (*UpdateResult, error) { // just guessing sizes so the we don't realloc immediately segmentReferences := make([]string, 0, 10) updatedSplitNames := make([]string, 0, 10) @@ -100,7 +101,7 @@ func (s *UpdaterImpl) fetchUntil(fetchOptions *service.FetchOptions, till *int64 currentSince, _ = s.splitStorage.ChangeNumber() before := time.Now() var splits *dtos.SplitChangesDTO - splits, err = s.splitFetcher.Fetch(currentSince, fetchOptions) + splits, err = s.splitFetcher.Fetch(fetchOptions.WithChangeNumber(currentSince)) if err != nil { if httpError, ok := err.(*dtos.HTTPError); ok { if httpError.Code == scRequestURITooLong { @@ -128,12 +129,12 @@ func (s *UpdaterImpl) fetchUntil(fetchOptions *service.FetchOptions, till *int64 } // attemptSplitSync Hit endpoint, update storage and return True if sync is complete. -func (s *UpdaterImpl) attemptSplitSync(fetchOptions *service.FetchOptions, till *int64) (internalSplitSync, error) { +func (s *UpdaterImpl) attemptSplitSync(fetchOptions *service.SplitFetchOptions, till *int64) (internalSplitSync, error) { internalBackoff := backoff.New(s.onDemandFetchBackoffBase, s.onDemandFetchBackoffMaxWait) remainingAttempts := onDemandFetchBackoffMaxRetries for { remainingAttempts = remainingAttempts - 1 - updateResult, err := s.fetchUntil(fetchOptions, till) // what we should do with err + updateResult, err := s.fetchUntil(fetchOptions) // what we should do with err if err != nil || remainingAttempts <= 0 { return internalSplitSync{updateResult: updateResult, successfulSync: false, attempt: remainingAttempts}, err } @@ -152,8 +153,8 @@ func (s *UpdaterImpl) SynchronizeSplits(till *int64) (*UpdateResult, error) { return &UpdateResult{}, nil } - fetchOptions := service.NewFetchOptions(true, nil) - internalSyncResult, err := s.attemptSplitSync(&fetchOptions, till) + fetchOptions := service.MakeSplitFetchOptions(common.StringRefOrNil(spec.FlagSpec)) + internalSyncResult, err := s.attemptSplitSync(fetchOptions, till) attempts := onDemandFetchBackoffMaxRetries - internalSyncResult.attempt if err != nil { return internalSyncResult.updateResult, err @@ -162,8 +163,8 @@ func (s *UpdaterImpl) SynchronizeSplits(till *int64) (*UpdateResult, error) { s.logger.Debug(fmt.Sprintf("Refresh completed in %d attempts.", attempts)) return internalSyncResult.updateResult, nil } - withCDNBypass := service.NewFetchOptions(true, &internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN - internalSyncResultCDNBypass, err := s.attemptSplitSync(&withCDNBypass, till) + withCDNBypass := service.MakeSplitFetchOptions(common.StringRefOrNil(spec.FlagSpec)).WithTill(internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN + internalSyncResultCDNBypass, err := s.attemptSplitSync(withCDNBypass, till) withoutCDNattempts := onDemandFetchBackoffMaxRetries - internalSyncResultCDNBypass.attempt if err != nil { return internalSyncResultCDNBypass.updateResult, err diff --git a/synchronizer/worker/split/split_test.go b/synchronizer/worker/split/split_test.go index e5287788..34b2f9db 100644 --- a/synchronizer/worker/split/split_test.go +++ b/synchronizer/worker/split/split_test.go @@ -27,11 +27,11 @@ func TestSplitSynchronizerError(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return nil, &dtos.HTTPError{Code: 500, Message: "some"} @@ -75,12 +75,12 @@ func TestSplitSynchronizerErrorScRequestURITooLong(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCall, 1) if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return nil, &dtos.HTTPError{Code: 414, Message: "some"} @@ -155,11 +155,11 @@ func TestSplitSynchronizer(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -218,11 +218,11 @@ func TestSplitSyncProcess(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch call { case 1: - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -231,7 +231,7 @@ func TestSplitSyncProcess(t *testing.T) { Till: 3, }, nil case 2: - if changeNumber != 3 { + if fetchOptions.ChangeNumber != 3 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -325,7 +325,7 @@ func TestSplitTill(t *testing.T) { mockedSplit1 := dtos.SplitDTO{Name: "split1", Killed: false, Status: "ACTIVE", TrafficTypeName: "one"} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, @@ -370,11 +370,11 @@ func TestByPassingCDN(t *testing.T) { mockedSplit1 := dtos.SplitDTO{Name: "split1", Killed: false, Status: "ACTIVE", TrafficTypeName: "one"} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SplitChangesDTO{ @@ -383,7 +383,7 @@ func TestByPassingCDN(t *testing.T) { Till: 2, }, nil case called >= 2 && called <= 11: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SplitChangesDTO{ @@ -392,7 +392,7 @@ func TestByPassingCDN(t *testing.T) { Till: 2, }, nil case called == 12: - if fetchOptions.ChangeNumber == nil || *fetchOptions.ChangeNumber != 2 { + if fetchOptions.Till == nil || *fetchOptions.Till != 2 { t.Error("ChangeNumber flag should be set with value 2") } return &dtos.SplitChangesDTO{ @@ -443,11 +443,11 @@ func TestByPassingCDNLimit(t *testing.T) { mockedSplit1 := dtos.SplitDTO{Name: "split1", Killed: false, Status: "ACTIVE", TrafficTypeName: "one"} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SplitChangesDTO{ @@ -456,7 +456,7 @@ func TestByPassingCDNLimit(t *testing.T) { Till: 2, }, nil case called >= 2 && called <= 11: - if fetchOptions.ChangeNumber != nil { + if fetchOptions.Till != nil { t.Error("It should be nil") } return &dtos.SplitChangesDTO{ @@ -465,7 +465,7 @@ func TestByPassingCDNLimit(t *testing.T) { Till: 2, }, nil case called >= 12: - if fetchOptions.ChangeNumber == nil || *fetchOptions.ChangeNumber != 2 { + if fetchOptions.Till == nil || *fetchOptions.Till != 2 { t.Error("ChangeNumber flag should be set with value 2") } return &dtos.SplitChangesDTO{ @@ -519,7 +519,7 @@ func TestProcessFFChange(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return nil, nil }, @@ -550,7 +550,7 @@ func TestAddOrUpdateFeatureFlagNil(t *testing.T) { UpdateCall: func(toAdd, toRemove []dtos.SplitDTO, changeNumber int64) {}, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return &dtos.SplitChangesDTO{ Till: 2, @@ -596,7 +596,7 @@ func TestAddOrUpdateFeatureFlagPcnEquals(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return nil, nil }, @@ -640,7 +640,7 @@ func TestAddOrUpdateFeatureFlagArchive(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return nil, nil }, @@ -677,7 +677,7 @@ func TestAddOrUpdateFFCNFromStorageError(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return &dtos.SplitChangesDTO{ Till: 2, @@ -764,11 +764,11 @@ func TestSplitSyncWithSets(t *testing.T) { mockedSplit3 := dtos.SplitDTO{Name: "split3", Killed: false, Status: "ACTIVE", TrafficTypeName: "one", Sets: []string{"set5", "set1"}} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch call { case 1: - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -820,11 +820,11 @@ func TestSplitSyncWithSetsInConfig(t *testing.T) { mockedSplit4 := dtos.SplitDTO{Name: "split4", Killed: false, Status: "ACTIVE", TrafficTypeName: "one", Sets: []string{"set2"}} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch call { case 1: - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ diff --git a/tasks/segmentsync_test.go b/tasks/segmentsync_test.go index a46dec47..fbaa8494 100644 --- a/tasks/segmentsync_test.go +++ b/tasks/segmentsync_test.go @@ -69,7 +69,7 @@ func TestSegmentSyncTask(t *testing.T) { } segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("no cache shold be true") } diff --git a/tasks/splitsync_test.go b/tasks/splitsync_test.go index 99fb80bf..16005805 100644 --- a/tasks/splitsync_test.go +++ b/tasks/splitsync_test.go @@ -52,12 +52,12 @@ func TestSplitSyncTask(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(changeNumber int64, fetchOptions *service.FetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true.") } atomic.AddInt64(&call, 1) - if changeNumber != -1 { + if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ From a7943377565aa94c37f820ec78de3309855821d0 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 30 Apr 2024 14:47:50 -0300 Subject: [PATCH 05/56] renamed FetchOptions in favor of RequestParams and made specVersion optional --- conf/conf.go | 2 + service/api/auth.go | 18 ++-- service/api/auth_test.go | 6 +- service/api/client.go | 4 +- service/api/client_test.go | 12 +-- service/api/http_fetchers.go | 16 +++- service/api/http_fetchers_test.go | 100 +++++++++++++++++--- service/api/mocks/client.go | 4 +- {spec => service/api/spec}/spec.go | 0 service/commons.go | 65 ++++++------- service/commons_test.go | 23 ++--- service/interfaces.go | 4 +- service/local/segmentFetcher.go | 2 +- service/local/segmentFetcher_test.go | 20 ++-- service/local/splitFetcher.go | 2 +- service/local/splitFetcher_test.go | 30 +++--- service/mocks/segment.go | 4 +- service/mocks/split.go | 4 +- synchronizer/local_test.go | 6 +- synchronizer/synchronizer_test.go | 28 +++--- synchronizer/worker/segment/segment.go | 8 +- synchronizer/worker/segment/segment_test.go | 16 ++-- synchronizer/worker/split/split.go | 9 +- synchronizer/worker/split/split_test.go | 28 +++--- tasks/segmentsync_test.go | 2 +- tasks/splitsync_test.go | 2 +- 26 files changed, 251 insertions(+), 164 deletions(-) rename {spec => service/api/spec}/spec.go (100%) diff --git a/conf/conf.go b/conf/conf.go index c1f0e3dd..20597b14 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -85,4 +85,6 @@ type AdvancedConfig struct { SplitsRefreshRate int SegmentsRefreshRate int FlagSetsFilter []string + AuthSpecVersion string + FlagsSpecVersion string } diff --git a/service/api/auth.go b/service/api/auth.go index f97dcb5b..419e6e1e 100644 --- a/service/api/auth.go +++ b/service/api/auth.go @@ -6,28 +6,34 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/spec" + "github.com/splitio/go-split-commons/v5/service/api/spec" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) // AuthAPIClient struct is responsible for authenticating client for push services type AuthAPIClient struct { - client Client - logger logging.LoggerInterface + client Client + fetchOptions *service.AuthRequestParams + logger logging.LoggerInterface } // NewAuthAPIClient instantiates and return an AuthAPIClient func NewAuthAPIClient(apikey string, cfg conf.AdvancedConfig, logger logging.LoggerInterface, metadata dtos.Metadata) *AuthAPIClient { + var specV *string + if cfg.AuthSpecVersion == spec.FlagSpec { // only valid versions + specV = common.StringRef(spec.FlagSpec) + } return &AuthAPIClient{ - client: NewHTTPClient(apikey, cfg, cfg.AuthServiceURL, logger, metadata), - logger: logger, + client: NewHTTPClient(apikey, cfg, cfg.AuthServiceURL, logger, metadata), + fetchOptions: service.MakeAuthRequestParams(specV), + logger: logger, } } // Authenticate performs authentication for push services func (a *AuthAPIClient) Authenticate() (*dtos.Token, error) { - raw, err := a.client.Get("/api/v2/auth", service.MakeAuthFetchOptions(common.StringRef(spec.FlagSpec))) + raw, err := a.client.Get("/api/v2/auth", a.fetchOptions) if err != nil { a.logger.Error("Error while authenticating for streaming", err) return nil, err diff --git a/service/api/auth_test.go b/service/api/auth_test.go index fcda3fde..a43cb074 100644 --- a/service/api/auth_test.go +++ b/service/api/auth_test.go @@ -18,7 +18,7 @@ func TestAuthErr(t *testing.T) { mockedAuth := AuthAPIClient{ client: mocks.ClientMock{ - GetCall: func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + GetCall: func(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { if endpoint != "/api/v2/auth" { t.Error("Wrong service passed") } @@ -42,7 +42,7 @@ func TestAuthPushEnabledFalse(t *testing.T) { mockedAuth := AuthAPIClient{ client: mocks.ClientMock{ - GetCall: func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + GetCall: func(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { if endpoint != "/api/v2/auth" { t.Error("Wrong service passed") } @@ -70,7 +70,7 @@ func TestAuthPushEnabledTrue(t *testing.T) { mockedAuth := AuthAPIClient{ client: mocks.ClientMock{ - GetCall: func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { + GetCall: func(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { if endpoint != "/api/v2/auth" { t.Error("Wrong service passed") } diff --git a/service/api/client.go b/service/api/client.go index d02259ad..a3cb2d6b 100644 --- a/service/api/client.go +++ b/service/api/client.go @@ -23,7 +23,7 @@ const ( // Client interface for HTTPClient type Client interface { - Get(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) + Get(endpoint string, fetchOptions service.RequestParams) ([]byte, error) Post(endpoint string, body []byte, headers map[string]string) error } @@ -56,7 +56,7 @@ func NewHTTPClient( } // Get method is a get call to an url -func (c *HTTPClient) Get(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { +func (c *HTTPClient) Get(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { serviceURL := c.url + endpoint c.logger.Debug("[GET] ", serviceURL) req, _ := http.NewRequest("GET", serviceURL, nil) diff --git a/service/api/client_test.go b/service/api/client_test.go index ffeeb5c6..53fda322 100644 --- a/service/api/client_test.go +++ b/service/api/client_test.go @@ -26,7 +26,7 @@ func TestGet(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) - txt, errg := httpClient.Get("/", service.MakeSplitFetchOptions(nil)) + txt, errg := httpClient.Get("/", service.MakeFlagRequestParams()) if errg != nil { t.Error(errg) } @@ -51,7 +51,7 @@ func TestGetSplitFetchOptions(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) - txt, errg := httpClient.Get("/test", service.MakeSplitFetchOptions(common.StringRef("v1.1")).WithChangeNumber(123456).WithTill(2345).WithFlagSetsFilter("filter")) + txt, errg := httpClient.Get("/test", service.MakeFlagRequestParams().WithChangeNumber(123456).WithTill(2345).WithFlagSetsFilter("filter").WithSpecVersion(common.StringRef("v1.1"))) if errg != nil { t.Error(errg) } @@ -61,13 +61,13 @@ func TestGetSplitFetchOptions(t *testing.T) { } } -func TestGetSegmentFetchOptions(t *testing.T) { +func TestGetSegmentRequestParams(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello, client") if r.Header.Get(CacheControlHeader) != CacheControlNoCache { t.Error("wrong header") } - expected := "/test?s=v1.1&since=123456&till=2345" + expected := "/test?since=123456&till=2345" if r.URL.String() != expected { t.Error("wrong query params, expected ", expected, "got", r.URL.String()) } @@ -76,7 +76,7 @@ func TestGetSegmentFetchOptions(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) - txt, errg := httpClient.Get("/test", service.MakeSegmentFetchOptions(common.StringRef("v1.1")).WithChangeNumber(123456).WithTill(2345)) + txt, errg := httpClient.Get("/test", service.MakeSegmentRequestParams().WithChangeNumber(123456).WithTill(2345)) if errg != nil { t.Error(errg) } @@ -101,7 +101,7 @@ func TestGetAuthOptions(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) httpClient := NewHTTPClient("", conf.AdvancedConfig{}, ts.URL, logger, dtos.Metadata{}) - txt, errg := httpClient.Get("/test", service.MakeAuthFetchOptions(common.StringRef("v1.1"))) + txt, errg := httpClient.Get("/test", service.MakeAuthRequestParams(common.StringRef("v1.1"))) if errg != nil { t.Error(errg) } diff --git a/service/api/http_fetchers.go b/service/api/http_fetchers.go index 105cb122..4927beb2 100644 --- a/service/api/http_fetchers.go +++ b/service/api/http_fetchers.go @@ -8,6 +8,8 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v5/service/api/spec" + "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) @@ -16,7 +18,7 @@ type httpFetcherBase struct { logger logging.LoggerInterface } -func (h *httpFetcherBase) fetchRaw(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { +func (h *httpFetcherBase) fetchRaw(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { data, err := h.client.Get(endpoint, fetchOptions) if err != nil { return nil, err @@ -28,22 +30,28 @@ func (h *httpFetcherBase) fetchRaw(endpoint string, fetchOptions service.FetchOp type HTTPSplitFetcher struct { httpFetcherBase flagSetsFilter string + specVersion *string } // NewHTTPSplitFetcher instantiates and return an HTTPSplitFetcher func NewHTTPSplitFetcher(apikey string, cfg conf.AdvancedConfig, logger logging.LoggerInterface, metadata dtos.Metadata) service.SplitFetcher { + var specVersion *string + if cfg.FlagsSpecVersion == spec.FlagSpec { // only match valid versions + specVersion = common.StringRef(spec.FlagSpec) + } return &HTTPSplitFetcher{ httpFetcherBase: httpFetcherBase{ client: NewHTTPClient(apikey, cfg, cfg.SdkURL, logger, metadata), logger: logger, }, flagSetsFilter: strings.Join(cfg.FlagSetsFilter, ","), + specVersion: specVersion, } } // Fetch makes an http call to the split backend and returns the list of updated splits -func (f *HTTPSplitFetcher) Fetch(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { - fetchOptions.WithFlagSetsFilter(f.flagSetsFilter) +func (f *HTTPSplitFetcher) Fetch(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { + fetchOptions.WithFlagSetsFilter(f.flagSetsFilter).WithSpecVersion(f.specVersion) data, err := f.fetchRaw("/splitChanges", fetchOptions) if err != nil { f.logger.Error("Error fetching split changes ", err) @@ -76,7 +84,7 @@ func NewHTTPSegmentFetcher(apikey string, cfg conf.AdvancedConfig, logger loggin } // Fetch issues a GET request to the split backend and returns the contents of a particular segment -func (f *HTTPSegmentFetcher) Fetch(segmentName string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { +func (f *HTTPSegmentFetcher) Fetch(segmentName string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { var bufferQuery bytes.Buffer bufferQuery.WriteString("/segmentChanges/") bufferQuery.WriteString(segmentName) diff --git a/service/api/http_fetchers_test.go b/service/api/http_fetchers_test.go index 53af3159..c02411c7 100644 --- a/service/api/http_fetchers_test.go +++ b/service/api/http_fetchers_test.go @@ -13,7 +13,6 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) @@ -25,12 +24,24 @@ func TestSpitChangesFetch(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Cache-Control") != "no-cache" { + if r.Header.Get(CacheControlHeader) != CacheControlNoCache { t.Error("wrong cache control header") } if r.URL.Query().Get("since") != "123456" { t.Error("wrong since") } + if r.URL.Query().Get("till") != "" { + t.Error("wrong till") + } + if r.URL.Query().Get("sets") != "" { + t.Error("wrong sets") + } + if r.URL.Query().Get("s") != "1.1" { + t.Error("wrong spec") + } + if r.URL.RawQuery != "s=1.1&since=123456" { + t.Error("wrong query params") + } fmt.Fprintln(w, fmt.Sprintf(string(splitsMock), splitMock)) })) defer ts.Close() @@ -38,14 +49,15 @@ func TestSpitChangesFetch(t *testing.T) { splitFetcher := NewHTTPSplitFetcher( "", conf.AdvancedConfig{ - EventsURL: ts.URL, - SdkURL: ts.URL, + EventsURL: ts.URL, + SdkURL: ts.URL, + FlagsSpecVersion: "1.1", }, logger, dtos.Metadata{}, ) - splitChangesDTO, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) + splitChangesDTO, err := splitFetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(123456)) if err != nil { t.Error(err) } @@ -91,7 +103,7 @@ func TestSpitChangesFetchWithFlagOptions(t *testing.T) { dtos.Metadata{}, ) - _, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) + _, err := splitFetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(123456)) if err != nil { t.Error(err) } @@ -105,7 +117,7 @@ func TestSpitChangesFetchWithFlagOptions(t *testing.T) { t.Error("Expected to not have till") } expectedTill := int64(10000) - _, err = splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456).WithTill(expectedTill)) + _, err = splitFetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(123456).WithTill(expectedTill)) if err != nil { t.Error(err) } @@ -144,7 +156,7 @@ func TestSpitChangesFetchWithFlagSetsFilter(t *testing.T) { dtos.Metadata{}, ) - _, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) + _, err := splitFetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(123456)) if err != nil { t.Error(err) } @@ -174,6 +186,68 @@ func TestSpitChangesFetchWithFlagSetsFilter(t *testing.T) { } } +func TestSpitChangesFetchWithAll(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + + var cacheControl string + var queryParams url.Values + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + cacheControl = r.Header.Get(CacheControlHeader) + queryParams = r.URL.Query() + fmt.Fprintln(w, fmt.Sprintf(string(splitsMock), splitMock)) + + if r.URL.RawQuery != "s=1.1&since=123456&sets=one%2Ctwo&till=10000" { + t.Error("wrong query params") + } + })) + defer ts.Close() + + splitFetcher := NewHTTPSplitFetcher( + "", + conf.AdvancedConfig{ + EventsURL: ts.URL, + SdkURL: ts.URL, + FlagSetsFilter: []string{"one", "two"}, + FlagsSpecVersion: "1.1", + }, + logger, + dtos.Metadata{}, + ) + + _, err := splitFetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(123456).WithTill(10000)) + if err != nil { + t.Error(err) + } + if cacheControl != CacheControlNoCache { + t.Error("Wrong header sent") + } + if queryParams.Get("since") != "123456" { + t.Error("Expected to have since") + } + if !queryParams.Has("till") { + t.Error("Expected to have till") + } + if !queryParams.Has("sets") { + t.Error("Expected to have sets") + } + if queryParams.Get("s") != "1.1" { + t.Error("Expected to have spec") + } + asString := queryParams.Get("sets") + asArray := strings.Split(asString, ",") + setsToTest := make(map[string]struct{}) + for _, featureFlag := range asArray { + setsToTest[featureFlag] = struct{}{} + } + if _, ok := setsToTest["one"]; !ok { + t.Error("Expected one to be present") + } + if _, ok := setsToTest["two"]; !ok { + t.Error("Expected two to be present") + } +} + func TestSpitChangesFetchHTTPError(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) @@ -193,7 +267,7 @@ func TestSpitChangesFetchHTTPError(t *testing.T) { dtos.Metadata{}, ) - _, err := splitFetcher.Fetch(service.MakeSplitFetchOptions(common.AsStringOrNil("v1.1"))) + _, err := splitFetcher.Fetch(service.MakeFlagRequestParams()) if err == nil { t.Error("Error expected but not found") } @@ -217,7 +291,7 @@ func TestSegmentChangesFetch(t *testing.T) { dtos.Metadata{}, ) - segmentFetched, err := segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1"))) + segmentFetched, err := segmentFetcher.Fetch("employees", service.MakeSegmentRequestParams()) if err != nil { t.Error("Error fetching segment", err) return @@ -246,7 +320,7 @@ func TestSegmentChangesFetchHTTPError(t *testing.T) { dtos.Metadata{}, ) - _, err := segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1"))) + _, err := segmentFetcher.Fetch("employees", service.MakeSegmentRequestParams()) if err == nil { t.Error("Error expected but not found") } @@ -275,7 +349,7 @@ func TestSegmentChangesFetchWithFlagOptions(t *testing.T) { dtos.Metadata{}, ) - _, err := segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1")).WithChangeNumber(123456)) + _, err := segmentFetcher.Fetch("employees", service.MakeSegmentRequestParams().WithChangeNumber(123456)) if err != nil { t.Error(err) } @@ -289,7 +363,7 @@ func TestSegmentChangesFetchWithFlagOptions(t *testing.T) { t.Error("Expected to not have till") } expectedTill := int64(10000) - _, err = segmentFetcher.Fetch("employees", service.MakeSegmentFetchOptions(common.AsStringOrNil("v1.1")).WithTill(expectedTill).WithChangeNumber(123456)) + _, err = segmentFetcher.Fetch("employees", service.MakeSegmentRequestParams().WithTill(expectedTill).WithChangeNumber(123456)) if err != nil { t.Error(err) } diff --git a/service/api/mocks/client.go b/service/api/mocks/client.go index afbc6e54..21f6668c 100644 --- a/service/api/mocks/client.go +++ b/service/api/mocks/client.go @@ -4,12 +4,12 @@ import "github.com/splitio/go-split-commons/v5/service" // ClientMock mocks client type ClientMock struct { - GetCall func(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) + GetCall func(endpoint string, fetchOptions service.RequestParams) ([]byte, error) PostCall func(endpoint string, body []byte, headers map[string]string) error } // Get mocks Get -func (c ClientMock) Get(endpoint string, fetchOptions service.FetchOptions) ([]byte, error) { +func (c ClientMock) Get(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { return c.GetCall(endpoint, fetchOptions) } diff --git a/spec/spec.go b/service/api/spec/spec.go similarity index 100% rename from spec/spec.go rename to service/api/spec/spec.go diff --git a/service/commons.go b/service/commons.go index f5a3f598..b8e91b90 100644 --- a/service/commons.go +++ b/service/commons.go @@ -23,47 +23,51 @@ type queryParamater struct { value string } -type FetchOptions interface { +type RequestParams interface { Apply(request *http.Request) error } -type BaseOptions struct { +type BaseRequestParams struct { CacheControlHeaders bool - SpecVersion *string } -type SplitFetchOptions struct { - BaseOptions +type FlagRequestParams struct { + BaseRequestParams ChangeNumber int64 FlagSetsFilter string + SpecVersion *string Till *int64 } -func MakeSplitFetchOptions(specVersion *string) *SplitFetchOptions { - return &SplitFetchOptions{ - BaseOptions: BaseOptions{ +func MakeFlagRequestParams() *FlagRequestParams { + return &FlagRequestParams{ + BaseRequestParams: BaseRequestParams{ CacheControlHeaders: true, - SpecVersion: specVersion, }, } } -func (s *SplitFetchOptions) WithChangeNumber(changeNumber int64) *SplitFetchOptions { +func (s *FlagRequestParams) WithChangeNumber(changeNumber int64) *FlagRequestParams { s.ChangeNumber = changeNumber return s } -func (s *SplitFetchOptions) WithFlagSetsFilter(flagSetsFilter string) *SplitFetchOptions { +func (s *FlagRequestParams) WithFlagSetsFilter(flagSetsFilter string) *FlagRequestParams { s.FlagSetsFilter = flagSetsFilter return s } -func (s *SplitFetchOptions) WithTill(till int64) *SplitFetchOptions { +func (s *FlagRequestParams) WithSpecVersion(specVersion *string) *FlagRequestParams { + s.SpecVersion = specVersion + return s +} + +func (s *FlagRequestParams) WithTill(till int64) *FlagRequestParams { s.Till = common.Int64Ref(till) return s } -func (s *SplitFetchOptions) Apply(request *http.Request) error { +func (s *FlagRequestParams) Apply(request *http.Request) error { request.Header.Set(cacheControl, cacheControlNoCache) queryParameters := []queryParamater{} @@ -82,38 +86,34 @@ func (s *SplitFetchOptions) Apply(request *http.Request) error { return nil } -type SegmentFetchOptions struct { - BaseOptions +type SegmentRequestParams struct { + BaseRequestParams ChangeNumber int64 Till *int64 } -func MakeSegmentFetchOptions(specVersion *string) *SegmentFetchOptions { - return &SegmentFetchOptions{ - BaseOptions: BaseOptions{ +func MakeSegmentRequestParams() *SegmentRequestParams { + return &SegmentRequestParams{ + BaseRequestParams: BaseRequestParams{ CacheControlHeaders: true, - SpecVersion: specVersion, }, } } -func (s *SegmentFetchOptions) WithChangeNumber(changeNumber int64) *SegmentFetchOptions { +func (s *SegmentRequestParams) WithChangeNumber(changeNumber int64) *SegmentRequestParams { s.ChangeNumber = changeNumber return s } -func (s *SegmentFetchOptions) WithTill(till int64) *SegmentFetchOptions { +func (s *SegmentRequestParams) WithTill(till int64) *SegmentRequestParams { s.Till = common.Int64Ref(till) return s } -func (s *SegmentFetchOptions) Apply(request *http.Request) error { +func (s *SegmentRequestParams) Apply(request *http.Request) error { request.Header.Set(cacheControl, cacheControlNoCache) queryParameters := []queryParamater{} - if s.SpecVersion != nil { - queryParameters = append(queryParameters, queryParamater{key: spec, value: common.StringFromRef(s.SpecVersion)}) - } queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.ChangeNumber, 10)}) if s.Till != nil { queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.Till, 10)}) @@ -123,20 +123,21 @@ func (s *SegmentFetchOptions) Apply(request *http.Request) error { return nil } -type AuthFetchOptions struct { - BaseOptions +type AuthRequestParams struct { + BaseRequestParams + SpecVersion *string } -func MakeAuthFetchOptions(specVersion *string) *AuthFetchOptions { - return &AuthFetchOptions{ - BaseOptions: BaseOptions{ +func MakeAuthRequestParams(specVersion *string) *AuthRequestParams { + return &AuthRequestParams{ + BaseRequestParams: BaseRequestParams{ CacheControlHeaders: true, - SpecVersion: specVersion, }, + SpecVersion: specVersion, } } -func (s *AuthFetchOptions) Apply(request *http.Request) error { +func (s *AuthRequestParams) Apply(request *http.Request) error { request.Header.Set(cacheControl, cacheControlNoCache) queryParams := request.URL.Query() diff --git a/service/commons_test.go b/service/commons_test.go index 95bd871a..abe94d78 100644 --- a/service/commons_test.go +++ b/service/commons_test.go @@ -8,7 +8,7 @@ import ( ) func TestSplitFetchOptions(t *testing.T) { - fetchOptions := MakeSplitFetchOptions(common.StringRef("v1")).WithChangeNumber(123456).WithFlagSetsFilter("filter").WithTill(*common.Int64Ref(123)) + fetchOptions := MakeFlagRequestParams().WithChangeNumber(123456).WithFlagSetsFilter("filter").WithTill(*common.Int64Ref(123)).WithSpecVersion(common.StringRef("1.1")) req, _ := http.NewRequest("GET", "test", nil) fetchOptions.Apply(req) @@ -18,7 +18,7 @@ func TestSplitFetchOptions(t *testing.T) { if req.URL.Query().Get(since) != "123456" { t.Error("Change number not set") } - if req.URL.Query().Get(spec) != "v1" { + if req.URL.Query().Get(spec) != "1.1" { t.Error("Spec version not set") } if req.URL.Query().Get(sets) != "filter" { @@ -27,13 +27,13 @@ func TestSplitFetchOptions(t *testing.T) { if req.URL.Query().Get(till) != "123" { t.Error("Till not set") } - if req.URL.String() != "test?s=v1&since=123456&sets=filter&till=123" { + if req.URL.String() != "test?s=1.1&since=123456&sets=filter&till=123" { t.Error("Query params not set correctly, expected: test?s=v1&since=123456&sets=filter&till=123, got:", req.URL.String()) } } -func TestSegmentFetchOptions(t *testing.T) { - fetchOptions := MakeSegmentFetchOptions(common.StringRef("v1")).WithChangeNumber(123456).WithTill(*common.Int64Ref(123)) +func TestSegmentRequestParams(t *testing.T) { + fetchOptions := MakeSegmentRequestParams().WithChangeNumber(123456).WithTill(*common.Int64Ref(123)) req, _ := http.NewRequest("GET", "test", nil) fetchOptions.Apply(req) @@ -44,30 +44,27 @@ func TestSegmentFetchOptions(t *testing.T) { if req.URL.Query().Get(since) != "123456" { t.Error("Change number not set") } - if req.URL.Query().Get(spec) != "v1" { - t.Error("Spec version not set") - } if req.URL.Query().Get(till) != "123" { t.Error("Till not set") } - if req.URL.String() != "test?s=v1&since=123456&till=123" { + if req.URL.String() != "test?since=123456&till=123" { t.Error("Query params not set correctly, expected: test?s=v1&since=123456&till=123, got:", req.URL.String()) } } -func TestAuthFetchOptions(t *testing.T) { - fetchOptions := MakeAuthFetchOptions(common.StringRef("v1")) +func TestAuthRequestParams(t *testing.T) { + fetchOptions := MakeAuthRequestParams(common.StringRef("1.1")) req, _ := http.NewRequest("GET", "test", nil) fetchOptions.Apply(req) if req.Header.Get(cacheControl) != cacheControlNoCache { t.Error("Cache control header not set") } - if req.URL.Query().Get(spec) != "v1" { + if req.URL.Query().Get(spec) != "1.1" { t.Error("Spec version not set") } - if req.URL.String() != "test?s=v1" { + if req.URL.String() != "test?s=1.1" { t.Error("Query params not set correctly, expected: test?s=v1, got:", req.URL.String()) } } diff --git a/service/interfaces.go b/service/interfaces.go index 13a302aa..8d702bee 100644 --- a/service/interfaces.go +++ b/service/interfaces.go @@ -11,12 +11,12 @@ type AuthClient interface { // SplitFetcher interface to be implemented by Split Fetchers type SplitFetcher interface { - Fetch(fetchOptions *SplitFetchOptions) (*dtos.SplitChangesDTO, error) + Fetch(fetchOptions *FlagRequestParams) (*dtos.SplitChangesDTO, error) } // SegmentFetcher interface to be implemented by Split Fetchers type SegmentFetcher interface { - Fetch(name string, fetchOptions *SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) + Fetch(name string, fetchOptions *SegmentRequestParams) (*dtos.SegmentChangesDTO, error) } // ImpressionsRecorder interface to be implemented by Impressions loggers diff --git a/service/local/segmentFetcher.go b/service/local/segmentFetcher.go index 1c31fc93..d64a6446 100644 --- a/service/local/segmentFetcher.go +++ b/service/local/segmentFetcher.go @@ -78,7 +78,7 @@ func (s *FileSegmentFetcher) processSegmentJson(fileContents []byte, segmentName } // Fetch parses the file and returns the appropriate structures -func (s *FileSegmentFetcher) Fetch(segmentName string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { +func (s *FileSegmentFetcher) Fetch(segmentName string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { fileContents, err := s.reader.ReadFile(fmt.Sprintf("%v/%v.json", s.segmentDirectory, segmentName)) if err != nil { s.logger.Error(fmt.Sprintf("could not find the segmentChange file for %s. error: %v", segmentName, err)) diff --git a/service/local/segmentFetcher_test.go b/service/local/segmentFetcher_test.go index 8b156606..45d4d91e 100644 --- a/service/local/segmentFetcher_test.go +++ b/service/local/segmentFetcher_test.go @@ -17,7 +17,7 @@ func TestLocalSegmentFetcherJson(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - res, err := fetcher.Fetch("segment_mock", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch("segment_mock", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -44,7 +44,7 @@ func TestInvalidTill(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - res, err := fetcher.Fetch("segmentTillInvalid", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch("segmentTillInvalid", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("should not fail.") } @@ -138,7 +138,7 @@ func TestFetchSomeSegments(t *testing.T) { } // 0) The CN from storage is -1, till and since are -1, and sha doesn't exist in the hash. It's going to return a segment change with updates. - segmentChange, _ := mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + segmentChange, _ := mockedFetchers.Fetch("test_1", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if segmentChange.Since != -1 || segmentChange.Till != -1 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -151,7 +151,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 1) The CN from storage is -1, till and since are -1, and sha is different than before. It's going to return a segment change with updates. - segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if segmentChange.Since != -1 || segmentChange.Till != -1 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -164,7 +164,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 2) The CN from storage is -1, till is 2323, and since is -1, and sha is the same as before. It's going to return a segment change with the same data. - segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if segmentChange.Since != -1 || segmentChange.Till != -1 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -177,7 +177,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 3) The CN from storage is -1, till is 2323, and since is -1, sha is different than before. It's going to return a segment change with updates. - segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if segmentChange.Since != 2323 || segmentChange.Till != 2323 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -190,7 +190,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 4) The CN from storage is 2323, till is 445345, and since is -1, and sha is the same as before. It's going to return a segment change with same data. - segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(2323)) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentRequestParams().WithChangeNumber(2323)) if segmentChange.Since != 2323 || segmentChange.Till != 2323 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -203,7 +203,7 @@ func TestFetchSomeSegments(t *testing.T) { fetches++ // 5) The CN from storage is 2323, till and since are -1, and sha is different than before. It's going to return a segment change with updates. - segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentFetchOptions(nil).WithChangeNumber(2323)) + segmentChange, _ = mockedFetchers.Fetch("test_1", service.MakeSegmentRequestParams().WithChangeNumber(2323)) if segmentChange.Since != 2323 || segmentChange.Till != 2323 { t.Error("Wrong since/till. Got: ", segmentChange.Since, segmentChange.Till) } @@ -221,7 +221,7 @@ func TestSegmentWithoutName(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - _, err := fetcher.Fetch("segmentWithoutName", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + _, err := fetcher.Fetch("segmentWithoutName", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if err == nil { t.Error("fetching should fail.") } @@ -232,7 +232,7 @@ func TestSegmentSanitization(t *testing.T) { fetcher := NewFileSegmentFetcher("../../testdata", logger) - res, err := fetcher.Fetch("segmentSanitization", service.MakeSegmentFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch("segmentSanitization", service.MakeSegmentRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } diff --git a/service/local/splitFetcher.go b/service/local/splitFetcher.go index 191ef82c..82f267b1 100644 --- a/service/local/splitFetcher.go +++ b/service/local/splitFetcher.go @@ -256,7 +256,7 @@ func (s *FileSplitFetcher) processSplitJson(data string, changeNumber int64) (*d } // Fetch parses the file and returns the appropriate structures -func (s *FileSplitFetcher) Fetch(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { +func (s *FileSplitFetcher) Fetch(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { fileContents, err := s.reader.ReadFile(s.splitFile) if err != nil { return nil, err diff --git a/service/local/splitFetcher_test.go b/service/local/splitFetcher_test.go index ffee4c2b..5353c792 100644 --- a/service/local/splitFetcher_test.go +++ b/service/local/splitFetcher_test.go @@ -40,7 +40,7 @@ func TestLocalSplitFetcher(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatClassic) - res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -55,7 +55,7 @@ func TestLocalSplitFetcher(t *testing.T) { // second call -- no change -- since == till - res, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(0)) + res, err = fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(0)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -74,7 +74,7 @@ func TestLocalSplitFetcher(t *testing.T) { // third call -- change -- till > since - res, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(0)) + res, err = fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(0)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -89,7 +89,7 @@ func TestLocalSplitFetcher(t *testing.T) { // fourth call -- no change -- till != since - res, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(1)) + res, err = fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -108,7 +108,7 @@ func TestLocalSplitFetcherJson(t *testing.T) { fetcher := NewFileSplitFetcher("../../testdata/splitChange_mock.json", logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) } @@ -148,7 +148,7 @@ func TestLocalSplitFetcherJsonTest1(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - _, err = fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + _, err = fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail.") @@ -184,7 +184,7 @@ func TestFetchSomeSplits(t *testing.T) { fileFormat: SplitFileFormatJSON, } // 0) The CN from storage is -1, till and since are -1, and sha doesn't exist in the hash. It's going to return a split change with updates. - splitChange, _ := mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + splitChange, _ := mockedFetchers.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if splitChange.Since != -1 || splitChange.Till != -1 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -194,7 +194,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 1) The CN from storage is -1, till and since are -1, and sha is different than before. It's going to return a split change with updates. - splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + splitChange, _ = mockedFetchers.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if splitChange.Since != -1 || splitChange.Till != -1 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -204,7 +204,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 2) The CN from storage is -1, till is 2323, and since is -1, and sha is the same as before. It's going to return a split change with the same data. - splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + splitChange, _ = mockedFetchers.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if splitChange.Since != -1 || splitChange.Till != -1 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -214,7 +214,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 3) The CN from storage is -1, till is 2323, and since is -1, sha is different than before. It's going to return a split change with updates. - splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + splitChange, _ = mockedFetchers.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if splitChange.Since != 2323 || splitChange.Till != 2323 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -224,7 +224,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 4) The CN from storage is 2323, till is 445345, and since is -1, and sha is the same as before. It's going to return a split change with same data. - splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(2323)) + splitChange, _ = mockedFetchers.Fetch(service.MakeFlagRequestParams().WithChangeNumber(2323)) if splitChange.Since != 2323 || splitChange.Till != 2323 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -234,7 +234,7 @@ func TestFetchSomeSplits(t *testing.T) { fetches++ // 5) The CN from storage is 2323, till and since are -1, and sha is different than before. It's going to return a split change with updates. - splitChange, _ = mockedFetchers.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(2323)) + splitChange, _ = mockedFetchers.Fetch(service.MakeFlagRequestParams().WithChangeNumber(2323)) if splitChange.Since != 2323 || splitChange.Till != 2323 { t.Error("Wrong since/till. Got: ", splitChange.Since, splitChange.Till) } @@ -261,7 +261,7 @@ func TestSplitWithoutName(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) @@ -290,7 +290,7 @@ func TestSplitMatchersEmpty(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) @@ -328,7 +328,7 @@ func TestSplitSanitization(t *testing.T) { logger := logging.NewLogger(nil) fetcher := NewFileSplitFetcher(file.Name(), logger, SplitFileFormatJSON) - res, err := fetcher.Fetch(service.MakeSplitFetchOptions(nil).WithChangeNumber(-1)) + res, err := fetcher.Fetch(service.MakeFlagRequestParams().WithChangeNumber(-1)) if err != nil { t.Error("fetching should not fail. Got: ", err) diff --git a/service/mocks/segment.go b/service/mocks/segment.go index 87157c8a..5c78ffd2 100644 --- a/service/mocks/segment.go +++ b/service/mocks/segment.go @@ -7,10 +7,10 @@ import ( // MockSegmentFetcher mocked implementation of segment fetcher type MockSegmentFetcher struct { - FetchCall func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) + FetchCall func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) } // Fetch mock -func (m MockSegmentFetcher) Fetch(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { +func (m MockSegmentFetcher) Fetch(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { return m.FetchCall(name, fetchOptions) } diff --git a/service/mocks/split.go b/service/mocks/split.go index 9841b504..d915776e 100644 --- a/service/mocks/split.go +++ b/service/mocks/split.go @@ -7,10 +7,10 @@ import ( // MockSplitFetcher mocked implementation of split fetcher type MockSplitFetcher struct { - FetchCall func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) + FetchCall func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) } // Fetch mock -func (m MockSplitFetcher) Fetch(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { +func (m MockSplitFetcher) Fetch(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { return m.FetchCall(fetchOptions) } diff --git a/synchronizer/local_test.go b/synchronizer/local_test.go index 8f0762ff..99bb0d2c 100644 --- a/synchronizer/local_test.go +++ b/synchronizer/local_test.go @@ -20,7 +20,7 @@ func TestLocalSyncAllError(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") @@ -54,7 +54,7 @@ func TestLocalSyncAllOk(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") @@ -103,7 +103,7 @@ func TestLocalPeriodicFetching(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) if fetchOptions.ChangeNumber != -1 { t.Error("Wrong changenumber passed") diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index 9e241688..0cab1d7e 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -33,7 +33,7 @@ func TestSyncAllErrorSplits(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("no cache should be true") } @@ -93,7 +93,7 @@ func TestSyncAllErrorInSegments(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -109,7 +109,7 @@ func TestSyncAllErrorInSegments(t *testing.T) { }, }, SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -185,7 +185,7 @@ func TestSyncAllOk(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -201,7 +201,7 @@ func TestSyncAllOk(t *testing.T) { }, }, SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -295,7 +295,7 @@ func TestPeriodicFetching(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -311,7 +311,7 @@ func TestPeriodicFetching(t *testing.T) { }, }, SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -539,7 +539,7 @@ func TestSplitUpdateWorkerCNGreaterThanFFChange(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return nil, nil }, @@ -588,7 +588,7 @@ func TestSplitUpdateWorkerStorageCNEqualsFFCN(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return nil, nil }, @@ -644,7 +644,7 @@ func TestSplitUpdateWorkerFFPcnEqualsFFNotNil(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return nil, nil }, @@ -707,7 +707,7 @@ func TestSplitUpdateWorkerGetCNFromStorageError(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) if fetchOptions.ChangeNumber != 0 { t.Error("Wrong changenumber passed") @@ -785,7 +785,7 @@ func TestSplitUpdateWorkerFFIsNil(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return &dtos.SplitChangesDTO{ Till: 4, @@ -853,7 +853,7 @@ func TestSplitUpdateWorkerFFPcnDifferentStorageCN(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) return &dtos.SplitChangesDTO{ Till: 2, @@ -949,7 +949,7 @@ func TestSplitUpdateWithReferencedSegments(t *testing.T) { var recordUpdateCall int64 logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{SegmentFetcher: httpMocks.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } diff --git a/synchronizer/worker/segment/segment.go b/synchronizer/worker/segment/segment.go index e3059456..8e15e545 100644 --- a/synchronizer/worker/segment/segment.go +++ b/synchronizer/worker/segment/segment.go @@ -103,7 +103,7 @@ func (s *UpdaterImpl) processUpdate(segmentChanges *dtos.SegmentChangesDTO) { s.segmentStorage.Update(segmentChanges.Name, toAdd, toRemove, segmentChanges.Till) } -func (s *UpdaterImpl) fetchUntil(name string, fetchOptions *service.SegmentFetchOptions) (*UpdateResult, error) { +func (s *UpdaterImpl) fetchUntil(name string, fetchOptions *service.SegmentRequestParams) (*UpdateResult, error) { var updatedKeys []string var err error var currentSince int64 @@ -139,7 +139,7 @@ func (s *UpdaterImpl) fetchUntil(name string, fetchOptions *service.SegmentFetch }, err } -func (s *UpdaterImpl) attemptSegmentSync(name string, till *int64, fetchOptions *service.SegmentFetchOptions) (internalSegmentSync, error) { +func (s *UpdaterImpl) attemptSegmentSync(name string, till *int64, fetchOptions *service.SegmentRequestParams) (internalSegmentSync, error) { internalBackoff := backoff.New(s.onDemandFetchBackoffBase, s.onDemandFetchBackoffMaxWait) remainingAttempts := onDemandFetchBackoffMaxRetries for { @@ -158,7 +158,7 @@ func (s *UpdaterImpl) attemptSegmentSync(name string, till *int64, fetchOptions // SynchronizeSegment syncs segment func (s *UpdaterImpl) SynchronizeSegment(name string, till *int64) (*UpdateResult, error) { - fetchOptions := service.MakeSegmentFetchOptions(nil) + fetchOptions := service.MakeSegmentRequestParams() s.hcMonitor.NotifyEvent(application.Segments) currentSince, _ := s.segmentStorage.ChangeNumber(name) @@ -175,7 +175,7 @@ func (s *UpdaterImpl) SynchronizeSegment(name string, till *int64) (*UpdateResul s.logger.Debug(fmt.Sprintf("Refresh completed in %d attempts.", attempts)) return internalSyncResult.updateResult, nil } - withCDNBypass := service.MakeSegmentFetchOptions(nil).WithTill(internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN + withCDNBypass := service.MakeSegmentRequestParams().WithTill(internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN internalSyncResultCDNBypass, err := s.attemptSegmentSync(name, till, withCDNBypass) withoutCDNattempts := onDemandFetchBackoffMaxRetries - internalSyncResultCDNBypass.attempt if err != nil { diff --git a/synchronizer/worker/segment/segment_test.go b/synchronizer/worker/segment/segment_test.go index ff5e41b3..d3deaadf 100644 --- a/synchronizer/worker/segment/segment_test.go +++ b/synchronizer/worker/segment/segment_test.go @@ -45,7 +45,7 @@ func TestSegmentsSynchronizerError(t *testing.T) { } segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("should have requested no cache") } @@ -149,7 +149,7 @@ func TestSegmentSynchronizer(t *testing.T) { } segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("should have requested no cache") } @@ -226,7 +226,7 @@ func TestSegmentSyncUpdate(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if name != "segment1" { t.Error("Wrong name") } @@ -340,7 +340,7 @@ func TestSegmentSyncProcess(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if name != "segment1" && name != "segment2" { t.Error("Wrong name") } @@ -425,7 +425,7 @@ func TestSegmentTill(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { atomic.AddInt64(&call, 1) return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil }, @@ -489,7 +489,7 @@ func TestSegmentCDNBypass(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: @@ -568,7 +568,7 @@ func TestSegmentCDNBypassLimit(t *testing.T) { segmentStorage := mutexmap.NewMMSegmentStorage() segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: @@ -633,7 +633,7 @@ func TestSegmentSyncConcurrencyLimit(t *testing.T) { var done sync.Map var inProgress int32 segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if current := atomic.AddInt32(&inProgress, 1); current > maxConcurrency { t.Errorf("throguhput exceeded max expected concurrency of %d. Is: %d", maxConcurrency, current) } diff --git a/synchronizer/worker/split/split.go b/synchronizer/worker/split/split.go index a0e6ee0c..6b58a8c2 100644 --- a/synchronizer/worker/split/split.go +++ b/synchronizer/worker/split/split.go @@ -8,7 +8,6 @@ import ( "github.com/splitio/go-split-commons/v5/flagsets" "github.com/splitio/go-split-commons/v5/healthcheck/application" "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/spec" "github.com/splitio/go-split-commons/v5/storage" "github.com/splitio/go-split-commons/v5/telemetry" "github.com/splitio/go-toolkit/v5/backoff" @@ -90,7 +89,7 @@ func (s *UpdaterImpl) processUpdate(featureFlags *dtos.SplitChangesDTO) { } // fetchUntil Hit endpoint, update storage and return when since==till. -func (s *UpdaterImpl) fetchUntil(fetchOptions *service.SplitFetchOptions) (*UpdateResult, error) { +func (s *UpdaterImpl) fetchUntil(fetchOptions *service.FlagRequestParams) (*UpdateResult, error) { // just guessing sizes so the we don't realloc immediately segmentReferences := make([]string, 0, 10) updatedSplitNames := make([]string, 0, 10) @@ -129,7 +128,7 @@ func (s *UpdaterImpl) fetchUntil(fetchOptions *service.SplitFetchOptions) (*Upda } // attemptSplitSync Hit endpoint, update storage and return True if sync is complete. -func (s *UpdaterImpl) attemptSplitSync(fetchOptions *service.SplitFetchOptions, till *int64) (internalSplitSync, error) { +func (s *UpdaterImpl) attemptSplitSync(fetchOptions *service.FlagRequestParams, till *int64) (internalSplitSync, error) { internalBackoff := backoff.New(s.onDemandFetchBackoffBase, s.onDemandFetchBackoffMaxWait) remainingAttempts := onDemandFetchBackoffMaxRetries for { @@ -153,7 +152,7 @@ func (s *UpdaterImpl) SynchronizeSplits(till *int64) (*UpdateResult, error) { return &UpdateResult{}, nil } - fetchOptions := service.MakeSplitFetchOptions(common.StringRefOrNil(spec.FlagSpec)) + fetchOptions := service.MakeFlagRequestParams() internalSyncResult, err := s.attemptSplitSync(fetchOptions, till) attempts := onDemandFetchBackoffMaxRetries - internalSyncResult.attempt if err != nil { @@ -163,7 +162,7 @@ func (s *UpdaterImpl) SynchronizeSplits(till *int64) (*UpdateResult, error) { s.logger.Debug(fmt.Sprintf("Refresh completed in %d attempts.", attempts)) return internalSyncResult.updateResult, nil } - withCDNBypass := service.MakeSplitFetchOptions(common.StringRefOrNil(spec.FlagSpec)).WithTill(internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN + withCDNBypass := service.MakeFlagRequestParams().WithTill(internalSyncResult.updateResult.NewChangeNumber) // Set flag for bypassing CDN internalSyncResultCDNBypass, err := s.attemptSplitSync(withCDNBypass, till) withoutCDNattempts := onDemandFetchBackoffMaxRetries - internalSyncResultCDNBypass.attempt if err != nil { diff --git a/synchronizer/worker/split/split_test.go b/synchronizer/worker/split/split_test.go index 34b2f9db..e2a42eb6 100644 --- a/synchronizer/worker/split/split_test.go +++ b/synchronizer/worker/split/split_test.go @@ -27,7 +27,7 @@ func TestSplitSynchronizerError(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -75,7 +75,7 @@ func TestSplitSynchronizerErrorScRequestURITooLong(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCall, 1) if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") @@ -155,7 +155,7 @@ func TestSplitSynchronizer(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true") } @@ -218,7 +218,7 @@ func TestSplitSyncProcess(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch call { case 1: @@ -325,7 +325,7 @@ func TestSplitTill(t *testing.T) { mockedSplit1 := dtos.SplitDTO{Name: "split1", Killed: false, Status: "ACTIVE", TrafficTypeName: "one"} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, @@ -370,7 +370,7 @@ func TestByPassingCDN(t *testing.T) { mockedSplit1 := dtos.SplitDTO{Name: "split1", Killed: false, Status: "ACTIVE", TrafficTypeName: "one"} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: @@ -443,7 +443,7 @@ func TestByPassingCDNLimit(t *testing.T) { mockedSplit1 := dtos.SplitDTO{Name: "split1", Killed: false, Status: "ACTIVE", TrafficTypeName: "one"} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: @@ -519,7 +519,7 @@ func TestProcessFFChange(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return nil, nil }, @@ -550,7 +550,7 @@ func TestAddOrUpdateFeatureFlagNil(t *testing.T) { UpdateCall: func(toAdd, toRemove []dtos.SplitDTO, changeNumber int64) {}, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return &dtos.SplitChangesDTO{ Till: 2, @@ -596,7 +596,7 @@ func TestAddOrUpdateFeatureFlagPcnEquals(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return nil, nil }, @@ -640,7 +640,7 @@ func TestAddOrUpdateFeatureFlagArchive(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return nil, nil }, @@ -677,7 +677,7 @@ func TestAddOrUpdateFFCNFromStorageError(t *testing.T) { }, } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCallCalled, 1) return &dtos.SplitChangesDTO{ Till: 2, @@ -764,7 +764,7 @@ func TestSplitSyncWithSets(t *testing.T) { mockedSplit3 := dtos.SplitDTO{Name: "split3", Killed: false, Status: "ACTIVE", TrafficTypeName: "one", Sets: []string{"set5", "set1"}} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch call { case 1: @@ -820,7 +820,7 @@ func TestSplitSyncWithSetsInConfig(t *testing.T) { mockedSplit4 := dtos.SplitDTO{Name: "split4", Killed: false, Status: "ACTIVE", TrafficTypeName: "one", Sets: []string{"set2"}} splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&call, 1) switch call { case 1: diff --git a/tasks/segmentsync_test.go b/tasks/segmentsync_test.go index fbaa8494..447f0b67 100644 --- a/tasks/segmentsync_test.go +++ b/tasks/segmentsync_test.go @@ -69,7 +69,7 @@ func TestSegmentSyncTask(t *testing.T) { } segmentMockFetcher := fetcherMock.MockSegmentFetcher{ - FetchCall: func(name string, fetchOptions *service.SegmentFetchOptions) (*dtos.SegmentChangesDTO, error) { + FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("no cache shold be true") } diff --git a/tasks/splitsync_test.go b/tasks/splitsync_test.go index 16005805..c489751a 100644 --- a/tasks/splitsync_test.go +++ b/tasks/splitsync_test.go @@ -52,7 +52,7 @@ func TestSplitSyncTask(t *testing.T) { } splitMockFetcher := fetcherMock.MockSplitFetcher{ - FetchCall: func(fetchOptions *service.SplitFetchOptions) (*dtos.SplitChangesDTO, error) { + FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { if !fetchOptions.CacheControlHeaders { t.Error("noCache should be true.") } From ae95a252f52854e549412e87d003ba5af58a544a Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 30 Apr 2024 15:01:41 -0300 Subject: [PATCH 06/56] merged with latest in semver --- sdk/specs/specversion.go | 6 ------ service/api/auth.go | 9 ++------- service/api/http_fetchers.go | 9 ++------- service/api/spec/spec.go | 4 ---- service/api/specs/specversion.go | 14 +++++++++++++ service/api/specs/specversion_test.go | 20 +++++++++++++++++++ .../api}/specs/splitversionfilter.go | 10 +++++----- .../api}/specs/splitversionfilter_test.go | 0 8 files changed, 43 insertions(+), 29 deletions(-) delete mode 100644 sdk/specs/specversion.go delete mode 100644 service/api/spec/spec.go create mode 100644 service/api/specs/specversion.go create mode 100644 service/api/specs/specversion_test.go rename {sdk => service/api}/specs/splitversionfilter.go (58%) rename {sdk => service/api}/specs/splitversionfilter_test.go (100%) diff --git a/sdk/specs/specversion.go b/sdk/specs/specversion.go deleted file mode 100644 index 15aa429e..00000000 --- a/sdk/specs/specversion.go +++ /dev/null @@ -1,6 +0,0 @@ -package specs - -const ( - FLAG_V1_0 = "1.0" - FLAG_V1_1 = "1.1" -) diff --git a/service/api/auth.go b/service/api/auth.go index 419e6e1e..d3d72fb7 100644 --- a/service/api/auth.go +++ b/service/api/auth.go @@ -6,8 +6,7 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/spec" - "github.com/splitio/go-toolkit/v5/common" + "github.com/splitio/go-split-commons/v5/service/api/specs" "github.com/splitio/go-toolkit/v5/logging" ) @@ -20,13 +19,9 @@ type AuthAPIClient struct { // NewAuthAPIClient instantiates and return an AuthAPIClient func NewAuthAPIClient(apikey string, cfg conf.AdvancedConfig, logger logging.LoggerInterface, metadata dtos.Metadata) *AuthAPIClient { - var specV *string - if cfg.AuthSpecVersion == spec.FlagSpec { // only valid versions - specV = common.StringRef(spec.FlagSpec) - } return &AuthAPIClient{ client: NewHTTPClient(apikey, cfg, cfg.AuthServiceURL, logger, metadata), - fetchOptions: service.MakeAuthRequestParams(specV), + fetchOptions: service.MakeAuthRequestParams(specs.Match(cfg.AuthSpecVersion)), logger: logger, } } diff --git a/service/api/http_fetchers.go b/service/api/http_fetchers.go index 4927beb2..1929714c 100644 --- a/service/api/http_fetchers.go +++ b/service/api/http_fetchers.go @@ -8,8 +8,7 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/spec" - "github.com/splitio/go-toolkit/v5/common" + "github.com/splitio/go-split-commons/v5/service/api/specs" "github.com/splitio/go-toolkit/v5/logging" ) @@ -35,17 +34,13 @@ type HTTPSplitFetcher struct { // NewHTTPSplitFetcher instantiates and return an HTTPSplitFetcher func NewHTTPSplitFetcher(apikey string, cfg conf.AdvancedConfig, logger logging.LoggerInterface, metadata dtos.Metadata) service.SplitFetcher { - var specVersion *string - if cfg.FlagsSpecVersion == spec.FlagSpec { // only match valid versions - specVersion = common.StringRef(spec.FlagSpec) - } return &HTTPSplitFetcher{ httpFetcherBase: httpFetcherBase{ client: NewHTTPClient(apikey, cfg, cfg.SdkURL, logger, metadata), logger: logger, }, flagSetsFilter: strings.Join(cfg.FlagSetsFilter, ","), - specVersion: specVersion, + specVersion: specs.Match(cfg.FlagsSpecVersion), } } diff --git a/service/api/spec/spec.go b/service/api/spec/spec.go deleted file mode 100644 index 7a403b61..00000000 --- a/service/api/spec/spec.go +++ /dev/null @@ -1,4 +0,0 @@ -package spec - -// FlagSpec FeatureFlag Version specification -const FlagSpec = "1.1" diff --git a/service/api/specs/specversion.go b/service/api/specs/specversion.go new file mode 100644 index 00000000..95ba6c8c --- /dev/null +++ b/service/api/specs/specversion.go @@ -0,0 +1,14 @@ +package specs + +const ( + FLAG_V1_0 = "1.0" + FLAG_V1_1 = "1.1" +) + +// Match returns the spec version if it is valid, otherwise it returns nil +func Match(specVersion string) *string { + if specVersion == FLAG_V1_0 || specVersion == FLAG_V1_1 { + return &specVersion + } + return nil +} diff --git a/service/api/specs/specversion_test.go b/service/api/specs/specversion_test.go new file mode 100644 index 00000000..594fbbfe --- /dev/null +++ b/service/api/specs/specversion_test.go @@ -0,0 +1,20 @@ +package specs + +import "testing" + +func TestMatch(t *testing.T) { + specVersion := "1.0" + if Match(specVersion) == nil { + t.Error("Expected 1.0") + } + + specVersion = "1.1" + if Match(specVersion) == nil { + t.Error("Expected 1.1") + } + + specVersion = "1.2" + if Match(specVersion) != nil { + t.Error("Expected nil") + } +} diff --git a/sdk/specs/splitversionfilter.go b/service/api/specs/splitversionfilter.go similarity index 58% rename from sdk/specs/splitversionfilter.go rename to service/api/specs/splitversionfilter.go index 974a466e..984ed8b9 100644 --- a/sdk/specs/splitversionfilter.go +++ b/service/api/specs/splitversionfilter.go @@ -13,11 +13,11 @@ type mkey struct { func NewSplitVersionFilter() SplitVersionFilter { matchersToExclude := map[mkey]struct{}{ - mkey{FLAG_V1_0, matchers.MatcherEqualToSemver}: {}, - mkey{FLAG_V1_0, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, - mkey{FLAG_V1_0, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, - mkey{FLAG_V1_0, matchers.MatcherTypeBetweenSemver}: {}, - mkey{FLAG_V1_0, matchers.MatcherTypeInListSemver}: {}, + {FLAG_V1_0, matchers.MatcherEqualToSemver}: {}, + {FLAG_V1_0, matchers.MatcherTypeLessThanOrEqualToSemver}: {}, + {FLAG_V1_0, matchers.MatcherTypeGreaterThanOrEqualToSemver}: {}, + {FLAG_V1_0, matchers.MatcherTypeBetweenSemver}: {}, + {FLAG_V1_0, matchers.MatcherTypeInListSemver}: {}, } return SplitVersionFilter{excluded: matchersToExclude} diff --git a/sdk/specs/splitversionfilter_test.go b/service/api/specs/splitversionfilter_test.go similarity index 100% rename from sdk/specs/splitversionfilter_test.go rename to service/api/specs/splitversionfilter_test.go From 97a144ebf958d88eb2211c5944dcf028841aaf86 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 30 Apr 2024 17:37:24 -0300 Subject: [PATCH 07/56] Add label UnsupportedMatcherType --- engine/evaluator/impressionlabels/impression_labels.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/evaluator/impressionlabels/impression_labels.go b/engine/evaluator/impressionlabels/impression_labels.go index 029cd4be..44dbb1db 100644 --- a/engine/evaluator/impressionlabels/impression_labels.go +++ b/engine/evaluator/impressionlabels/impression_labels.go @@ -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 = "unsupported matcher type" From 64c3571fcbccc57c6435a00301da0deba7381978 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 30 Apr 2024 17:45:51 -0300 Subject: [PATCH 08/56] Update label --- engine/evaluator/impressionlabels/impression_labels.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/evaluator/impressionlabels/impression_labels.go b/engine/evaluator/impressionlabels/impression_labels.go index 44dbb1db..924eeeba 100644 --- a/engine/evaluator/impressionlabels/impression_labels.go +++ b/engine/evaluator/impressionlabels/impression_labels.go @@ -22,4 +22,4 @@ const Exception = "exception" const ClientNotReady = "not ready" // UnsupportedMatcherType label will be returned when a matcher is not supported -const UnsupportedMatcherType = "unsupported matcher type" +const UnsupportedMatcherType = "targeting rule type unsupported by sdk" From 28a77ca37e9ba8bd34d993a4f22b7371e2f7efe7 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 30 Apr 2024 18:33:50 -0300 Subject: [PATCH 09/56] added logic to process matchers in case it arrives an unsupported one --- service/api/http_fetchers_test.go | 9 +++-- service/commons_test.go | 9 +++-- synchronizer/worker/split/split.go | 23 +++++++++++- synchronizer/worker/split/split_test.go | 49 +++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 9 deletions(-) diff --git a/service/api/http_fetchers_test.go b/service/api/http_fetchers_test.go index c02411c7..f480144b 100644 --- a/service/api/http_fetchers_test.go +++ b/service/api/http_fetchers_test.go @@ -13,6 +13,7 @@ import ( "github.com/splitio/go-split-commons/v5/conf" "github.com/splitio/go-split-commons/v5/dtos" "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" ) @@ -36,7 +37,7 @@ func TestSpitChangesFetch(t *testing.T) { if r.URL.Query().Get("sets") != "" { t.Error("wrong sets") } - if r.URL.Query().Get("s") != "1.1" { + if r.URL.Query().Get("s") != specs.FLAG_V1_1 { t.Error("wrong spec") } if r.URL.RawQuery != "s=1.1&since=123456" { @@ -51,7 +52,7 @@ func TestSpitChangesFetch(t *testing.T) { conf.AdvancedConfig{ EventsURL: ts.URL, SdkURL: ts.URL, - FlagsSpecVersion: "1.1", + FlagsSpecVersion: specs.FLAG_V1_1, }, logger, dtos.Metadata{}, @@ -209,7 +210,7 @@ func TestSpitChangesFetchWithAll(t *testing.T) { EventsURL: ts.URL, SdkURL: ts.URL, FlagSetsFilter: []string{"one", "two"}, - FlagsSpecVersion: "1.1", + FlagsSpecVersion: specs.FLAG_V1_1, }, logger, dtos.Metadata{}, @@ -231,7 +232,7 @@ func TestSpitChangesFetchWithAll(t *testing.T) { if !queryParams.Has("sets") { t.Error("Expected to have sets") } - if queryParams.Get("s") != "1.1" { + if queryParams.Get("s") != specs.FLAG_V1_1 { t.Error("Expected to have spec") } asString := queryParams.Get("sets") diff --git a/service/commons_test.go b/service/commons_test.go index abe94d78..fa9e386d 100644 --- a/service/commons_test.go +++ b/service/commons_test.go @@ -4,11 +4,12 @@ import ( "net/http" "testing" + "github.com/splitio/go-split-commons/v5/service/api/specs" "github.com/splitio/go-toolkit/v5/common" ) func TestSplitFetchOptions(t *testing.T) { - fetchOptions := MakeFlagRequestParams().WithChangeNumber(123456).WithFlagSetsFilter("filter").WithTill(*common.Int64Ref(123)).WithSpecVersion(common.StringRef("1.1")) + fetchOptions := MakeFlagRequestParams().WithChangeNumber(123456).WithFlagSetsFilter("filter").WithTill(*common.Int64Ref(123)).WithSpecVersion(common.StringRef(specs.FLAG_V1_1)) req, _ := http.NewRequest("GET", "test", nil) fetchOptions.Apply(req) @@ -18,7 +19,7 @@ func TestSplitFetchOptions(t *testing.T) { if req.URL.Query().Get(since) != "123456" { t.Error("Change number not set") } - if req.URL.Query().Get(spec) != "1.1" { + if req.URL.Query().Get(spec) != specs.FLAG_V1_1 { t.Error("Spec version not set") } if req.URL.Query().Get(sets) != "filter" { @@ -54,14 +55,14 @@ func TestSegmentRequestParams(t *testing.T) { } func TestAuthRequestParams(t *testing.T) { - fetchOptions := MakeAuthRequestParams(common.StringRef("1.1")) + fetchOptions := MakeAuthRequestParams(common.StringRef(specs.FLAG_V1_1)) req, _ := http.NewRequest("GET", "test", nil) fetchOptions.Apply(req) if req.Header.Get(cacheControl) != cacheControlNoCache { t.Error("Cache control header not set") } - if req.URL.Query().Get(spec) != "1.1" { + if req.URL.Query().Get(spec) != specs.FLAG_V1_1 { t.Error("Spec version not set") } if req.URL.String() != "test?s=1.1" { diff --git a/synchronizer/worker/split/split.go b/synchronizer/worker/split/split.go index 6b58a8c2..53ecd06b 100644 --- a/synchronizer/worker/split/split.go +++ b/synchronizer/worker/split/split.go @@ -5,6 +5,10 @@ import ( "time" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/evaluator" + "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/grammar/matchers" "github.com/splitio/go-split-commons/v5/flagsets" "github.com/splitio/go-split-commons/v5/healthcheck/application" "github.com/splitio/go-split-commons/v5/service" @@ -12,6 +16,7 @@ import ( "github.com/splitio/go-split-commons/v5/telemetry" "github.com/splitio/go-toolkit/v5/backoff" "github.com/splitio/go-toolkit/v5/common" + "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" ) @@ -196,12 +201,28 @@ func appendSegmentNames(dst []string, splits *dtos.SplitChangesDTO) []string { return dst } +func (s *UpdaterImpl) processMatchers(split dtos.SplitDTO) dtos.SplitDTO { + for idx := range split.Conditions { + for jdx := range split.Conditions[idx].MatcherGroup.Matchers { + _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, s.logger) + if err != nil { + split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist + split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys + split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil + split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType + split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}} + } + } + } + return split +} + func (s *UpdaterImpl) processFeatureFlagChanges(featureFlags *dtos.SplitChangesDTO) ([]dtos.SplitDTO, []dtos.SplitDTO) { toRemove := make([]dtos.SplitDTO, 0, len(featureFlags.Splits)) toAdd := make([]dtos.SplitDTO, 0, len(featureFlags.Splits)) for idx := range featureFlags.Splits { if featureFlags.Splits[idx].Status == Active && s.flagSetsFilter.Instersect(featureFlags.Splits[idx].Sets) { - toAdd = append(toAdd, featureFlags.Splits[idx]) + toAdd = append(toAdd, s.processMatchers(featureFlags.Splits[idx])) } else { toRemove = append(toRemove, featureFlags.Splits[idx]) } diff --git a/synchronizer/worker/split/split_test.go b/synchronizer/worker/split/split_test.go index e2a42eb6..febf4fbc 100644 --- a/synchronizer/worker/split/split_test.go +++ b/synchronizer/worker/split/split_test.go @@ -7,6 +7,8 @@ import ( "time" "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/flagsets" hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" "github.com/splitio/go-split-commons/v5/service" @@ -875,3 +877,50 @@ func TestSplitSyncWithSetsInConfig(t *testing.T) { t.Error("split4 should be present") } } + +func TestProcessMatchers(t *testing.T) { + splitUpdater := NewSplitUpdater(mocks.MockSplitStorage{}, fetcherMock.MockSplitFetcher{}, logging.NewLogger(nil), mocks.MockTelemetryStorage{}, hcMock.MockApplicationMonitor{}, flagsets.NewFlagSetFilter(nil)) + split := dtos.SplitDTO{ + Conditions: []dtos.ConditionDTO{ + { + ConditionType: "NEW_MATCHER", + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: "NEW_MATCHER", KeySelector: nil}, + }, + }, + }, + }, + } + splitUpdater.processMatchers(split) + + if split.Conditions[0].ConditionType != grammar.ConditionTypeWhitelist { + t.Error("ConditionType should be WHITELIST") + } + if split.Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { + t.Error("MatcherType should be ALL_KEYS") + } + + split = dtos.SplitDTO{ + Conditions: []dtos.ConditionDTO{ + { + ConditionType: grammar.ConditionTypeRollout, + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: matchers.MatcherTypeAllKeys, KeySelector: nil}, + }, + }, + }, + }, + } + splitUpdater.processMatchers(split) + + if split.Conditions[0].ConditionType != grammar.ConditionTypeRollout { + t.Error("ConditionType should be ROLLOUT") + } + if split.Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { + t.Error("MatcherType should be ALL_KEYS") + } +} From 7547df56e3c5880dcb864c2a05d352adbd7f2ff8 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 09:47:21 -0300 Subject: [PATCH 10/56] moved process to another package to be reused --- engine/validator/matchers.go | 27 +++++++++++ engine/validator/matchers_test.go | 55 ++++++++++++++++++++++ synchronizer/worker/split/split.go | 25 ++-------- synchronizer/worker/split/split_test.go | 62 +++++++++++++------------ 4 files changed, 118 insertions(+), 51 deletions(-) create mode 100644 engine/validator/matchers.go create mode 100644 engine/validator/matchers_test.go diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go new file mode 100644 index 00000000..aace5178 --- /dev/null +++ b/engine/validator/matchers.go @@ -0,0 +1,27 @@ +package validator + +import ( + "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/evaluator" + "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/grammar/matchers" + "github.com/splitio/go-toolkit/v5/injection" + "github.com/splitio/go-toolkit/v5/logging" +) + +// ProcessMatchers processes the matchers of a split and validates them +func ProcessMatchers(split dtos.SplitDTO, logger logging.LoggerInterface) { + for idx := range split.Conditions { + for jdx := range split.Conditions[idx].MatcherGroup.Matchers { + _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, logger) + if err != nil { + split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist + split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys + split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil + split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType + split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}} + } + } + } +} diff --git a/engine/validator/matchers_test.go b/engine/validator/matchers_test.go new file mode 100644 index 00000000..1bb1b9a9 --- /dev/null +++ b/engine/validator/matchers_test.go @@ -0,0 +1,55 @@ +package validator + +import ( + "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/grammar/matchers" + "github.com/splitio/go-toolkit/v5/logging" +) + +func TestProcessMatchers(t *testing.T) { + split := dtos.SplitDTO{ + Conditions: []dtos.ConditionDTO{ + { + ConditionType: "NEW_MATCHER", + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: "NEW_MATCHER", KeySelector: nil}, + }, + }, + }, + }, + } + ProcessMatchers(split, logging.NewLogger(nil)) + if split.Conditions[0].ConditionType != grammar.ConditionTypeWhitelist { + t.Error("ConditionType should be WHITELIST") + } + if split.Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { + t.Error("MatcherType should be ALL_KEYS") + } + + split = dtos.SplitDTO{ + Conditions: []dtos.ConditionDTO{ + { + ConditionType: grammar.ConditionTypeRollout, + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: matchers.MatcherTypeAllKeys, KeySelector: nil}, + }, + }, + }, + }, + } + ProcessMatchers(split, logging.NewLogger(nil)) + + if split.Conditions[0].ConditionType != grammar.ConditionTypeRollout { + t.Error("ConditionType should be ROLLOUT") + } + if split.Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { + t.Error("MatcherType should be ALL_KEYS") + } +} diff --git a/synchronizer/worker/split/split.go b/synchronizer/worker/split/split.go index 53ecd06b..a876064f 100644 --- a/synchronizer/worker/split/split.go +++ b/synchronizer/worker/split/split.go @@ -5,10 +5,7 @@ import ( "time" "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/evaluator" - "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/grammar/matchers" + "github.com/splitio/go-split-commons/v5/engine/validator" "github.com/splitio/go-split-commons/v5/flagsets" "github.com/splitio/go-split-commons/v5/healthcheck/application" "github.com/splitio/go-split-commons/v5/service" @@ -16,7 +13,6 @@ import ( "github.com/splitio/go-split-commons/v5/telemetry" "github.com/splitio/go-toolkit/v5/backoff" "github.com/splitio/go-toolkit/v5/common" - "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" ) @@ -201,28 +197,13 @@ func appendSegmentNames(dst []string, splits *dtos.SplitChangesDTO) []string { return dst } -func (s *UpdaterImpl) processMatchers(split dtos.SplitDTO) dtos.SplitDTO { - for idx := range split.Conditions { - for jdx := range split.Conditions[idx].MatcherGroup.Matchers { - _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, s.logger) - if err != nil { - split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist - split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys - split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil - split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType - split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}} - } - } - } - return split -} - func (s *UpdaterImpl) processFeatureFlagChanges(featureFlags *dtos.SplitChangesDTO) ([]dtos.SplitDTO, []dtos.SplitDTO) { toRemove := make([]dtos.SplitDTO, 0, len(featureFlags.Splits)) toAdd := make([]dtos.SplitDTO, 0, len(featureFlags.Splits)) for idx := range featureFlags.Splits { if featureFlags.Splits[idx].Status == Active && s.flagSetsFilter.Instersect(featureFlags.Splits[idx].Sets) { - toAdd = append(toAdd, s.processMatchers(featureFlags.Splits[idx])) + validator.ProcessMatchers(featureFlags.Splits[idx], s.logger) + toAdd = append(toAdd, featureFlags.Splits[idx]) } else { toRemove = append(toRemove, featureFlags.Splits[idx]) } diff --git a/synchronizer/worker/split/split_test.go b/synchronizer/worker/split/split_test.go index febf4fbc..08e136ce 100644 --- a/synchronizer/worker/split/split_test.go +++ b/synchronizer/worker/split/split_test.go @@ -880,47 +880,51 @@ func TestSplitSyncWithSetsInConfig(t *testing.T) { func TestProcessMatchers(t *testing.T) { splitUpdater := NewSplitUpdater(mocks.MockSplitStorage{}, fetcherMock.MockSplitFetcher{}, logging.NewLogger(nil), mocks.MockTelemetryStorage{}, hcMock.MockApplicationMonitor{}, flagsets.NewFlagSetFilter(nil)) - split := dtos.SplitDTO{ - Conditions: []dtos.ConditionDTO{ - { - ConditionType: "NEW_MATCHER", - Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, - MatcherGroup: dtos.MatcherGroupDTO{ - Matchers: []dtos.MatcherDTO{ - {MatcherType: "NEW_MATCHER", KeySelector: nil}, + splitChange := &dtos.SplitChangesDTO{Till: 1, Since: 1, Splits: []dtos.SplitDTO{ + { + Name: "split1", + Status: Active, + Conditions: []dtos.ConditionDTO{ + { + ConditionType: "NEW_MATCHER", + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: "NEW_MATCHER", KeySelector: nil}, + }, }, }, }, }, - } - splitUpdater.processMatchers(split) - - if split.Conditions[0].ConditionType != grammar.ConditionTypeWhitelist { - t.Error("ConditionType should be WHITELIST") - } - if split.Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { - t.Error("MatcherType should be ALL_KEYS") - } - - split = dtos.SplitDTO{ - Conditions: []dtos.ConditionDTO{ - { - ConditionType: grammar.ConditionTypeRollout, - Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, - MatcherGroup: dtos.MatcherGroupDTO{ - Matchers: []dtos.MatcherDTO{ - {MatcherType: matchers.MatcherTypeAllKeys, KeySelector: nil}, + { + Name: "split2", + Status: Active, + Conditions: []dtos.ConditionDTO{ + { + ConditionType: grammar.ConditionTypeRollout, + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: matchers.MatcherTypeAllKeys, KeySelector: nil}, + }, }, }, }, }, + }} + toAdd, _ := splitUpdater.processFeatureFlagChanges(splitChange) + + if toAdd[0].Conditions[0].ConditionType != grammar.ConditionTypeWhitelist { + t.Error("ConditionType should be WHITELIST") + } + if toAdd[0].Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { + t.Error("MatcherType should be ALL_KEYS") } - splitUpdater.processMatchers(split) - if split.Conditions[0].ConditionType != grammar.ConditionTypeRollout { + if toAdd[1].Conditions[0].ConditionType != grammar.ConditionTypeRollout { t.Error("ConditionType should be ROLLOUT") } - if split.Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { + if toAdd[1].Conditions[0].MatcherGroup.Matchers[0].MatcherType != matchers.MatcherTypeAllKeys { t.Error("MatcherType should be ALL_KEYS") } } From 47f94ffad9485e72f0a9c147981e228ea8dc6c9d Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 11:43:24 -0300 Subject: [PATCH 11/56] made SplitDTO as pointer --- engine/validator/matchers.go | 2 +- engine/validator/matchers_test.go | 4 ++-- synchronizer/worker/split/split.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index aace5178..39bb3252 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -11,7 +11,7 @@ import ( ) // ProcessMatchers processes the matchers of a split and validates them -func ProcessMatchers(split dtos.SplitDTO, logger logging.LoggerInterface) { +func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) { for idx := range split.Conditions { for jdx := range split.Conditions[idx].MatcherGroup.Matchers { _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, logger) diff --git a/engine/validator/matchers_test.go b/engine/validator/matchers_test.go index 1bb1b9a9..709c0ef7 100644 --- a/engine/validator/matchers_test.go +++ b/engine/validator/matchers_test.go @@ -10,7 +10,7 @@ import ( ) func TestProcessMatchers(t *testing.T) { - split := dtos.SplitDTO{ + split := &dtos.SplitDTO{ Conditions: []dtos.ConditionDTO{ { ConditionType: "NEW_MATCHER", @@ -31,7 +31,7 @@ func TestProcessMatchers(t *testing.T) { t.Error("MatcherType should be ALL_KEYS") } - split = dtos.SplitDTO{ + split = &dtos.SplitDTO{ Conditions: []dtos.ConditionDTO{ { ConditionType: grammar.ConditionTypeRollout, diff --git a/synchronizer/worker/split/split.go b/synchronizer/worker/split/split.go index a876064f..b21aead3 100644 --- a/synchronizer/worker/split/split.go +++ b/synchronizer/worker/split/split.go @@ -202,7 +202,7 @@ func (s *UpdaterImpl) processFeatureFlagChanges(featureFlags *dtos.SplitChangesD toAdd := make([]dtos.SplitDTO, 0, len(featureFlags.Splits)) for idx := range featureFlags.Splits { if featureFlags.Splits[idx].Status == Active && s.flagSetsFilter.Instersect(featureFlags.Splits[idx].Sets) { - validator.ProcessMatchers(featureFlags.Splits[idx], s.logger) + validator.ProcessMatchers(&featureFlags.Splits[idx], s.logger) toAdd = append(toAdd, featureFlags.Splits[idx]) } else { toRemove = append(toRemove, featureFlags.Splits[idx]) From cd637e77eee868107ffd4ced05ddbac610caf2b5 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 12:15:56 -0300 Subject: [PATCH 12/56] made cacheControl optional --- service/commons.go | 27 ++++++++++++++++++++++++--- service/commons_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/service/commons.go b/service/commons.go index b8e91b90..9e41a867 100644 --- a/service/commons.go +++ b/service/commons.go @@ -47,6 +47,11 @@ func MakeFlagRequestParams() *FlagRequestParams { } } +func (s *FlagRequestParams) WithCacheControl(cacheControl bool) *FlagRequestParams { + s.CacheControlHeaders = cacheControl + return s +} + func (s *FlagRequestParams) WithChangeNumber(changeNumber int64) *FlagRequestParams { s.ChangeNumber = changeNumber return s @@ -68,7 +73,9 @@ func (s *FlagRequestParams) WithTill(till int64) *FlagRequestParams { } func (s *FlagRequestParams) Apply(request *http.Request) error { - request.Header.Set(cacheControl, cacheControlNoCache) + if s.CacheControlHeaders { + request.Header.Set(cacheControl, cacheControlNoCache) + } queryParameters := []queryParamater{} if s.SpecVersion != nil { @@ -100,6 +107,11 @@ func MakeSegmentRequestParams() *SegmentRequestParams { } } +func (s *SegmentRequestParams) WithCacheControl(cacheControl bool) *SegmentRequestParams { + s.CacheControlHeaders = cacheControl + return s +} + func (s *SegmentRequestParams) WithChangeNumber(changeNumber int64) *SegmentRequestParams { s.ChangeNumber = changeNumber return s @@ -111,7 +123,9 @@ func (s *SegmentRequestParams) WithTill(till int64) *SegmentRequestParams { } func (s *SegmentRequestParams) Apply(request *http.Request) error { - request.Header.Set(cacheControl, cacheControlNoCache) + if s.CacheControlHeaders { + request.Header.Set(cacheControl, cacheControlNoCache) + } queryParameters := []queryParamater{} queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.ChangeNumber, 10)}) @@ -137,8 +151,15 @@ func MakeAuthRequestParams(specVersion *string) *AuthRequestParams { } } +func (s *AuthRequestParams) WithCacheControl(cacheControl bool) *AuthRequestParams { + s.CacheControlHeaders = cacheControl + return s +} + func (s *AuthRequestParams) Apply(request *http.Request) error { - request.Header.Set(cacheControl, cacheControlNoCache) + if s.CacheControlHeaders { + request.Header.Set(cacheControl, cacheControlNoCache) + } queryParams := request.URL.Query() if s.SpecVersion != nil { diff --git a/service/commons_test.go b/service/commons_test.go index fa9e386d..1991d5bb 100644 --- a/service/commons_test.go +++ b/service/commons_test.go @@ -69,3 +69,29 @@ func TestAuthRequestParams(t *testing.T) { t.Error("Query params not set correctly, expected: test?s=v1, got:", req.URL.String()) } } + +func TestOverrideCacheControl(t *testing.T) { + flagParams := MakeFlagRequestParams().WithCacheControl(false) + req, _ := http.NewRequest("GET", "test", nil) + flagParams.Apply(req) + + if req.Header.Get(cacheControl) != "" { + t.Error("Cache control header should not be set") + } + + segmentParams := MakeSegmentRequestParams().WithCacheControl(false) + req, _ = http.NewRequest("GET", "test", nil) + segmentParams.Apply(req) + + if req.Header.Get(cacheControl) != "" { + t.Error("Cache control header should not be set") + } + + authParams := MakeAuthRequestParams(nil).WithCacheControl(false) + req, _ = http.NewRequest("GET", "test", nil) + authParams.Apply(req) + + if req.Header.Get(cacheControl) != "" { + t.Error("Cache control header should not be set") + } +} From 03946208930e11f91954fe3ada234555eff3188d Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 12:25:38 -0300 Subject: [PATCH 13/56] moved logging debug for GET --- service/api/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/api/client.go b/service/api/client.go index a3cb2d6b..979fa569 100644 --- a/service/api/client.go +++ b/service/api/client.go @@ -58,7 +58,6 @@ func NewHTTPClient( // Get method is a get call to an url func (c *HTTPClient) Get(endpoint string, fetchOptions service.RequestParams) ([]byte, error) { serviceURL := c.url + endpoint - c.logger.Debug("[GET] ", serviceURL) req, _ := http.NewRequest("GET", serviceURL, nil) authorization := c.apikey c.logger.Debug("Authorization [ApiKey]: ", logging.ObfuscateAPIKey(authorization)) @@ -78,6 +77,7 @@ func (c *HTTPClient) Get(endpoint string, fetchOptions service.RequestParams) ([ fetchOptions.Apply(req) } + c.logger.Debug("[GET] ", req.URL.RawQuery) resp, err := c.httpClient.Do(req) if err != nil { c.logger.Error("Error requesting data to API: ", req.URL.String(), err.Error()) From 221c57a08ca114f6ee572bd03b37c3305a3bbcf8 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 12:33:43 -0300 Subject: [PATCH 14/56] logging url --- service/api/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/api/client.go b/service/api/client.go index 979fa569..11093738 100644 --- a/service/api/client.go +++ b/service/api/client.go @@ -77,7 +77,7 @@ func (c *HTTPClient) Get(endpoint string, fetchOptions service.RequestParams) ([ fetchOptions.Apply(req) } - c.logger.Debug("[GET] ", req.URL.RawQuery) + c.logger.Debug("[GET] ", req.URL.String()) resp, err := c.httpClient.Do(req) if err != nil { c.logger.Error("Error requesting data to API: ", req.URL.String(), err.Error()) From 97f050270ae152e2d64352e0f0551eb319b53055 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 14:40:52 -0300 Subject: [PATCH 15/56] made private props in RequestParams --- CHANGES | 3 + service/commons.go | 94 +++++++++++---------- service/local/segmentFetcher.go | 2 +- service/local/splitFetcher.go | 6 +- synchronizer/local_test.go | 6 +- synchronizer/synchronizer_test.go | 58 +++++-------- synchronizer/worker/segment/segment_test.go | 42 ++++----- synchronizer/worker/split/split_test.go | 61 ++++++------- tasks/segmentsync_test.go | 3 - tasks/splitsync_test.go | 13 +-- 10 files changed, 134 insertions(+), 154 deletions(-) diff --git a/CHANGES b/CHANGES index d6fa8c17..09bbeff8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +6.X.X ( XX, 2024) +- Changed FetchOptions and Fetch API. + 5.2.2 (Apr 26, 2024) - Added split version filter to be used on semver matchers logic. diff --git a/service/commons.go b/service/commons.go index 9e41a867..2b42912e 100644 --- a/service/commons.go +++ b/service/commons.go @@ -27,66 +27,70 @@ type RequestParams interface { Apply(request *http.Request) error } -type BaseRequestParams struct { - CacheControlHeaders bool +type baseRequestParams struct { + cacheControlHeaders bool } type FlagRequestParams struct { - BaseRequestParams - ChangeNumber int64 - FlagSetsFilter string - SpecVersion *string - Till *int64 + baseRequestParams + changeNumber int64 + flagSetsFilter string + specVersion *string + till *int64 } func MakeFlagRequestParams() *FlagRequestParams { return &FlagRequestParams{ - BaseRequestParams: BaseRequestParams{ - CacheControlHeaders: true, + baseRequestParams: baseRequestParams{ + cacheControlHeaders: true, }, } } func (s *FlagRequestParams) WithCacheControl(cacheControl bool) *FlagRequestParams { - s.CacheControlHeaders = cacheControl + s.cacheControlHeaders = cacheControl return s } func (s *FlagRequestParams) WithChangeNumber(changeNumber int64) *FlagRequestParams { - s.ChangeNumber = changeNumber + s.changeNumber = changeNumber return s } func (s *FlagRequestParams) WithFlagSetsFilter(flagSetsFilter string) *FlagRequestParams { - s.FlagSetsFilter = flagSetsFilter + s.flagSetsFilter = flagSetsFilter return s } func (s *FlagRequestParams) WithSpecVersion(specVersion *string) *FlagRequestParams { - s.SpecVersion = specVersion + s.specVersion = specVersion return s } func (s *FlagRequestParams) WithTill(till int64) *FlagRequestParams { - s.Till = common.Int64Ref(till) + s.till = common.Int64Ref(till) return s } +func (s *FlagRequestParams) ChangeNumber() int64 { + return s.changeNumber +} + func (s *FlagRequestParams) Apply(request *http.Request) error { - if s.CacheControlHeaders { + if s.cacheControlHeaders { request.Header.Set(cacheControl, cacheControlNoCache) } queryParameters := []queryParamater{} - if s.SpecVersion != nil { - queryParameters = append(queryParameters, queryParamater{key: spec, value: common.StringFromRef(s.SpecVersion)}) + if s.specVersion != nil { + queryParameters = append(queryParameters, queryParamater{key: spec, value: common.StringFromRef(s.specVersion)}) } - queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.ChangeNumber, 10)}) - if len(s.FlagSetsFilter) > 0 { - queryParameters = append(queryParameters, queryParamater{key: sets, value: s.FlagSetsFilter}) + queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.changeNumber, 10)}) + if len(s.flagSetsFilter) > 0 { + queryParameters = append(queryParameters, queryParamater{key: sets, value: s.flagSetsFilter}) } - if s.Till != nil { - queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.Till, 10)}) + if s.till != nil { + queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.till, 10)}) } request.URL.RawQuery = encode(queryParameters) @@ -94,43 +98,47 @@ func (s *FlagRequestParams) Apply(request *http.Request) error { } type SegmentRequestParams struct { - BaseRequestParams - ChangeNumber int64 - Till *int64 + baseRequestParams + changeNumber int64 + till *int64 } func MakeSegmentRequestParams() *SegmentRequestParams { return &SegmentRequestParams{ - BaseRequestParams: BaseRequestParams{ - CacheControlHeaders: true, + baseRequestParams: baseRequestParams{ + cacheControlHeaders: true, }, } } func (s *SegmentRequestParams) WithCacheControl(cacheControl bool) *SegmentRequestParams { - s.CacheControlHeaders = cacheControl + s.cacheControlHeaders = cacheControl return s } func (s *SegmentRequestParams) WithChangeNumber(changeNumber int64) *SegmentRequestParams { - s.ChangeNumber = changeNumber + s.changeNumber = changeNumber return s } func (s *SegmentRequestParams) WithTill(till int64) *SegmentRequestParams { - s.Till = common.Int64Ref(till) + s.till = common.Int64Ref(till) return s } +func (s *SegmentRequestParams) ChangeNumber() int64 { + return s.changeNumber +} + func (s *SegmentRequestParams) Apply(request *http.Request) error { - if s.CacheControlHeaders { + if s.cacheControlHeaders { request.Header.Set(cacheControl, cacheControlNoCache) } queryParameters := []queryParamater{} - queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.ChangeNumber, 10)}) - if s.Till != nil { - queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.Till, 10)}) + queryParameters = append(queryParameters, queryParamater{key: since, value: strconv.FormatInt(s.changeNumber, 10)}) + if s.till != nil { + queryParameters = append(queryParameters, queryParamater{key: till, value: strconv.FormatInt(*s.till, 10)}) } request.URL.RawQuery = encode(queryParameters) @@ -138,32 +146,32 @@ func (s *SegmentRequestParams) Apply(request *http.Request) error { } type AuthRequestParams struct { - BaseRequestParams - SpecVersion *string + baseRequestParams + specVersion *string } func MakeAuthRequestParams(specVersion *string) *AuthRequestParams { return &AuthRequestParams{ - BaseRequestParams: BaseRequestParams{ - CacheControlHeaders: true, + baseRequestParams: baseRequestParams{ + cacheControlHeaders: true, }, - SpecVersion: specVersion, + specVersion: specVersion, } } func (s *AuthRequestParams) WithCacheControl(cacheControl bool) *AuthRequestParams { - s.CacheControlHeaders = cacheControl + s.cacheControlHeaders = cacheControl return s } func (s *AuthRequestParams) Apply(request *http.Request) error { - if s.CacheControlHeaders { + if s.cacheControlHeaders { request.Header.Set(cacheControl, cacheControlNoCache) } queryParams := request.URL.Query() - if s.SpecVersion != nil { - queryParams.Add(spec, common.StringFromRef(s.SpecVersion)) + if s.specVersion != nil { + queryParams.Add(spec, common.StringFromRef(s.specVersion)) } request.URL.RawQuery = queryParams.Encode() diff --git a/service/local/segmentFetcher.go b/service/local/segmentFetcher.go index d64a6446..0c0caf15 100644 --- a/service/local/segmentFetcher.go +++ b/service/local/segmentFetcher.go @@ -84,5 +84,5 @@ func (s *FileSegmentFetcher) Fetch(segmentName string, fetchOptions *service.Seg s.logger.Error(fmt.Sprintf("could not find the segmentChange file for %s. error: %v", segmentName, err)) return nil, err } - return s.processSegmentJson(fileContents, segmentName, fetchOptions.ChangeNumber) + return s.processSegmentJson(fileContents, segmentName, fetchOptions.ChangeNumber()) } diff --git a/service/local/splitFetcher.go b/service/local/splitFetcher.go index 82f267b1..d5b12d27 100644 --- a/service/local/splitFetcher.go +++ b/service/local/splitFetcher.go @@ -270,13 +270,13 @@ func (s *FileSplitFetcher) Fetch(fetchOptions *service.FlagRequestParams) (*dtos case SplitFileFormatYAML: splits = s.parseSplitsYAML(data) case SplitFileFormatJSON: - return s.processSplitJson(data, fetchOptions.ChangeNumber) + return s.processSplitJson(data, fetchOptions.ChangeNumber()) default: return nil, fmt.Errorf("unsupported file format") } - till := fetchOptions.ChangeNumber + till := fetchOptions.ChangeNumber() // Get the SHA1 sum of the raw contents of the file, and compare it to the last one seen // if it's equal, nothing has changed, return since == till @@ -291,7 +291,7 @@ func (s *FileSplitFetcher) Fetch(fetchOptions *service.FlagRequestParams) (*dtos s.lastHash = currSum return &dtos.SplitChangesDTO{ Splits: splits, - Since: fetchOptions.ChangeNumber, + Since: fetchOptions.ChangeNumber(), Till: till, }, nil } diff --git a/synchronizer/local_test.go b/synchronizer/local_test.go index 99bb0d2c..6d6da7f6 100644 --- a/synchronizer/local_test.go +++ b/synchronizer/local_test.go @@ -22,7 +22,7 @@ func TestLocalSyncAllError(t *testing.T) { SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return nil, errors.New("Some") @@ -56,7 +56,7 @@ func TestLocalSyncAllOk(t *testing.T) { SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -105,7 +105,7 @@ func TestLocalPeriodicFetching(t *testing.T) { SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index 0cab1d7e..892fd832 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -2,6 +2,7 @@ package synchronizer import ( "errors" + "net/http" "sync/atomic" "testing" "time" @@ -27,6 +28,17 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) +func validReqParams(t *testing.T, fetchOptions service.RequestParams) { + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + if req.Header.Get("Cache-Control") != "no-cache" { + t.Error("Wrong header") + } + if req.URL.Query().Get("since") != "-1" { + t.Error("Wrong since") + } +} + func TestSyncAllErrorSplits(t *testing.T) { var splitFetchCalled int64 var notifyEventCalled int64 @@ -34,13 +46,8 @@ func TestSyncAllErrorSplits(t *testing.T) { splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("no cache should be true") - } atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { - t.Error("Wrong changenumber passed") - } + validReqParams(t, fetchOptions) return nil, errors.New("Some") }, }, @@ -94,13 +101,8 @@ func TestSyncAllErrorInSegments(t *testing.T) { splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { - t.Error("Wrong changenumber passed") - } + validReqParams(t, fetchOptions) return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1, mockedSplit2}, Since: 3, @@ -110,10 +112,8 @@ func TestSyncAllErrorInSegments(t *testing.T) { }, SegmentFetcher: httpMocks.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&segmentFetchCalled, 1) + validReqParams(t, fetchOptions) if name != "segment1" && name != "segment2" { t.Error("Wrong name") } @@ -186,13 +186,8 @@ func TestSyncAllOk(t *testing.T) { splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { - t.Error("Wrong changenumber passed") - } + validReqParams(t, fetchOptions) return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1, mockedSplit2}, Since: 3, @@ -202,13 +197,11 @@ func TestSyncAllOk(t *testing.T) { }, SegmentFetcher: httpMocks.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&segmentFetchCalled, 1) if name != "segment1" && name != "segment2" { t.Error("Wrong name") } + validReqParams(t, fetchOptions) return &dtos.SegmentChangesDTO{ Name: name, Added: []string{"some"}, @@ -296,13 +289,8 @@ func TestPeriodicFetching(t *testing.T) { splitAPI := api.SplitAPI{ SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != -1 { - t.Error("Wrong changenumber passed") - } + validReqParams(t, fetchOptions) return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1, mockedSplit2}, Since: 3, @@ -312,13 +300,11 @@ func TestPeriodicFetching(t *testing.T) { }, SegmentFetcher: httpMocks.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&segmentFetchCalled, 1) if name != "segment1" && name != "segment2" { t.Error("Wrong name") } + validReqParams(t, fetchOptions) return &dtos.SegmentChangesDTO{ Name: name, Added: []string{"some"}, @@ -709,7 +695,7 @@ func TestSplitUpdateWorkerGetCNFromStorageError(t *testing.T) { SplitFetcher: httpMocks.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&splitFetchCalled, 1) - if fetchOptions.ChangeNumber != 0 { + if fetchOptions.ChangeNumber() != 0 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -950,13 +936,11 @@ func TestSplitUpdateWithReferencedSegments(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) splitAPI := api.SplitAPI{SegmentFetcher: httpMocks.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } atomic.AddInt64(&segmentFetchCalled, 1) if name != "segment1" { t.Error("Wrong name") } + validReqParams(t, fetchOptions) return &dtos.SegmentChangesDTO{ Name: name, Added: []string{"some"}, diff --git a/synchronizer/worker/segment/segment_test.go b/synchronizer/worker/segment/segment_test.go index d3deaadf..035fa59b 100644 --- a/synchronizer/worker/segment/segment_test.go +++ b/synchronizer/worker/segment/segment_test.go @@ -2,6 +2,7 @@ package segment import ( "fmt" + "net/http" "sync" "sync/atomic" "testing" @@ -23,6 +24,17 @@ import ( "github.com/splitio/go-toolkit/v5/testhelpers" ) +func validReqParams(t *testing.T, fetchOptions service.RequestParams, till string) { + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + if req.Header.Get("Cache-Control") != "no-cache" { + t.Error("Wrong header") + } + if req.URL.Query().Get("till") != till { + t.Error("Wrong till") + } +} + func TestSegmentsSynchronizerError(t *testing.T) { var notifyEventCalled int64 splitMockStorage := mocks.MockSplitStorage{ @@ -46,9 +58,6 @@ func TestSegmentsSynchronizerError(t *testing.T) { segmentMockFetcher := fetcherMock.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("should have requested no cache") - } if name != "segment1" && name != "segment2" { t.Error("Wrong name") } @@ -150,9 +159,6 @@ func TestSegmentSynchronizer(t *testing.T) { segmentMockFetcher := fetcherMock.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("should have requested no cache") - } if name != "segment1" && name != "segment2" { t.Error("Wrong name") } @@ -493,19 +499,13 @@ func TestSegmentCDNBypass(t *testing.T) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 1, Till: 2}, nil case called >= 2 && called <= 11: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil case called == 12: - if fetchOptions.Till == nil || *fetchOptions.Till != 2 { - t.Error("Till flag should be set with value 2") - } + validReqParams(t, fetchOptions, "2") return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 3, Till: 3}, nil } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 1, Till: 2}, nil @@ -572,19 +572,13 @@ func TestSegmentCDNBypassLimit(t *testing.T) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 1, Till: 2}, nil case called > 1 && called <= 11: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil case called >= 12: - if fetchOptions.Till == nil || *fetchOptions.Till != 2 { - t.Error("Till flag should be set with value 2") - } + validReqParams(t, fetchOptions, "2") return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil } return &dtos.SegmentChangesDTO{Name: name, Added: addedS1, Removed: []string{}, Since: 2, Till: 2}, nil diff --git a/synchronizer/worker/split/split_test.go b/synchronizer/worker/split/split_test.go index 08e136ce..f9afa415 100644 --- a/synchronizer/worker/split/split_test.go +++ b/synchronizer/worker/split/split_test.go @@ -2,6 +2,7 @@ package split import ( "errors" + "net/http" "sync/atomic" "testing" "time" @@ -21,6 +22,17 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) +func validReqParams(t *testing.T, fetchOptions service.RequestParams, till string) { + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + if req.Header.Get("Cache-Control") != "no-cache" { + t.Error("Wrong header") + } + if req.URL.Query().Get("till") != till { + t.Error("Wrong till") + } +} + func TestSplitSynchronizerError(t *testing.T) { var notifyEventCalled int64 @@ -30,10 +42,7 @@ func TestSplitSynchronizerError(t *testing.T) { splitMockFetcher := fetcherMock.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return nil, &dtos.HTTPError{Code: 500, Message: "some"} @@ -79,10 +88,7 @@ func TestSplitSynchronizerErrorScRequestURITooLong(t *testing.T) { splitMockFetcher := fetcherMock.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { atomic.AddInt64(&fetchCall, 1) - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return nil, &dtos.HTTPError{Code: 414, Message: "some"} @@ -158,11 +164,8 @@ func TestSplitSynchronizer(t *testing.T) { splitMockFetcher := fetcherMock.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true") - } - if fetchOptions.ChangeNumber != -1 { - t.Error("Wrong changenumber passed") + if fetchOptions.ChangeNumber() != -1 { + t.Error("Wrong since") } return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1, mockedSplit2, mockedSplit3}, @@ -224,7 +227,7 @@ func TestSplitSyncProcess(t *testing.T) { atomic.AddInt64(&call, 1) switch call { case 1: - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -233,7 +236,7 @@ func TestSplitSyncProcess(t *testing.T) { Till: 3, }, nil case 2: - if fetchOptions.ChangeNumber != 3 { + if fetchOptions.ChangeNumber() != 3 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -376,27 +379,21 @@ func TestByPassingCDN(t *testing.T) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, Since: 1, Till: 2, }, nil case called >= 2 && called <= 11: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, Since: 2, Till: 2, }, nil case called == 12: - if fetchOptions.Till == nil || *fetchOptions.Till != 2 { - t.Error("ChangeNumber flag should be set with value 2") - } + validReqParams(t, fetchOptions, "2") return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, Since: 3, @@ -449,27 +446,21 @@ func TestByPassingCDNLimit(t *testing.T) { atomic.AddInt64(&call, 1) switch called := atomic.LoadInt64(&call); { case called == 1: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, Since: 1, Till: 2, }, nil case called >= 2 && called <= 11: - if fetchOptions.Till != nil { - t.Error("It should be nil") - } + validReqParams(t, fetchOptions, "") return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, Since: 2, Till: 2, }, nil case called >= 12: - if fetchOptions.Till == nil || *fetchOptions.Till != 2 { - t.Error("ChangeNumber flag should be set with value 2") - } + validReqParams(t, fetchOptions, "2") return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1}, Since: 2, @@ -770,7 +761,7 @@ func TestSplitSyncWithSets(t *testing.T) { atomic.AddInt64(&call, 1) switch call { case 1: - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ @@ -826,7 +817,7 @@ func TestSplitSyncWithSetsInConfig(t *testing.T) { atomic.AddInt64(&call, 1) switch call { case 1: - if fetchOptions.ChangeNumber != -1 { + if fetchOptions.ChangeNumber() != -1 { t.Error("Wrong changenumber passed") } return &dtos.SplitChangesDTO{ diff --git a/tasks/segmentsync_test.go b/tasks/segmentsync_test.go index 447f0b67..34031db6 100644 --- a/tasks/segmentsync_test.go +++ b/tasks/segmentsync_test.go @@ -70,9 +70,6 @@ func TestSegmentSyncTask(t *testing.T) { segmentMockFetcher := fetcherMock.MockSegmentFetcher{ FetchCall: func(name string, fetchOptions *service.SegmentRequestParams) (*dtos.SegmentChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("no cache shold be true") - } if name != "segment1" && name != "segment2" { t.Error("Wrong name") } diff --git a/tasks/splitsync_test.go b/tasks/splitsync_test.go index c489751a..8a33d65b 100644 --- a/tasks/splitsync_test.go +++ b/tasks/splitsync_test.go @@ -1,6 +1,7 @@ package tasks import ( + "net/http" "sync/atomic" "testing" "time" @@ -53,12 +54,14 @@ func TestSplitSyncTask(t *testing.T) { splitMockFetcher := fetcherMock.MockSplitFetcher{ FetchCall: func(fetchOptions *service.FlagRequestParams) (*dtos.SplitChangesDTO, error) { - if !fetchOptions.CacheControlHeaders { - t.Error("noCache should be true.") - } atomic.AddInt64(&call, 1) - if fetchOptions.ChangeNumber != -1 { - t.Error("Wrong changenumber passed") + req, _ := http.NewRequest("GET", "test", nil) + fetchOptions.Apply(req) + if req.Header.Get("Cache-Control") != "no-cache" { + t.Error("Wrong header") + } + if req.URL.Query().Get("since") != "-1" { + t.Error("Wrong since") } return &dtos.SplitChangesDTO{ Splits: []dtos.SplitDTO{mockedSplit1, mockedSplit2, mockedSplit3}, From 5cae4af0ef0796d819052938c37d597abbf128a8 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 2 May 2024 16:43:07 -0300 Subject: [PATCH 16/56] doc --- service/commons.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/service/commons.go b/service/commons.go index 2b42912e..47a32a9d 100644 --- a/service/commons.go +++ b/service/commons.go @@ -23,6 +23,7 @@ type queryParamater struct { value string } +// RequestParams interface for request parameters type RequestParams interface { Apply(request *http.Request) error } @@ -31,6 +32,7 @@ type baseRequestParams struct { cacheControlHeaders bool } +// FlagRequestParams struct for flag request parameters type FlagRequestParams struct { baseRequestParams changeNumber int64 @@ -39,6 +41,7 @@ type FlagRequestParams struct { till *int64 } +// MakeFlagRequestParams returns a new instance of FlagRequestParams func MakeFlagRequestParams() *FlagRequestParams { return &FlagRequestParams{ baseRequestParams: baseRequestParams{ @@ -47,35 +50,42 @@ func MakeFlagRequestParams() *FlagRequestParams { } } +// WithCacheControl sets the cache control header func (s *FlagRequestParams) WithCacheControl(cacheControl bool) *FlagRequestParams { s.cacheControlHeaders = cacheControl return s } +// WithChangeNumber sets the change number func (s *FlagRequestParams) WithChangeNumber(changeNumber int64) *FlagRequestParams { s.changeNumber = changeNumber return s } +// WithFlagSetsFilter sets the flag sets filter func (s *FlagRequestParams) WithFlagSetsFilter(flagSetsFilter string) *FlagRequestParams { s.flagSetsFilter = flagSetsFilter return s } +// WithSpecVersion sets the spec version func (s *FlagRequestParams) WithSpecVersion(specVersion *string) *FlagRequestParams { s.specVersion = specVersion return s } +// WithTill sets the till func (s *FlagRequestParams) WithTill(till int64) *FlagRequestParams { s.till = common.Int64Ref(till) return s } +// ChangeNumber returns the change number func (s *FlagRequestParams) ChangeNumber() int64 { return s.changeNumber } +// Apply applies the request parameters func (s *FlagRequestParams) Apply(request *http.Request) error { if s.cacheControlHeaders { request.Header.Set(cacheControl, cacheControlNoCache) @@ -97,12 +107,14 @@ func (s *FlagRequestParams) Apply(request *http.Request) error { return nil } +// SegmentRequestParams struct for segment request parameters type SegmentRequestParams struct { baseRequestParams changeNumber int64 till *int64 } +// MakeSegmentRequestParams returns a new instance of SegmentRequestParams func MakeSegmentRequestParams() *SegmentRequestParams { return &SegmentRequestParams{ baseRequestParams: baseRequestParams{ @@ -111,25 +123,30 @@ func MakeSegmentRequestParams() *SegmentRequestParams { } } +// WithCacheControl sets the cache control header func (s *SegmentRequestParams) WithCacheControl(cacheControl bool) *SegmentRequestParams { s.cacheControlHeaders = cacheControl return s } +// WithChangeNumber sets the change number func (s *SegmentRequestParams) WithChangeNumber(changeNumber int64) *SegmentRequestParams { s.changeNumber = changeNumber return s } +// WithTill sets the till func (s *SegmentRequestParams) WithTill(till int64) *SegmentRequestParams { s.till = common.Int64Ref(till) return s } +// ChangeNumber returns the change number func (s *SegmentRequestParams) ChangeNumber() int64 { return s.changeNumber } +// Apply applies the request parameters func (s *SegmentRequestParams) Apply(request *http.Request) error { if s.cacheControlHeaders { request.Header.Set(cacheControl, cacheControlNoCache) @@ -145,11 +162,13 @@ func (s *SegmentRequestParams) Apply(request *http.Request) error { return nil } +// AuthRequestParams struct for auth request parameters type AuthRequestParams struct { baseRequestParams specVersion *string } +// MakeAuthRequestParams returns a new instance of AuthRequestParams func MakeAuthRequestParams(specVersion *string) *AuthRequestParams { return &AuthRequestParams{ baseRequestParams: baseRequestParams{ @@ -159,11 +178,13 @@ func MakeAuthRequestParams(specVersion *string) *AuthRequestParams { } } +// WithCacheControl sets the cache control header func (s *AuthRequestParams) WithCacheControl(cacheControl bool) *AuthRequestParams { s.cacheControlHeaders = cacheControl return s } +// WithSpecVersion sets the spec version func (s *AuthRequestParams) Apply(request *http.Request) error { if s.cacheControlHeaders { request.Header.Set(cacheControl, cacheControlNoCache) From b129e757301d87972c5e03e860c8e61b71c29a95 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 3 May 2024 12:59:51 -0300 Subject: [PATCH 17/56] make public override --- engine/validator/matchers.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 39bb3252..8a47f77e 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -10,17 +10,22 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) +// OverrideWithUnsupported overrides the split with an unsupported matcher type +func OverrideWithUnsupported(split *dtos.SplitDTO, idx int, jdx int) { + split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist + split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys + split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil + split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType + split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}} +} + // ProcessMatchers processes the matchers of a split and validates them func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) { for idx := range split.Conditions { for jdx := range split.Conditions[idx].MatcherGroup.Matchers { _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, logger) if err != nil { - split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist - split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys - split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil - split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType - split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}} + OverrideWithUnsupported(split, idx, jdx) } } } From a294e1519e8b81353e9a4ba3c7eff1b6a48ccbd3 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 3 May 2024 16:41:55 -0300 Subject: [PATCH 18/56] Add Semver --- engine/grammar/matchers/datatypes/semver.go | 202 ++++++++++++++++++ .../grammar/matchers/datatypes/semver_test.go | 179 ++++++++++++++++ testdata/between_semver.csv | 14 ++ testdata/equal_to_semver.csv | 6 + testdata/invalid_semantic_versions.csv | 30 +++ testdata/valid_semantic_versions.csv | 20 ++ 6 files changed, 451 insertions(+) create mode 100644 engine/grammar/matchers/datatypes/semver.go create mode 100644 engine/grammar/matchers/datatypes/semver_test.go create mode 100644 testdata/between_semver.csv create mode 100644 testdata/equal_to_semver.csv create mode 100644 testdata/invalid_semantic_versions.csv create mode 100644 testdata/valid_semantic_versions.csv diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go new file mode 100644 index 00000000..0152d686 --- /dev/null +++ b/engine/grammar/matchers/datatypes/semver.go @@ -0,0 +1,202 @@ +package datatypes + +import ( + "fmt" + "strconv" + + "strings" +) + +const ( + MetadataDelimiter = "+" + PreReleaseDelimiter = "-" + ValueDelimiter = "." +) + +type Semver struct { + major int64 + minor int64 + patch int64 + preRealse []string + isStable bool + metadata string + version string +} + +func BuildSemver(version string) (*Semver, error) { + if len(strings.TrimSpace(version)) == 0 { + return nil, fmt.Errorf("unable to convert to semver, version cannot be empty") + } + metadata, vWithoutMetadata, err := processMetadata(version) + if err != nil { + return nil, err + } + preRealse, vWithoutPreRelease, err := processPreRelease(vWithoutMetadata) + if err != nil { + return nil, err + } + major, minor, patch, err := processComponents(vWithoutPreRelease) + if err != nil { + return nil, err + } + + return &Semver{ + metadata: metadata, + preRealse: preRealse, + major: major, + minor: minor, + patch: patch, + isStable: len(preRealse) == 0, + version: version, + }, nil +} + +func processMetadata(version string) (string, string, error) { + index, metadata := calculateIndexAndTrimString(version, MetadataDelimiter) + if index == -1 { + return "", version, nil + } + + if len(metadata) == 0 { + return "", "", fmt.Errorf("unable to convert to semver, incorrect pre release data") + + } + return metadata, strings.TrimSpace(version[0:index]), nil +} + +func processPreRelease(vWithoutMetadata string) ([]string, string, error) { + index, preReleaseData := calculateIndexAndTrimString(vWithoutMetadata, PreReleaseDelimiter) + if index == -1 { + return nil, vWithoutMetadata, nil + } + + preRealse := strings.Split(preReleaseData, ValueDelimiter) + + if len(preRealse) == 0 || isEmpty(preRealse) { + return nil, "", fmt.Errorf("unable to convert to semver, incorrect pre release data") + } + return preRealse, strings.TrimSpace(vWithoutMetadata[0:index]), nil +} + +func calculateIndexAndTrimString(vWithoutMetadata string, delimiter string) (int, string) { + index := strings.Index(vWithoutMetadata, delimiter) + if index == -1 { + return index, "" + } + + return index, strings.TrimSpace(vWithoutMetadata[index+1:]) +} + +func isEmpty(preRelease []string) bool { + for _, pr := range preRelease { + if len(pr) == 0 { + return true + } + } + return false +} + +func processComponents(version string) (int64, int64, int64, error) { + vParts := strings.Split(version, ValueDelimiter) + if len(vParts) != 3 { + return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + } + + major, err := strconv.ParseInt(vParts[0], 10, 64) + if err != nil { + return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + } + minor, err := strconv.ParseInt(vParts[1], 10, 64) + if err != nil { + return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + } + patch, err := strconv.ParseInt(vParts[2], 10, 64) + if err != nil { + return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + } + return major, minor, patch, nil +} + +func (s *Semver) Compare(toCompare Semver) int { + if s.version == toCompare.version { + return 0 + } + + // Compare major, minor, and patch versions numerically + compareResult := compareLongs(s.major, toCompare.major) + if compareResult != 0 { + return compareResult + } + + compareResult = compareLongs(s.minor, toCompare.minor) + if compareResult != 0 { + return compareResult + } + + compareResult = compareLongs(s.patch, toCompare.patch) + if compareResult != 0 { + return compareResult + } + + if !s.isStable && toCompare.isStable { + return -1 + } else if s.isStable && !toCompare.isStable { + return 1 + } + + minLength := 0 + if len(s.preRealse) > len(toCompare.preRealse) { + minLength = len(toCompare.preRealse) + } else { + minLength = len(s.preRealse) + } + // Compare pre-release versions lexically + for i := 0; i < minLength; i++ { + if s.preRealse[i] == toCompare.preRealse[i] { + continue + } + if isNumeric(s.preRealse[i]) && isNumeric(toCompare.preRealse[i]) { + preRelease1, err := strconv.ParseInt(s.preRealse[i], 10, 64) + if err != nil { + return -1 + } + preRelease2, err := strconv.ParseInt(s.preRealse[i], 10, 64) + if err != nil { + return -1 + } + if preRelease1 != preRelease2 { + if preRelease1 < preRelease2 { + return -1 + } + return 1 + } else { + return 0 + } + } + return strings.Compare(s.preRealse[i], toCompare.preRealse[i]) + } + + // Compare lengths of pre-release versions + sPreReleaseLen := len(s.preRealse) + toComparePreReleaseLen := len(toCompare.preRealse) + + return compareLongs(int64(sPreReleaseLen), int64(toComparePreReleaseLen)) +} + +func isNumeric(strNum string) bool { + if len(strNum) == 0 { + return false + } + _, err := strconv.ParseInt(strNum, 10, 0) + return err == nil +} + +func compareLongs(compare1 int64, compare2 int64) int { + if compare1 != compare2 { + if compare1 < compare2 { + return -1 + } + return 1 + } + return 0 +} diff --git a/engine/grammar/matchers/datatypes/semver_test.go b/engine/grammar/matchers/datatypes/semver_test.go new file mode 100644 index 00000000..5b051a34 --- /dev/null +++ b/engine/grammar/matchers/datatypes/semver_test.go @@ -0,0 +1,179 @@ +package datatypes + +import ( + "encoding/csv" + "io" + "os" + "testing" +) + +type Semvers struct { + semver1 string + semver2 string + semver3 string +} + +func TestCompareSemver(t *testing.T) { + semvers, err := parseCSVTwoSemvers("../../../../testdata/valid_semantic_versions.csv") + if err != nil { + t.Error(err) + } + + for _, semversPair := range semvers { + semver1, err := BuildSemver(semversPair.semver1) + if err != nil { + t.Error("should create semver1") + } + semver2, err := BuildSemver(semversPair.semver2) + if err != nil { + t.Error("should create semver2") + } + + if semver1.Compare(*semver2) < 0 { + t.Error("semver 1 should be greather than semver 2") + } + if semver2.Compare(*semver1) > 0 { + t.Error("semver 1 should be greather than semver 2") + } + if semver1.Compare(*semver1) != 0 { + t.Error("semver 1 should be equal to semver 1") + } + if semver2.Compare(*semver2) != 0 { + t.Error("semver 2 should be equal to semver 2") + } + } +} + +func TestInvalidFormats(t *testing.T) { + semvers, err := parseCSVOneSemver("../../../../testdata/invalid_semantic_versions.csv") + if err != nil { + t.Error(err) + } + for _, semver := range semvers { + _, err := BuildSemver(semver) + if err == nil { + t.Error("should not create semver") + } + } +} + +func TestEqualTo(t *testing.T) { + semvers, err := parseCSVTwoSemvers("../../../../testdata/equal_to_semver.csv") + if err != nil { + t.Error(err) + } + + for _, semversPair := range semvers { + semver1, err := BuildSemver(semversPair.semver1) + if err != nil { + t.Error("should create semver1") + } + semver2, err := BuildSemver(semversPair.semver2) + if err != nil { + t.Error("should create semver2") + } + + if semver1.Compare(*semver2) != 0 { + t.Error("semver 1 should be equal to semver 2") + } + } +} + +func TestBetween(t *testing.T) { + semvers, err := parseCSVThreeSemvers("../../../../testdata/between_semver.csv") + if err != nil { + t.Error(err) + } + + for _, threeSemvers := range semvers { + semver1, err := BuildSemver(threeSemvers.semver1) + if err != nil { + t.Error("should create semver1") + } + semver2, err := BuildSemver(threeSemvers.semver2) + if err != nil { + t.Error("should create semver2") + } + semver3, err := BuildSemver(threeSemvers.semver3) + if err != nil { + t.Error("should create semver2") + } + + if semver2.Compare(*semver1) < 0 && semver2.Compare(*semver3) > 0 { + t.Error("semver 2 should be between to semver 1 and semver 3") + } + } +} + +func parseCSVOneSemver(file string) ([]string, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + defer f.Close() + + csvr := csv.NewReader(f) + + var results []string + for { + row, err := csvr.Read() + if err != nil { + if err == io.EOF { + err = nil + } + return results, err + } + results = append(results, row[0]) + } +} + +func parseCSVTwoSemvers(file string) ([]Semvers, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + defer f.Close() + + csvr := csv.NewReader(f) + + var results []Semvers + for { + row, err := csvr.Read() + if err != nil { + if err == io.EOF { + err = nil + } + return results, err + } + results = append(results, Semvers{ + semver1: row[0], + semver2: row[1], + }) + } +} + +func parseCSVThreeSemvers(file string) ([]Semvers, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + defer f.Close() + + csvr := csv.NewReader(f) + + var results []Semvers + for { + row, err := csvr.Read() + if err != nil { + if err == io.EOF { + err = nil + } + return results, err + } + results = append(results, Semvers{ + semver1: row[0], + semver2: row[1], + semver3: row[2], + }) + } +} diff --git a/testdata/between_semver.csv b/testdata/between_semver.csv new file mode 100644 index 00000000..ae7148c0 --- /dev/null +++ b/testdata/between_semver.csv @@ -0,0 +1,14 @@ +1.1.1,2.2.2,3.3.3 +1.1.1-rc.1,1.1.1-rc.2,1.1.1-rc.3 +1.0.0-alpha,1.0.0-alpha.1,1.0.0-alpha.beta +1.0.0-alpha.1,1.0.0-alpha.beta,1.0.0-beta +1.0.0-alpha.beta,1.0.0-beta,1.0.0-beta.2 +1.0.0-beta,1.0.0-beta.2,1.0.0-beta.11 +1.0.0-beta.2,1.0.0-beta.11,1.0.0-rc.1 +1.0.0-beta.11,1.0.0-rc.1,1.0.0 +1.1.2,1.1.3,1.1.4 +1.2.1,1.3.1,1.4.1 +2.0.0,3.0.0,4.0.0 +2.2.2,2.2.3-rc1,2.2.3 +2.2.2,2.3.2-rc100,2.3.3 +1.0.0-rc.1+build.1,1.2.3-beta,1.2.3-rc.1+build.123 \ No newline at end of file diff --git a/testdata/equal_to_semver.csv b/testdata/equal_to_semver.csv new file mode 100644 index 00000000..8c680776 --- /dev/null +++ b/testdata/equal_to_semver.csv @@ -0,0 +1,6 @@ +1.1.1,1.1.1 +88.88.88,88.88.88 +1.2.3----RC-SNAPSHOT.12.9.1--.12,1.2.3----RC-SNAPSHOT.12.9.1--.12 +00.01.002-0003.00004,0.1.2-3.4 +1.1.2-prerelease+meta, 1.1.2-prerelease+meta +1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay, 1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay \ No newline at end of file diff --git a/testdata/invalid_semantic_versions.csv b/testdata/invalid_semantic_versions.csv new file mode 100644 index 00000000..2d5c5a6f --- /dev/null +++ b/testdata/invalid_semantic_versions.csv @@ -0,0 +1,30 @@ +1 +1.2 +1.alpha.2 ++invalid +-invalid +-invalid+invalid +-invalid.01 +alpha +alpha.beta +alpha.beta.1 +alpha.1 +alpha+beta +alpha_beta +alpha. +alpha.. +beta +-alpha. +1.2 +1.2.3.DEV +1.2-SNAPSHOT +1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788 +1.2-RC-SNAPSHOT +-1.0.3-gamma+b7718 ++justmeta +99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12 +1.1.1- +999.999.999----RC-SNAPSHOT.12.09.1--------------------------------..12 +1.2.31----RC-SNAPSHOT.12.09.1--..12+788 +1..1 +2.2.2+ \ No newline at end of file diff --git a/testdata/valid_semantic_versions.csv b/testdata/valid_semantic_versions.csv new file mode 100644 index 00000000..b7110ab1 --- /dev/null +++ b/testdata/valid_semantic_versions.csv @@ -0,0 +1,20 @@ +1.2.3----RC-SNAPSHOT.12.9.1--.12+788,1.2.3----R-S.12.9.1--.12+meta +1.1.2,1.1.1 +1.0.0,1.0.0-rc.1 +1.1.0-rc.1,1.0.0-beta.11 +1.0.0-beta.11,1.0.0-beta.2 +1.0.0-beta.2,1.0.0-beta +1.0.0-beta,1.0.0-alpha.beta +1.0.0-alpha.beta,1.0.0-alpha.1 +1.0.0-alpha.1,1.0.0-alpha +2.2.2-rc.2+metadata-lalala,2.2.2-rc.1.2 +1.2.3,0.0.4 +1.1.2+meta,1.1.2-prerelease+meta +1.0.0-beta,1.0.0-alpha +1.0.0-alpha0.valid,1.0.0-alpha.0valid +1.0.0-rc.1+build.1,1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay +10.2.3-DEV-SNAPSHOT,1.2.3-SNAPSHOT-123 +1.1.1-rc2,1.0.0-0A.is.legal +1.2.3----RC-SNAPSHOT.12.9.1--.12.88,1.2.3----RC-SNAPSHOT.12.9.1--.12 +9223372036854775807.9223372036854775807.9223372036854775807,9223372036854775807.9223372036854775807.9223372036854775806 +1.1.1-alpha.beta.rc.build.java.pr.support.10,1.1.1-alpha.beta.rc.build.java.pr.support \ No newline at end of file From e27538248eb8471cf954d827b2b17b74fb271351 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 3 May 2024 17:06:58 -0300 Subject: [PATCH 19/56] Update Semver --- engine/grammar/matchers/datatypes/semver.go | 62 ++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index 0152d686..a88fbe30 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -14,13 +14,13 @@ const ( ) type Semver struct { - major int64 - minor int64 - patch int64 - preRealse []string - isStable bool - metadata string - version string + major int64 + minor int64 + patch int64 + preRelease []string + isStable bool + metadata string + version string } func BuildSemver(version string) (*Semver, error) { @@ -31,7 +31,7 @@ func BuildSemver(version string) (*Semver, error) { if err != nil { return nil, err } - preRealse, vWithoutPreRelease, err := processPreRelease(vWithoutMetadata) + preRelease, vWithoutPreRelease, err := processPreRelease(vWithoutMetadata) if err != nil { return nil, err } @@ -41,13 +41,13 @@ func BuildSemver(version string) (*Semver, error) { } return &Semver{ - metadata: metadata, - preRealse: preRealse, - major: major, - minor: minor, - patch: patch, - isStable: len(preRealse) == 0, - version: version, + metadata: metadata, + preRelease: preRelease, + major: major, + minor: minor, + patch: patch, + isStable: len(preRelease) == 0, + version: version, }, nil } @@ -70,21 +70,21 @@ func processPreRelease(vWithoutMetadata string) ([]string, string, error) { return nil, vWithoutMetadata, nil } - preRealse := strings.Split(preReleaseData, ValueDelimiter) + preRelease := strings.Split(preReleaseData, ValueDelimiter) - if len(preRealse) == 0 || isEmpty(preRealse) { + if len(preRelease) == 0 || isEmpty(preRelease) { return nil, "", fmt.Errorf("unable to convert to semver, incorrect pre release data") } - return preRealse, strings.TrimSpace(vWithoutMetadata[0:index]), nil + return preRelease, strings.TrimSpace(vWithoutMetadata[0:index]), nil } -func calculateIndexAndTrimString(vWithoutMetadata string, delimiter string) (int, string) { - index := strings.Index(vWithoutMetadata, delimiter) +func calculateIndexAndTrimString(stringToTrim string, delimiter string) (int, string) { + index := strings.Index(stringToTrim, delimiter) if index == -1 { return index, "" } - return index, strings.TrimSpace(vWithoutMetadata[index+1:]) + return index, strings.TrimSpace(stringToTrim[index+1:]) } func isEmpty(preRelease []string) bool { @@ -145,22 +145,22 @@ func (s *Semver) Compare(toCompare Semver) int { } minLength := 0 - if len(s.preRealse) > len(toCompare.preRealse) { - minLength = len(toCompare.preRealse) + if len(s.preRelease) > len(toCompare.preRelease) { + minLength = len(toCompare.preRelease) } else { - minLength = len(s.preRealse) + minLength = len(s.preRelease) } // Compare pre-release versions lexically for i := 0; i < minLength; i++ { - if s.preRealse[i] == toCompare.preRealse[i] { + if s.preRelease[i] == toCompare.preRelease[i] { continue } - if isNumeric(s.preRealse[i]) && isNumeric(toCompare.preRealse[i]) { - preRelease1, err := strconv.ParseInt(s.preRealse[i], 10, 64) + if isNumeric(s.preRelease[i]) && isNumeric(toCompare.preRelease[i]) { + preRelease1, err := strconv.ParseInt(s.preRelease[i], 10, 64) if err != nil { return -1 } - preRelease2, err := strconv.ParseInt(s.preRealse[i], 10, 64) + preRelease2, err := strconv.ParseInt(s.preRelease[i], 10, 64) if err != nil { return -1 } @@ -173,12 +173,12 @@ func (s *Semver) Compare(toCompare Semver) int { return 0 } } - return strings.Compare(s.preRealse[i], toCompare.preRealse[i]) + return strings.Compare(s.preRelease[i], toCompare.preRelease[i]) } // Compare lengths of pre-release versions - sPreReleaseLen := len(s.preRealse) - toComparePreReleaseLen := len(toCompare.preRealse) + sPreReleaseLen := len(s.preRelease) + toComparePreReleaseLen := len(toCompare.preRelease) return compareLongs(int64(sPreReleaseLen), int64(toComparePreReleaseLen)) } From aacfa3e7ebe50c25b651997b53b029d495d2a1eb Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 3 May 2024 21:37:37 -0300 Subject: [PATCH 20/56] PR suggestions --- engine/grammar/matchers/datatypes/semver.go | 56 +++++++++------------ testdata/invalid_semantic_versions.csv | 3 +- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index a88fbe30..cf244d1f 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -8,9 +8,10 @@ import ( ) const ( - MetadataDelimiter = "+" - PreReleaseDelimiter = "-" - ValueDelimiter = "." + metadataDelimiter = "+" + preReleaseDelimiter = "-" + valueDelimiter = "." + unableToConvertSemverMessage = "unable to convert to semver, incorrect format: %s" ) type Semver struct { @@ -52,39 +53,39 @@ func BuildSemver(version string) (*Semver, error) { } func processMetadata(version string) (string, string, error) { - index, metadata := calculateIndexAndTrimString(version, MetadataDelimiter) + index, metadata := extract(version, metadataDelimiter) if index == -1 { return "", version, nil } if len(metadata) == 0 { - return "", "", fmt.Errorf("unable to convert to semver, incorrect pre release data") + return "", "", fmt.Errorf("unable to convert to semver, incorrect metadata") } return metadata, strings.TrimSpace(version[0:index]), nil } func processPreRelease(vWithoutMetadata string) ([]string, string, error) { - index, preReleaseData := calculateIndexAndTrimString(vWithoutMetadata, PreReleaseDelimiter) + index, preReleaseData := extract(vWithoutMetadata, preReleaseDelimiter) if index == -1 { return nil, vWithoutMetadata, nil } - preRelease := strings.Split(preReleaseData, ValueDelimiter) + preRelease := strings.Split(preReleaseData, valueDelimiter) if len(preRelease) == 0 || isEmpty(preRelease) { - return nil, "", fmt.Errorf("unable to convert to semver, incorrect pre release data") + return nil, "", fmt.Errorf("unable to convert to semver, incorrect prerelease data") } return preRelease, strings.TrimSpace(vWithoutMetadata[0:index]), nil } -func calculateIndexAndTrimString(stringToTrim string, delimiter string) (int, string) { - index := strings.Index(stringToTrim, delimiter) +func extract(str string, delimiter string) (int, string) { + index := strings.Index(str, delimiter) if index == -1 { return index, "" } - return index, strings.TrimSpace(stringToTrim[index+1:]) + return index, strings.TrimSpace(str[index+1:]) } func isEmpty(preRelease []string) bool { @@ -97,22 +98,22 @@ func isEmpty(preRelease []string) bool { } func processComponents(version string) (int64, int64, int64, error) { - vParts := strings.Split(version, ValueDelimiter) + vParts := strings.Split(version, valueDelimiter) if len(vParts) != 3 { - return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) } major, err := strconv.ParseInt(vParts[0], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) } minor, err := strconv.ParseInt(vParts[1], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) } patch, err := strconv.ParseInt(vParts[2], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf("unable to convert to semver, incorrect format: %s", version) + return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) } return major, minor, patch, nil } @@ -164,14 +165,7 @@ func (s *Semver) Compare(toCompare Semver) int { if err != nil { return -1 } - if preRelease1 != preRelease2 { - if preRelease1 < preRelease2 { - return -1 - } - return 1 - } else { - return 0 - } + return compareLongs(preRelease1, preRelease2) } return strings.Compare(s.preRelease[i], toCompare.preRelease[i]) } @@ -187,16 +181,16 @@ func isNumeric(strNum string) bool { if len(strNum) == 0 { return false } - _, err := strconv.ParseInt(strNum, 10, 0) + _, err := strconv.ParseInt(strNum, 10, 64) return err == nil } func compareLongs(compare1 int64, compare2 int64) int { - if compare1 != compare2 { - if compare1 < compare2 { - return -1 - } - return 1 + if compare1 == compare2 { + return 0 + } + if compare1 < compare2 { + return -1 } - return 0 + return 1 } diff --git a/testdata/invalid_semantic_versions.csv b/testdata/invalid_semantic_versions.csv index 2d5c5a6f..9268df4b 100644 --- a/testdata/invalid_semantic_versions.csv +++ b/testdata/invalid_semantic_versions.csv @@ -27,4 +27,5 @@ beta 999.999.999----RC-SNAPSHOT.12.09.1--------------------------------..12 1.2.31----RC-SNAPSHOT.12.09.1--..12+788 1..1 -2.2.2+ \ No newline at end of file +2.2.2+ + 1.3.4 \ No newline at end of file From 52e5c527f5f37a88d234b68c5a92875b73adc58e Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Mon, 6 May 2024 09:43:39 -0300 Subject: [PATCH 21/56] Update log errors --- engine/grammar/matchers/datatypes/semver.go | 28 ++++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index cf244d1f..91b418f8 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -1,19 +1,23 @@ package datatypes import ( - "fmt" + "errors" "strconv" "strings" ) const ( - metadataDelimiter = "+" - preReleaseDelimiter = "-" - valueDelimiter = "." - unableToConvertSemverMessage = "unable to convert to semver, incorrect format: %s" + metadataDelimiter = "+" + preReleaseDelimiter = "-" + valueDelimiter = "." ) +var ErrEmptyVersion = errors.New("version cannot be empty") +var ErrInvalidMetadata = errors.New("invalid metadata when parsing semver") +var ErrInvalidPrerelease = errors.New("invalid prerelease when parsing semver") +var ErrUnableToConvertSemver = errors.New("unable to convert to semver, incorrect format") + type Semver struct { major int64 minor int64 @@ -26,7 +30,7 @@ type Semver struct { func BuildSemver(version string) (*Semver, error) { if len(strings.TrimSpace(version)) == 0 { - return nil, fmt.Errorf("unable to convert to semver, version cannot be empty") + return nil, ErrEmptyVersion } metadata, vWithoutMetadata, err := processMetadata(version) if err != nil { @@ -59,7 +63,7 @@ func processMetadata(version string) (string, string, error) { } if len(metadata) == 0 { - return "", "", fmt.Errorf("unable to convert to semver, incorrect metadata") + return "", "", ErrInvalidMetadata } return metadata, strings.TrimSpace(version[0:index]), nil @@ -74,7 +78,7 @@ func processPreRelease(vWithoutMetadata string) ([]string, string, error) { preRelease := strings.Split(preReleaseData, valueDelimiter) if len(preRelease) == 0 || isEmpty(preRelease) { - return nil, "", fmt.Errorf("unable to convert to semver, incorrect prerelease data") + return nil, "", ErrInvalidPrerelease } return preRelease, strings.TrimSpace(vWithoutMetadata[0:index]), nil } @@ -100,20 +104,20 @@ func isEmpty(preRelease []string) bool { func processComponents(version string) (int64, int64, int64, error) { vParts := strings.Split(version, valueDelimiter) if len(vParts) != 3 { - return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) + return 0, 0, 0, ErrUnableToConvertSemver } major, err := strconv.ParseInt(vParts[0], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) + return 0, 0, 0, ErrUnableToConvertSemver } minor, err := strconv.ParseInt(vParts[1], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) + return 0, 0, 0, ErrUnableToConvertSemver } patch, err := strconv.ParseInt(vParts[2], 10, 64) if err != nil { - return 0, 0, 0, fmt.Errorf(unableToConvertSemverMessage, version) + return 0, 0, 0, ErrUnableToConvertSemver } return major, minor, patch, nil } From bc88f82a749774681f097f4d092f42148ce8cbc1 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Mon, 6 May 2024 11:17:16 -0300 Subject: [PATCH 22/56] Update compare and test cases --- engine/grammar/matchers/datatypes/semver.go | 32 ++++++++----------- .../grammar/matchers/datatypes/semver_test.go | 2 +- testdata/valid_semantic_versions.csv | 3 +- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index 91b418f8..aef4c42f 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -13,10 +13,10 @@ const ( valueDelimiter = "." ) -var ErrEmptyVersion = errors.New("version cannot be empty") -var ErrInvalidMetadata = errors.New("invalid metadata when parsing semver") -var ErrInvalidPrerelease = errors.New("invalid prerelease when parsing semver") -var ErrUnableToConvertSemver = errors.New("unable to convert to semver, incorrect format") +var errEmptyVersion = errors.New("version cannot be empty") +var errInvalidMetadata = errors.New("invalid metadata when parsing semver") +var errInvalidPrerelease = errors.New("invalid prerelease when parsing semver") +var errUnableToConvertSemver = errors.New("unable to convert to semver, incorrect format") type Semver struct { major int64 @@ -30,7 +30,7 @@ type Semver struct { func BuildSemver(version string) (*Semver, error) { if len(strings.TrimSpace(version)) == 0 { - return nil, ErrEmptyVersion + return nil, errEmptyVersion } metadata, vWithoutMetadata, err := processMetadata(version) if err != nil { @@ -63,7 +63,7 @@ func processMetadata(version string) (string, string, error) { } if len(metadata) == 0 { - return "", "", ErrInvalidMetadata + return "", "", errInvalidMetadata } return metadata, strings.TrimSpace(version[0:index]), nil @@ -78,7 +78,7 @@ func processPreRelease(vWithoutMetadata string) ([]string, string, error) { preRelease := strings.Split(preReleaseData, valueDelimiter) if len(preRelease) == 0 || isEmpty(preRelease) { - return nil, "", ErrInvalidPrerelease + return nil, "", errInvalidPrerelease } return preRelease, strings.TrimSpace(vWithoutMetadata[0:index]), nil } @@ -104,20 +104,20 @@ func isEmpty(preRelease []string) bool { func processComponents(version string) (int64, int64, int64, error) { vParts := strings.Split(version, valueDelimiter) if len(vParts) != 3 { - return 0, 0, 0, ErrUnableToConvertSemver + return 0, 0, 0, errUnableToConvertSemver } major, err := strconv.ParseInt(vParts[0], 10, 64) if err != nil { - return 0, 0, 0, ErrUnableToConvertSemver + return 0, 0, 0, errUnableToConvertSemver } minor, err := strconv.ParseInt(vParts[1], 10, 64) if err != nil { - return 0, 0, 0, ErrUnableToConvertSemver + return 0, 0, 0, errUnableToConvertSemver } patch, err := strconv.ParseInt(vParts[2], 10, 64) if err != nil { - return 0, 0, 0, ErrUnableToConvertSemver + return 0, 0, 0, errUnableToConvertSemver } return major, minor, patch, nil } @@ -161,14 +161,8 @@ func (s *Semver) Compare(toCompare Semver) int { continue } if isNumeric(s.preRelease[i]) && isNumeric(toCompare.preRelease[i]) { - preRelease1, err := strconv.ParseInt(s.preRelease[i], 10, 64) - if err != nil { - return -1 - } - preRelease2, err := strconv.ParseInt(s.preRelease[i], 10, 64) - if err != nil { - return -1 - } + preRelease1, _ := strconv.ParseInt(s.preRelease[i], 10, 64) + preRelease2, _ := strconv.ParseInt(s.preRelease[i], 10, 64) return compareLongs(preRelease1, preRelease2) } return strings.Compare(s.preRelease[i], toCompare.preRelease[i]) diff --git a/engine/grammar/matchers/datatypes/semver_test.go b/engine/grammar/matchers/datatypes/semver_test.go index 5b051a34..b5fd8fa7 100644 --- a/engine/grammar/matchers/datatypes/semver_test.go +++ b/engine/grammar/matchers/datatypes/semver_test.go @@ -13,7 +13,7 @@ type Semvers struct { semver3 string } -func TestCompareSemver(t *testing.T) { +func TestCompareSemverToGreaterAndEqual(t *testing.T) { semvers, err := parseCSVTwoSemvers("../../../../testdata/valid_semantic_versions.csv") if err != nil { t.Error(err) diff --git a/testdata/valid_semantic_versions.csv b/testdata/valid_semantic_versions.csv index b7110ab1..d34b5d78 100644 --- a/testdata/valid_semantic_versions.csv +++ b/testdata/valid_semantic_versions.csv @@ -17,4 +17,5 @@ 1.1.1-rc2,1.0.0-0A.is.legal 1.2.3----RC-SNAPSHOT.12.9.1--.12.88,1.2.3----RC-SNAPSHOT.12.9.1--.12 9223372036854775807.9223372036854775807.9223372036854775807,9223372036854775807.9223372036854775807.9223372036854775806 -1.1.1-alpha.beta.rc.build.java.pr.support.10,1.1.1-alpha.beta.rc.build.java.pr.support \ No newline at end of file +1.1.1-alpha.beta.rc.build.java.pr.support.10,1.1.1-alpha.beta.rc.build.java.pr.support +1.0.0-beta+hjadshksh,1.0.0-beta+f \ No newline at end of file From ec7d38f6c5688c11826d67fe407ede7ea5158a4e Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Mon, 6 May 2024 12:00:26 -0300 Subject: [PATCH 23/56] Add equal to semver --- engine/grammar/matchers/equaltosemver.go | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 engine/grammar/matchers/equaltosemver.go diff --git a/engine/grammar/matchers/equaltosemver.go b/engine/grammar/matchers/equaltosemver.go new file mode 100644 index 00000000..6354e341 --- /dev/null +++ b/engine/grammar/matchers/equaltosemver.go @@ -0,0 +1,6 @@ +package matchers + +type EqualToSemverMatcher struct { + Matcher + ComparisonValue string +} From 76c2bd67ebe55d210e3ec183849ac5b1bf321dc9 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Mon, 6 May 2024 12:07:22 -0300 Subject: [PATCH 24/56] Update compare --- engine/grammar/matchers/datatypes/semver.go | 36 ++++++++------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index aef4c42f..1b9060ec 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -13,10 +13,10 @@ const ( valueDelimiter = "." ) -var errEmptyVersion = errors.New("version cannot be empty") -var errInvalidMetadata = errors.New("invalid metadata when parsing semver") -var errInvalidPrerelease = errors.New("invalid prerelease when parsing semver") -var errUnableToConvertSemver = errors.New("unable to convert to semver, incorrect format") +var ErrEmptyVersion = errors.New("version cannot be empty") +var ErrInvalidMetadata = errors.New("invalid metadata when parsing semver") +var ErrInvalidPrerelease = errors.New("invalid prerelease when parsing semver") +var ErrUnableToConvertSemver = errors.New("unable to convert to semver, incorrect format") type Semver struct { major int64 @@ -30,7 +30,7 @@ type Semver struct { func BuildSemver(version string) (*Semver, error) { if len(strings.TrimSpace(version)) == 0 { - return nil, errEmptyVersion + return nil, ErrEmptyVersion } metadata, vWithoutMetadata, err := processMetadata(version) if err != nil { @@ -63,7 +63,7 @@ func processMetadata(version string) (string, string, error) { } if len(metadata) == 0 { - return "", "", errInvalidMetadata + return "", "", ErrInvalidMetadata } return metadata, strings.TrimSpace(version[0:index]), nil @@ -78,7 +78,7 @@ func processPreRelease(vWithoutMetadata string) ([]string, string, error) { preRelease := strings.Split(preReleaseData, valueDelimiter) if len(preRelease) == 0 || isEmpty(preRelease) { - return nil, "", errInvalidPrerelease + return nil, "", ErrInvalidPrerelease } return preRelease, strings.TrimSpace(vWithoutMetadata[0:index]), nil } @@ -104,20 +104,20 @@ func isEmpty(preRelease []string) bool { func processComponents(version string) (int64, int64, int64, error) { vParts := strings.Split(version, valueDelimiter) if len(vParts) != 3 { - return 0, 0, 0, errUnableToConvertSemver + return 0, 0, 0, ErrUnableToConvertSemver } major, err := strconv.ParseInt(vParts[0], 10, 64) if err != nil { - return 0, 0, 0, errUnableToConvertSemver + return 0, 0, 0, ErrUnableToConvertSemver } minor, err := strconv.ParseInt(vParts[1], 10, 64) if err != nil { - return 0, 0, 0, errUnableToConvertSemver + return 0, 0, 0, ErrUnableToConvertSemver } patch, err := strconv.ParseInt(vParts[2], 10, 64) if err != nil { - return 0, 0, 0, errUnableToConvertSemver + return 0, 0, 0, ErrUnableToConvertSemver } return major, minor, patch, nil } @@ -160,9 +160,9 @@ func (s *Semver) Compare(toCompare Semver) int { if s.preRelease[i] == toCompare.preRelease[i] { continue } - if isNumeric(s.preRelease[i]) && isNumeric(toCompare.preRelease[i]) { - preRelease1, _ := strconv.ParseInt(s.preRelease[i], 10, 64) - preRelease2, _ := strconv.ParseInt(s.preRelease[i], 10, 64) + preRelease1, e1 := strconv.ParseInt(s.preRelease[i], 10, 64) + preRelease2, e2 := strconv.ParseInt(s.preRelease[i], 10, 64) + if e1 == nil && e2 == nil { return compareLongs(preRelease1, preRelease2) } return strings.Compare(s.preRelease[i], toCompare.preRelease[i]) @@ -175,14 +175,6 @@ func (s *Semver) Compare(toCompare Semver) int { return compareLongs(int64(sPreReleaseLen), int64(toComparePreReleaseLen)) } -func isNumeric(strNum string) bool { - if len(strNum) == 0 { - return false - } - _, err := strconv.ParseInt(strNum, 10, 64) - return err == nil -} - func compareLongs(compare1 int64, compare2 int64) int { if compare1 == compare2 { return 0 From d44eb59b153fc64d1127273f97b4628a110621a9 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Mon, 6 May 2024 17:06:04 -0300 Subject: [PATCH 25/56] added greaterthanorequal semver --- engine/grammar/matchers/datatypes/semver.go | 7 ++ engine/grammar/matchers/matchers.go | 14 ++++ engine/grammar/matchers/semver_gtoe.go | 55 +++++++++++++++ engine/grammar/matchers/semver_gtoe_test.go | 76 +++++++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 engine/grammar/matchers/semver_gtoe.go create mode 100644 engine/grammar/matchers/semver_gtoe_test.go diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index 1b9060ec..bc9c9018 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -28,6 +28,7 @@ type Semver struct { version string } +// BuildSemver builds a semver object from a version string func BuildSemver(version string) (*Semver, error) { if len(strings.TrimSpace(version)) == 0 { return nil, ErrEmptyVersion @@ -122,6 +123,7 @@ func processComponents(version string) (int64, int64, int64, error) { return major, minor, patch, nil } +// Compare compares two semver versions func (s *Semver) Compare(toCompare Semver) int { if s.version == toCompare.version { return 0 @@ -184,3 +186,8 @@ func compareLongs(compare1 int64, compare2 int64) int { } return 1 } + +// String returns the version string +func (s *Semver) Version() string { + return s.version +} diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 306c61b1..821aa56a 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -347,6 +347,20 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L attributeName, ) + case MatcherTypeGreaterThanOrEqualToSemver: + if dto.String == nil { + return nil, errors.New("Semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") + } + logger.Debug(fmt.Sprintf( + "Building GreaterThanOrEqualToSemverMatcher with negate=%t, semver=%s, attributeName=%v", + dto.Negate, *dto.String, attributeName, + )) + matcher = NewGreaterThanOrEqualToSemverMatcher( + dto.Negate, + *dto.String, + attributeName, + ) + default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver_gtoe.go b/engine/grammar/matchers/semver_gtoe.go new file mode 100644 index 00000000..eb0869b1 --- /dev/null +++ b/engine/grammar/matchers/semver_gtoe.go @@ -0,0 +1,55 @@ +package matchers + +import ( + "fmt" + + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" +) + +// GreaterThanOrEqualToSemverMatcher struct to hold the semver to compare +type GreaterThanOrEqualToSemverMatcher struct { + Matcher + semver datatypes.Semver +} + +// Match compares the semver of the key with the semver in the feature flag +func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + matchingKey, err := g.matchingKey(key, attributes) + if err != nil { + g.logger.Warning(fmt.Sprintf("GreaterThanOrEqualToSemverMatcher: %s", err.Error())) + return false + } + + asString, ok := matchingKey.(string) + if !ok { + g.logger.Error("GreaterThanOrEqualToSemverMatcher: Error type-asserting string") + return false + } + + semver, err := datatypes.BuildSemver(asString) + if err != nil { + g.logger.Error("GreaterThanOrEqualToSemverMatcher: Error parsing semver") + return false + } + + result := semver.Compare(g.semver) >= 0 + fmt.Println("original", g.semver.Version(), "comming", asString, " result ", result, "compare ", semver.Compare(g.semver)) + + g.logger.Debug(fmt.Sprintf("%s >= %s | Result: %t", semver.Version(), g.semver.Version(), result)) + return result +} + +// NewGreaterThanOrEqualToSemverMatcher returns an instance of GreaterThanOrEqualToSemverMatcher +func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attributeName *string) *GreaterThanOrEqualToSemverMatcher { + semver, err := datatypes.BuildSemver(compareTo) + if err != nil { + return nil + } + return &GreaterThanOrEqualToSemverMatcher{ + Matcher: Matcher{ + negate: negate, + attributeName: attributeName, + }, + semver: *semver, + } +} diff --git a/engine/grammar/matchers/semver_gtoe_test.go b/engine/grammar/matchers/semver_gtoe_test.go new file mode 100644 index 00000000..c9f4aa35 --- /dev/null +++ b/engine/grammar/matchers/semver_gtoe_test.go @@ -0,0 +1,76 @@ +package matchers + +import ( + "encoding/csv" + "io" + "os" + "reflect" + "testing" + + "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-toolkit/v5/logging" +) + +type semvers struct { + semver1 string + semver2 string +} + +func parseCSVTwoSemvers(file string) ([]semvers, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + defer f.Close() + + csvr := csv.NewReader(f) + + var results []semvers + for { + row, err := csvr.Read() + if err != nil { + if err == io.EOF { + err = nil + } + return results, err + } + results = append(results, semvers{ + semver1: row[0], + semver2: row[1], + }) + } +} + +func TestGreaterThanOrEqualToSemverMatcher(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + semvers, err := parseCSVTwoSemvers("../../../testdata/valid_semantic_versions.csv") + if err != nil { + t.Error(err) + } + + for _, twoSemvers := range semvers { + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeGreaterThanOrEqualToSemver, + String: &twoSemvers.semver1, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + } + matcherType := reflect.TypeOf(matcher).String() + if matcherType != "*matchers.GreaterThanOrEqualToSemverMatcher" { + t.Errorf("Incorrect matcher constructed. Should be *matchers.GreaterThanOrEqualToSemverMatcher and was %s", matcherType) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = twoSemvers.semver2 + if matcher.Match("asd", attributes, nil) { + t.Error(twoSemvers.semver1, " >= ", twoSemvers.semver2, " should match") + } + } +} From d6cbf4420131dc537ad96b96989fca912e38f6ee Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Mon, 6 May 2024 17:12:16 -0300 Subject: [PATCH 26/56] one file for semvers --- engine/grammar/matchers/{semver_gtoe.go => semver.go} | 0 engine/grammar/matchers/{semver_gtoe_test.go => semver_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename engine/grammar/matchers/{semver_gtoe.go => semver.go} (100%) rename engine/grammar/matchers/{semver_gtoe_test.go => semver_test.go} (100%) diff --git a/engine/grammar/matchers/semver_gtoe.go b/engine/grammar/matchers/semver.go similarity index 100% rename from engine/grammar/matchers/semver_gtoe.go rename to engine/grammar/matchers/semver.go diff --git a/engine/grammar/matchers/semver_gtoe_test.go b/engine/grammar/matchers/semver_test.go similarity index 100% rename from engine/grammar/matchers/semver_gtoe_test.go rename to engine/grammar/matchers/semver_test.go From f1c54d06c375c863bc65ecbfc1132bb584d92fc3 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Mon, 6 May 2024 17:55:10 -0300 Subject: [PATCH 27/56] updates on test for gtoe; --- engine/grammar/matchers/datatypes/semver.go | 4 ++-- engine/grammar/matchers/semver.go | 2 -- testdata/between_semver.csv | 2 +- testdata/equal_to_semver.csv | 2 +- testdata/invalid_semantic_versions.csv | 2 +- testdata/valid_semantic_versions.csv | 1 - 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index bc9c9018..7459daf1 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -163,7 +163,7 @@ func (s *Semver) Compare(toCompare Semver) int { continue } preRelease1, e1 := strconv.ParseInt(s.preRelease[i], 10, 64) - preRelease2, e2 := strconv.ParseInt(s.preRelease[i], 10, 64) + preRelease2, e2 := strconv.ParseInt(toCompare.preRelease[i], 10, 64) if e1 == nil && e2 == nil { return compareLongs(preRelease1, preRelease2) } @@ -187,7 +187,7 @@ func compareLongs(compare1 int64, compare2 int64) int { return 1 } -// String returns the version string +// Version returns the version string func (s *Semver) Version() string { return s.version } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index eb0869b1..dd2db39d 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -33,8 +33,6 @@ func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[str } result := semver.Compare(g.semver) >= 0 - fmt.Println("original", g.semver.Version(), "comming", asString, " result ", result, "compare ", semver.Compare(g.semver)) - g.logger.Debug(fmt.Sprintf("%s >= %s | Result: %t", semver.Version(), g.semver.Version(), result)) return result } diff --git a/testdata/between_semver.csv b/testdata/between_semver.csv index ae7148c0..adeee012 100644 --- a/testdata/between_semver.csv +++ b/testdata/between_semver.csv @@ -11,4 +11,4 @@ 2.0.0,3.0.0,4.0.0 2.2.2,2.2.3-rc1,2.2.3 2.2.2,2.3.2-rc100,2.3.3 -1.0.0-rc.1+build.1,1.2.3-beta,1.2.3-rc.1+build.123 \ No newline at end of file +1.0.0-rc.1+build.1,1.2.3-beta,1.2.3-rc.1+build.123 diff --git a/testdata/equal_to_semver.csv b/testdata/equal_to_semver.csv index 8c680776..e2295d55 100644 --- a/testdata/equal_to_semver.csv +++ b/testdata/equal_to_semver.csv @@ -3,4 +3,4 @@ 1.2.3----RC-SNAPSHOT.12.9.1--.12,1.2.3----RC-SNAPSHOT.12.9.1--.12 00.01.002-0003.00004,0.1.2-3.4 1.1.2-prerelease+meta, 1.1.2-prerelease+meta -1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay, 1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay \ No newline at end of file +1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay, 1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay diff --git a/testdata/invalid_semantic_versions.csv b/testdata/invalid_semantic_versions.csv index 9268df4b..7a22b1c8 100644 --- a/testdata/invalid_semantic_versions.csv +++ b/testdata/invalid_semantic_versions.csv @@ -28,4 +28,4 @@ beta 1.2.31----RC-SNAPSHOT.12.09.1--..12+788 1..1 2.2.2+ - 1.3.4 \ No newline at end of file + 1.3.4 diff --git a/testdata/valid_semantic_versions.csv b/testdata/valid_semantic_versions.csv index d34b5d78..bc8caaa7 100644 --- a/testdata/valid_semantic_versions.csv +++ b/testdata/valid_semantic_versions.csv @@ -18,4 +18,3 @@ 1.2.3----RC-SNAPSHOT.12.9.1--.12.88,1.2.3----RC-SNAPSHOT.12.9.1--.12 9223372036854775807.9223372036854775807.9223372036854775807,9223372036854775807.9223372036854775807.9223372036854775806 1.1.1-alpha.beta.rc.build.java.pr.support.10,1.1.1-alpha.beta.rc.build.java.pr.support -1.0.0-beta+hjadshksh,1.0.0-beta+f \ No newline at end of file From 8dd750c09d457204d784e813e27f2e4c98feddc6 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 09:36:23 -0300 Subject: [PATCH 28/56] Add semver file to track semver matchers --- engine/grammar/matchers/datatypes/semver.go | 7 +- engine/grammar/matchers/equaltosemver.go | 6 - engine/grammar/matchers/matchers.go | 14 +- engine/grammar/matchers/semver.go | 49 ++++++ engine/grammar/matchers/semver_test.go | 164 ++++++++++++++++++++ 5 files changed, 232 insertions(+), 8 deletions(-) delete mode 100644 engine/grammar/matchers/equaltosemver.go create mode 100644 engine/grammar/matchers/semver.go create mode 100644 engine/grammar/matchers/semver_test.go diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index 1b9060ec..a30267a0 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -161,7 +161,7 @@ func (s *Semver) Compare(toCompare Semver) int { continue } preRelease1, e1 := strconv.ParseInt(s.preRelease[i], 10, 64) - preRelease2, e2 := strconv.ParseInt(s.preRelease[i], 10, 64) + preRelease2, e2 := strconv.ParseInt(toCompare.preRelease[i], 10, 64) if e1 == nil && e2 == nil { return compareLongs(preRelease1, preRelease2) } @@ -184,3 +184,8 @@ func compareLongs(compare1 int64, compare2 int64) int { } return 1 } + +// Version returns the version string +func (s *Semver) Version() string { + return s.version +} diff --git a/engine/grammar/matchers/equaltosemver.go b/engine/grammar/matchers/equaltosemver.go deleted file mode 100644 index 6354e341..00000000 --- a/engine/grammar/matchers/equaltosemver.go +++ /dev/null @@ -1,6 +0,0 @@ -package matchers - -type EqualToSemverMatcher struct { - Matcher - ComparisonValue string -} diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 306c61b1..90d6d2ed 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -346,7 +346,19 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L *dto.String, attributeName, ) - + case MatcherEqualToSemver: + if dto.String == nil { + return nil, errors.New("String is required for EQUAL_TO_SEMVER matcher type") + } + logger.Debug(fmt.Sprintf( + "Building SemverMatcher with negate=%t, regex=%s, attributeName=%v", + dto.Negate, *dto.String, attributeName, + )) + matcher = NewEqualToSemverMatcher( + *dto.String, + dto.Negate, + attributeName, + ) default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go new file mode 100644 index 00000000..9674c314 --- /dev/null +++ b/engine/grammar/matchers/semver.go @@ -0,0 +1,49 @@ +package matchers + +import ( + "fmt" + + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" +) + +type EqualToSemverMatcher struct { + Matcher + semver datatypes.Semver +} + +// Match will match if the comparisonValue is equal to the matchingValue +func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + matchingKey, err := e.matchingKey(key, attributes) + if err != nil { + e.logger.Warning(fmt.Sprintf("EqualToSemverMatcher: %s", err.Error())) + return false + } + + asString, ok := matchingKey.(string) + if !ok { + e.logger.Error("EqualToSemverMatcher: Error type-asserting string") + return false + } + + semver, err := datatypes.BuildSemver(asString) + if err != nil { + e.logger.Error("EqualToSemverMatcher: Error parsing semver") + return false + } + + result := semver.Version() == e.semver.Version() + e.logger.Debug(fmt.Sprintf("%s >= %s | Result: %t", semver.Version(), e.semver.Version(), result)) + return result +} + +// NewEqualToSemverMatcher returns a pointer to a new instance of EqualToSemverMatcher +func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *EqualToSemverMatcher { + semver, _ := datatypes.BuildSemver(cmpVal) + return &EqualToSemverMatcher{ + Matcher: Matcher{ + negate: negate, + attributeName: attributeName, + }, + semver: *semver, + } +} diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go new file mode 100644 index 00000000..01cf3850 --- /dev/null +++ b/engine/grammar/matchers/semver_test.go @@ -0,0 +1,164 @@ +package matchers + +import ( + "testing" + + "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-toolkit/v5/logging" +) + +func TestEqualToSemverMatcher(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "1.0.0" + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + t.Error(err) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "1.0.0" + if !matcher.Match("asd", attributes, nil) { + t.Error("Equal should match") + } +} + +func TestPatchDiffers(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "1.0.0" + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + t.Error(err) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "1.0.0" + if matcher.Match("sded", map[string]interface{}{}, nil) { + t.Error("Equal should not match") + } +} + +func TestPreReleaseShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + t.Error(err) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" + if !matcher.Match("ass", attributes, nil) { + t.Error("Equal should match") + } +} + +func TestPreReleaseShouldReturnFalseWhenVersionsDiffer(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + t.Error(err) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "1.2.3----RC-SNAPSHOT.12.9.1--.12.99" + if matcher.Match("asd", attributes, nil) { + t.Error("Equal should not match") + } +} + +func TestMetadataShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "2.2.2-rc.2+metadata-lalala" + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + t.Error(err) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.2.2-rc.2+metadata-lalala" + if !matcher.Match("asd", attributes, nil) { + t.Error("Equal should match") + } +} + +func TestMetadataShouldReturnFalseWhenVersionsDiffer(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "2.2.2-rc.2+metadata-lalala" + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + t.Error(err) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.2.2-rc.2+metadata" + if matcher.Match("asd", attributes, nil) { + t.Error("Equal should not match") + } +} + +func TestShouldReturnErrorWithNilSemver(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := &dtos.MatcherDTO{ + MatcherType: "EQUAL_TO_SEMVER", + String: nil, + } + _, err := BuildMatcher(dto, nil, logger) + if err == nil { + t.Error("There should be errors when building the matcher") + } +} From 017f282736fe707cc28362304b04ae242a60d75a Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 10:52:56 -0300 Subject: [PATCH 29/56] Add less than or equal to semver matcher --- engine/grammar/matchers/matchers.go | 13 ++++ engine/grammar/matchers/semver.go | 42 +++++++++++++ engine/grammar/matchers/semver_test.go | 82 +++++++++++++++++++++++--- testdata/valid_semantic_versions.csv | 3 +- 4 files changed, 131 insertions(+), 9 deletions(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 90d6d2ed..84faa3cc 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -359,6 +359,19 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L dto.Negate, attributeName, ) + case MatcherTypeLessThanOrEqualToSemver: + if dto.String == nil { + return nil, errors.New("String is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type") + } + logger.Debug(fmt.Sprintf( + "Building SemverMatcher with negate=%t, regex=%s, attributeName=%v", + dto.Negate, *dto.String, attributeName, + )) + matcher = NewLessThanOrEqualToSemverMatcher( + *dto.String, + dto.Negate, + attributeName, + ) default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 9674c314..9c7b84cb 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -11,6 +11,11 @@ type EqualToSemverMatcher struct { semver datatypes.Semver } +type LessThanOrEqualToSemverMatcher struct { + Matcher + semver datatypes.Semver +} + // Match will match if the comparisonValue is equal to the matchingValue func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { matchingKey, err := e.matchingKey(key, attributes) @@ -47,3 +52,40 @@ func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) semver: *semver, } } + +// Match will match if the comparisonValue is less or equal to the matchingValue +func (l *LessThanOrEqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + matchingKey, err := l.matchingKey(key, attributes) + if err != nil { + l.logger.Warning(fmt.Sprintf("LessThanOrEqualToSemverMatcher: %s", err.Error())) + return false + } + + asString, ok := matchingKey.(string) + if !ok { + l.logger.Error("LessThanOrEqualToSemverMatcher: Error type-asserting string") + return false + } + + semver, err := datatypes.BuildSemver(asString) + if err != nil { + l.logger.Error("LessThanOrEqualToSemverMatcher: Error parsing semver") + return false + } + + result := semver.Compare(l.semver) <= 0 + l.logger.Debug(fmt.Sprintf("%s >= %s | Result: %t", semver.Version(), l.semver.Version(), result)) + return result +} + +// NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher +func NewLessThanOrEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *LessThanOrEqualToSemverMatcher { + semver, _ := datatypes.BuildSemver(cmpVal) + return &LessThanOrEqualToSemverMatcher{ + Matcher: Matcher{ + negate: negate, + attributeName: attributeName, + }, + semver: *semver, + } +} diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index 01cf3850..2875eade 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -1,18 +1,52 @@ package matchers import ( + "encoding/csv" + "io" + "os" + "reflect" "testing" "github.com/splitio/go-split-commons/v5/dtos" "github.com/splitio/go-toolkit/v5/logging" ) +type semvers struct { + semver1 string + semver2 string +} + +func parseCSVTwoSemvers(file string) ([]semvers, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + defer f.Close() + + csvr := csv.NewReader(f) + + var results []semvers + for { + row, err := csvr.Read() + if err != nil { + if err == io.EOF { + err = nil + } + return results, err + } + results = append(results, semvers{ + semver1: row[0], + semver2: row[1], + }) + } +} + func TestEqualToSemverMatcher(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) attrName := "version" str := "1.0.0" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -36,7 +70,7 @@ func TestPatchDiffers(t *testing.T) { attrName := "version" str := "1.0.0" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -60,7 +94,7 @@ func TestPreReleaseShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { attrName := "version" str := "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -84,7 +118,7 @@ func TestPreReleaseShouldReturnFalseWhenVersionsDiffer(t *testing.T) { attrName := "version" str := "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -108,7 +142,7 @@ func TestMetadataShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { attrName := "version" str := "2.2.2-rc.2+metadata-lalala" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -132,7 +166,7 @@ func TestMetadataShouldReturnFalseWhenVersionsDiffer(t *testing.T) { attrName := "version" str := "2.2.2-rc.2+metadata-lalala" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -154,7 +188,7 @@ func TestMetadataShouldReturnFalseWhenVersionsDiffer(t *testing.T) { func TestShouldReturnErrorWithNilSemver(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: nil, } _, err := BuildMatcher(dto, nil, logger) @@ -162,3 +196,37 @@ func TestShouldReturnErrorWithNilSemver(t *testing.T) { t.Error("There should be errors when building the matcher") } } + +func TestLessThanOrEqualToSemverMatcher(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + semvers, err := parseCSVTwoSemvers("../../../testdata/valid_semantic_versions.csv") + if err != nil { + t.Error(err) + } + + for _, twoSemvers := range semvers { + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeLessThanOrEqualToSemver, + String: &twoSemvers.semver2, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + } + matcherType := reflect.TypeOf(matcher).String() + if matcherType != "*matchers.LessThanOrEqualToSemverMatcher" { + t.Errorf("Incorrect matcher constructed. Should be *matchers.LessThanOrEqualToSemverMatcher and was %s", matcherType) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = twoSemvers.semver1 + if matcher.Match("asd", attributes, nil) { + t.Error(twoSemvers.semver2, " <= ", twoSemvers.semver1, " should match") + } + } +} diff --git a/testdata/valid_semantic_versions.csv b/testdata/valid_semantic_versions.csv index d34b5d78..b7110ab1 100644 --- a/testdata/valid_semantic_versions.csv +++ b/testdata/valid_semantic_versions.csv @@ -17,5 +17,4 @@ 1.1.1-rc2,1.0.0-0A.is.legal 1.2.3----RC-SNAPSHOT.12.9.1--.12.88,1.2.3----RC-SNAPSHOT.12.9.1--.12 9223372036854775807.9223372036854775807.9223372036854775807,9223372036854775807.9223372036854775807.9223372036854775806 -1.1.1-alpha.beta.rc.build.java.pr.support.10,1.1.1-alpha.beta.rc.build.java.pr.support -1.0.0-beta+hjadshksh,1.0.0-beta+f \ No newline at end of file +1.1.1-alpha.beta.rc.build.java.pr.support.10,1.1.1-alpha.beta.rc.build.java.pr.support \ No newline at end of file From 44d2b5e12afe1bd2e1f30ad3730da2294441dd18 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 10:54:31 -0300 Subject: [PATCH 30/56] Updated matchers --- engine/grammar/matchers/matchers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 84faa3cc..ca7cae1e 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -351,7 +351,7 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L return nil, errors.New("String is required for EQUAL_TO_SEMVER matcher type") } logger.Debug(fmt.Sprintf( - "Building SemverMatcher with negate=%t, regex=%s, attributeName=%v", + "Building EqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) matcher = NewEqualToSemverMatcher( @@ -364,7 +364,7 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L return nil, errors.New("String is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type") } logger.Debug(fmt.Sprintf( - "Building SemverMatcher with negate=%t, regex=%s, attributeName=%v", + "Building LessThanOrEqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) matcher = NewLessThanOrEqualToSemverMatcher( From a44cc04adae8d0ca8a810d88593ff0840f290946 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 10:59:02 -0300 Subject: [PATCH 31/56] Update matcher message and semver test --- engine/grammar/matchers/matchers.go | 2 +- engine/grammar/matchers/semver_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 90d6d2ed..0de1cc7a 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -351,7 +351,7 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L return nil, errors.New("String is required for EQUAL_TO_SEMVER matcher type") } logger.Debug(fmt.Sprintf( - "Building SemverMatcher with negate=%t, regex=%s, attributeName=%v", + "Building EqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) matcher = NewEqualToSemverMatcher( diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index 01cf3850..4dcbeebe 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -12,7 +12,7 @@ func TestEqualToSemverMatcher(t *testing.T) { attrName := "version" str := "1.0.0" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -36,7 +36,7 @@ func TestPatchDiffers(t *testing.T) { attrName := "version" str := "1.0.0" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -60,7 +60,7 @@ func TestPreReleaseShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { attrName := "version" str := "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -84,7 +84,7 @@ func TestPreReleaseShouldReturnFalseWhenVersionsDiffer(t *testing.T) { attrName := "version" str := "1.2.3----RC-SNAPSHOT.12.9.1--.12.88" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -108,7 +108,7 @@ func TestMetadataShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { attrName := "version" str := "2.2.2-rc.2+metadata-lalala" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -132,7 +132,7 @@ func TestMetadataShouldReturnFalseWhenVersionsDiffer(t *testing.T) { attrName := "version" str := "2.2.2-rc.2+metadata-lalala" dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: &str, KeySelector: &dtos.KeySelectorDTO{ Attribute: &attrName, @@ -154,7 +154,7 @@ func TestMetadataShouldReturnFalseWhenVersionsDiffer(t *testing.T) { func TestShouldReturnErrorWithNilSemver(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) dto := &dtos.MatcherDTO{ - MatcherType: "EQUAL_TO_SEMVER", + MatcherType: MatcherEqualToSemver, String: nil, } _, err := BuildMatcher(dto, nil, logger) From 1a170c7840fde2c6e3555d4c212868c8c39f1b25 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 7 May 2024 11:37:27 -0300 Subject: [PATCH 32/56] added err var --- engine/grammar/matchers/matchers.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 821aa56a..58f9e806 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -10,6 +10,8 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) +var ErrInvalidGTOESemver = errors.New("semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") + const ( // MatcherTypeAllKeys string value MatcherTypeAllKeys = "ALL_KEYS" @@ -349,7 +351,7 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L case MatcherTypeGreaterThanOrEqualToSemver: if dto.String == nil { - return nil, errors.New("Semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") + return nil, ErrInvalidGTOESemver } logger.Debug(fmt.Sprintf( "Building GreaterThanOrEqualToSemverMatcher with negate=%t, semver=%s, attributeName=%v", From fc24246a62f12380b1449368a3b1c377f362eb34 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 11:39:28 -0300 Subject: [PATCH 33/56] WIP beteewn semver matcher --- engine/grammar/matchers/semver.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 9c7b84cb..4afea53a 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -16,6 +16,12 @@ type LessThanOrEqualToSemverMatcher struct { semver datatypes.Semver } +type BetweenSemverMatcher struct { + Matcher + startSemver datatypes.Semver + endSemver datatypes.Semver +} + // Match will match if the comparisonValue is equal to the matchingValue func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { matchingKey, err := e.matchingKey(key, attributes) @@ -89,3 +95,17 @@ func NewLessThanOrEqualToSemverMatcher(cmpVal string, negate bool, attributeName semver: *semver, } } + +// NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher +func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string) *BetweenSemverMatcher { + startSemver, _ := datatypes.BuildSemver(startVal) + endSemver, _ := datatypes.BuildSemver(endVal) + return &BetweenSemverMatcher{ + Matcher: Matcher{ + negate: negate, + attributeName: attributeName, + }, + startSemver: *startSemver, + endSemver: *endSemver, + } +} From 01953a263fe75af01f9c3c0a0e363ac4a6e2edcb Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 12:22:55 -0300 Subject: [PATCH 34/56] Update semver and add logs --- engine/grammar/matchers/matchers.go | 3 ++- engine/grammar/matchers/semver.go | 36 ++++++++++++++--------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index eb655c79..3e3ffd7d 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -10,6 +10,7 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) +var ErrInvalidEqualSemver = errors.New("semver is required for EQUAL_TO_SEMVER matcher type") var ErrInvalidGTOESemver = errors.New("semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") const ( @@ -350,7 +351,7 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L ) case MatcherEqualToSemver: if dto.String == nil { - return nil, errors.New("String is required for EQUAL_TO_SEMVER matcher type") + return nil, ErrInvalidEqualSemver } logger.Debug(fmt.Sprintf( "Building EqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 19be3011..02d9958f 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -12,12 +12,6 @@ type EqualToSemverMatcher struct { semver datatypes.Semver } -// GreaterThanOrEqualToSemverMatcher struct to hold the semver to compare -type GreaterThanOrEqualToSemverMatcher struct { - Matcher - semver datatypes.Semver -} - // Match will match if the comparisonValue is equal to the matchingValue func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { matchingKey, err := e.matchingKey(key, attributes) @@ -43,6 +37,24 @@ func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface return result } +// NewEqualToSemverMatcher returns a pointer to a new instance of EqualToSemverMatcher +func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *EqualToSemverMatcher { + semver, _ := datatypes.BuildSemver(cmpVal) + return &EqualToSemverMatcher{ + Matcher: Matcher{ + negate: negate, + attributeName: attributeName, + }, + semver: *semver, + } +} + +// GreaterThanOrEqualToSemverMatcher struct to hold the semver to compare +type GreaterThanOrEqualToSemverMatcher struct { + Matcher + semver datatypes.Semver +} + // Match compares the semver of the key with the semver in the feature flag func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { matchingKey, err := g.matchingKey(key, attributes) @@ -68,18 +80,6 @@ func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[str return result } -// NewEqualToSemverMatcher returns a pointer to a new instance of EqualToSemverMatcher -func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *EqualToSemverMatcher { - semver, _ := datatypes.BuildSemver(cmpVal) - return &EqualToSemverMatcher{ - Matcher: Matcher{ - negate: negate, - attributeName: attributeName, - }, - semver: *semver, - } -} - // NewGreaterThanOrEqualToSemverMatcher returns an instance of GreaterThanOrEqualToSemverMatcher func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attributeName *string) *GreaterThanOrEqualToSemverMatcher { semver, err := datatypes.BuildSemver(compareTo) From a0eee06e6889c0a16b82d470a736819f9e4874f0 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 12:27:45 -0300 Subject: [PATCH 35/56] Update with equal to semver --- engine/grammar/matchers/matchers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 78584fed..77a18ca4 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -12,6 +12,7 @@ import ( var ErrInvalidEqualSemver = errors.New("semver is required for EQUAL_TO_SEMVER matcher type") var ErrInvalidGTOESemver = errors.New("semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") +var ErrInvalidLTOESemver = errors.New("semver is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type") const ( // MatcherTypeAllKeys string value @@ -377,7 +378,7 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L ) case MatcherTypeLessThanOrEqualToSemver: if dto.String == nil { - return nil, errors.New("String is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type") + return nil, ErrInvalidLTOESemver } logger.Debug(fmt.Sprintf( "Building LessThanOrEqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", From 1ce7836e59275665ff707c59f28272c549536a19 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 12:47:04 -0300 Subject: [PATCH 36/56] Update test cases --- engine/grammar/matchers/semver.go | 9 ++++++--- engine/grammar/matchers/semver_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 722ff1e2..b0b05d08 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -39,7 +39,10 @@ func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface // NewEqualToSemverMatcher returns a pointer to a new instance of EqualToSemverMatcher func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *EqualToSemverMatcher { - semver, _ := datatypes.BuildSemver(cmpVal) + semver, err := datatypes.BuildSemver(cmpVal) + if err != nil { + return nil + } return &EqualToSemverMatcher{ Matcher: Matcher{ negate: negate, @@ -127,8 +130,8 @@ func (l *LessThanOrEqualToSemverMatcher) Match(key string, attributes map[string } // NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher -func NewLessThanOrEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *LessThanOrEqualToSemverMatcher { - semver, err := datatypes.BuildSemver(cmpVal) +func NewLessThanOrEqualToSemverMatcher(compareTo string, negate bool, attributeName *string) *LessThanOrEqualToSemverMatcher { + semver, err := datatypes.BuildSemver(compareTo) if err != nil { return nil } diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index 42d3e12d..27486656 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -264,3 +264,15 @@ func TestLessThanOrEqualToSemverMatcher(t *testing.T) { } } } + +func TestLessThanOrEqualToSemverMatcherWithInvalidSemver(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeLessThanOrEqualToSemver, + String: nil, + } + _, err := BuildMatcher(dto, nil, logger) + if err == nil { + t.Error("There should be errors when building the matcher") + } +} From 848bfe0c8d553d80478daa203689e4642b3db649 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 16:02:14 -0300 Subject: [PATCH 37/56] Add Between semver --- dtos/split.go | 7 +++ engine/grammar/matchers/matchers.go | 15 +++++ engine/grammar/matchers/semver.go | 35 +++++++++++- engine/grammar/matchers/semver_test.go | 79 ++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 2 deletions(-) diff --git a/dtos/split.go b/dtos/split.go index 10a7e532..af35ad8b 100644 --- a/dtos/split.go +++ b/dtos/split.go @@ -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"` @@ -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 diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 77a18ca4..54cd6b28 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -13,6 +13,7 @@ import ( var ErrInvalidEqualSemver = errors.New("semver is required for EQUAL_TO_SEMVER matcher type") var ErrInvalidGTOESemver = errors.New("semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") var ErrInvalidLTOESemver = errors.New("semver is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type") +var ErrInvalidLBetweenSemver = errors.New("semver is required for BETWEEN_SEMVER matcher type") const ( // MatcherTypeAllKeys string value @@ -389,6 +390,20 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L dto.Negate, attributeName, ) + case MatcherTypeBetweenSemver: + if dto.BetweenString.Start == nil || dto.BetweenString.End == nil { + return nil, ErrInvalidLBetweenSemver + } + logger.Debug(fmt.Sprintf( + "Building BetweenSemverMatcher with negate=%t, regexStart=%s, regexEnd=%s, attributeName=%v", + dto.Negate, *dto.BetweenString.Start, *dto.BetweenString.End, attributeName, + )) + matcher = NewBetweenSemverMatcher( + *dto.BetweenString.Start, + *dto.BetweenString.End, + dto.Negate, + attributeName, + ) default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 2b7dc399..571aad47 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -151,10 +151,41 @@ type BetweenSemverMatcher struct { endSemver datatypes.Semver } +// Match will match if the comparisonValue is less or equal to the matchingValue +func (b *BetweenSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + matchingKey, err := b.matchingKey(key, attributes) + if err != nil { + b.logger.Warning(fmt.Sprintf("BetweenSemverMatcher: %s", err.Error())) + return false + } + + asString, ok := matchingKey.(string) + if !ok { + b.logger.Error("BetweenSemverMatcher: Error type-asserting string") + return false + } + + semver, err := datatypes.BuildSemver(asString) + if err != nil { + b.logger.Error("BetweenSemverMatcher: Error parsing semver") + return false + } + + result := semver.Compare(b.startSemver) >= 0 && semver.Compare(b.endSemver) <= 0 + b.logger.Debug(fmt.Sprintf("%s between %s and %s | Result: %t", semver.Version(), b.startSemver.Version(), b.endSemver.Version(), result)) + return result +} + // NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string) *BetweenSemverMatcher { - startSemver, _ := datatypes.BuildSemver(startVal) - endSemver, _ := datatypes.BuildSemver(endVal) + startSemver, err := datatypes.BuildSemver(startVal) + if err != nil { + return nil + } + endSemver, err := datatypes.BuildSemver(endVal) + if err != nil { + return nil + } return &BetweenSemverMatcher{ Matcher: Matcher{ negate: negate, diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index 27486656..ea2c4eee 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -14,6 +14,7 @@ import ( type semvers struct { semver1 string semver2 string + semver3 string } func parseCSVTwoSemvers(file string) ([]semvers, error) { @@ -41,6 +42,32 @@ func parseCSVTwoSemvers(file string) ([]semvers, error) { } } +func parseCSVThreeSemvers(file string) ([]semvers, error) { + f, err := os.Open(file) + if err != nil { + return nil, err + } + defer f.Close() + + csvr := csv.NewReader(f) + + var results []semvers + for { + row, err := csvr.Read() + if err != nil { + if err == io.EOF { + err = nil + } + return results, err + } + results = append(results, semvers{ + semver1: row[0], + semver2: row[1], + semver3: row[2], + }) + } +} + func TestEqualToSemverMatcher(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) attrName := "version" @@ -276,3 +303,55 @@ func TestLessThanOrEqualToSemverMatcherWithInvalidSemver(t *testing.T) { t.Error("There should be errors when building the matcher") } } + +func TestBetweenSemverMatcher(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + semvers, err := parseCSVThreeSemvers("../../../testdata/between_semver.csv") + if err != nil { + t.Error(err) + } + + for _, threeSemvers := range semvers { + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeBetweenSemver, + BetweenString: &dtos.BetweenStringMatcherDataDTO{ + Start: &threeSemvers.semver1, + End: &threeSemvers.semver3, + }, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + } + matcherType := reflect.TypeOf(matcher).String() + + if matcherType != "*matchers.BetweenSemverMatcher" { + t.Errorf("Incorrect matcher constructed. Should be *matchers.BetweenSemverMatcher and was %s", matcherType) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = threeSemvers.semver2 + if !matcher.Match("asd", attributes, nil) { + t.Error(threeSemvers.semver2, " between ", threeSemvers.semver1, "and", threeSemvers.semver3, " should match") + } + } +} + +func TestBetweenSemverWithInvalidSemvers(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeLessThanOrEqualToSemver, + BetweenString: &dtos.BetweenStringMatcherDataDTO{ + Start: nil, + End: nil, + }, + } + _, err := BuildMatcher(dto, nil, logger) + if err == nil { + t.Error("There should be errors when building the matcher") + } +} From 7a0e698a8e55e8a57628b99b9b9769c12bb52c0d Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 17:28:35 -0300 Subject: [PATCH 38/56] Add in list semver --- engine/grammar/matchers/matchers.go | 14 +++++ engine/grammar/matchers/semver.go | 60 ++++++++++++++++++++- engine/grammar/matchers/semver_test.go | 74 ++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 2 deletions(-) diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 54cd6b28..3653604c 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -14,6 +14,7 @@ var ErrInvalidEqualSemver = errors.New("semver is required for EQUAL_TO_SEMVER m var ErrInvalidGTOESemver = errors.New("semver is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type") var ErrInvalidLTOESemver = errors.New("semver is required for LESS_THAN_OR_EQUAL_TO_SEMVER matcher type") var ErrInvalidLBetweenSemver = errors.New("semver is required for BETWEEN_SEMVER matcher type") +var ErrInvalidLInListSemver = errors.New("semver is required for IN_LIST_SEMVER matcher type") const ( // MatcherTypeAllKeys string value @@ -404,6 +405,19 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L dto.Negate, attributeName, ) + case MatcherTypeInListSemver: + if dto.Whitelist == nil { + return nil, ErrInvalidLInListSemver + } + logger.Debug(fmt.Sprintf( + "Building ErrInvalidLInListSemver with negate=%t, regex=%v, attributeName=%v", + dto.Negate, dto.Whitelist.Whitelist, attributeName, + )) + matcher = NewInListSemverMatcher( + dto.Whitelist.Whitelist, + dto.Negate, + attributeName, + ) default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 571aad47..ef026c6e 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -151,7 +151,7 @@ type BetweenSemverMatcher struct { endSemver datatypes.Semver } -// Match will match if the comparisonValue is less or equal to the matchingValue +// Match will match if the comparisonValue is between to the matchingValue func (b *BetweenSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { matchingKey, err := b.matchingKey(key, attributes) if err != nil { @@ -176,7 +176,7 @@ func (b *BetweenSemverMatcher) Match(key string, attributes map[string]interface return result } -// NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher +// NewBetweenSemverMatcher returns a pointer to a new instance of BetweenSemverMatcher func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string) *BetweenSemverMatcher { startSemver, err := datatypes.BuildSemver(startVal) if err != nil { @@ -195,3 +195,59 @@ func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attrib endSemver: *endSemver, } } + +// InListSemverMatcher struct to hold the semver to compare +type InListSemverMatcher struct { + Matcher + semvers []datatypes.Semver +} + +// Match will match if the comparisonValue is in list to the matchingValue +func (i *InListSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + matchingKey, err := i.matchingKey(key, attributes) + if err != nil { + i.logger.Warning(fmt.Sprintf("InListSemverMatcher: %s", err.Error())) + return false + } + + asString, ok := matchingKey.(string) + if !ok { + i.logger.Error("InListSemverMatcher: Error type-asserting string") + return false + } + + semver, err := datatypes.BuildSemver(asString) + if err != nil { + i.logger.Error("InListSemverMatcher: Error parsing semver") + return false + } + + for _, semsemver := range i.semvers { + result := semsemver.Version() == semver.Version() + if result { + i.logger.Debug(fmt.Sprintf("%s in list | Result: %t", semver.Version(), result)) + return result + } + + } + i.logger.Debug(fmt.Sprintf("%s in list | Result: %t", semver.Version(), false)) + return false +} + +// NewInListSemverMatcher returns a pointer to a new instance of InListSemverMatcher +func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string) *InListSemverMatcher { + semvers := make([]datatypes.Semver, 0, len(cmpList)) + for _, str := range cmpList { + semver, err := datatypes.BuildSemver(str) + if err == nil { + semvers = append(semvers, *semver) + } + } + return &InListSemverMatcher{ + Matcher: Matcher{ + negate: negate, + attributeName: attributeName, + }, + semvers: semvers, + } +} diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index ea2c4eee..ebb96901 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -355,3 +355,77 @@ func TestBetweenSemverWithInvalidSemvers(t *testing.T) { t.Error("There should be errors when building the matcher") } } + +func TestInListSemvers(t *testing.T) { + semvers := make([]string, 0, 3) + semvers = append(semvers, "1.0.0-rc.1") + semvers = append(semvers, "2.2.2-rc.1.2") + semvers = append(semvers, "1.1.2-prerelease+meta") + attrName := "version" + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := &dtos.MatcherDTO{ + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + MatcherType: MatcherTypeInListSemver, + Whitelist: &dtos.WhitelistMatcherDataDTO{Whitelist: semvers}, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + } + matcherType := reflect.TypeOf(matcher).String() + + if matcherType != "*matchers.InListSemverMatcher" { + t.Errorf("Incorrect matcher constructed. Should be *matchers.InListSemverMatcher and was %s", matcherType) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.2.2-rc.1.2" + if !matcher.Match("asd", attributes, nil) { + t.Error("2.2.2-rc.1.2", " in list ", semvers, " should match") + } +} + +func TestInListSemversNotMatch(t *testing.T) { + semvers := make([]string, 0, 3) + semvers = append(semvers, "1.0.0-rc.1") + semvers = append(semvers, "2.2.2-rc.1.2") + semvers = append(semvers, "1.1.2-prerelease+meta") + attrName := "version" + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := &dtos.MatcherDTO{ + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + MatcherType: MatcherTypeInListSemver, + Whitelist: &dtos.WhitelistMatcherDataDTO{Whitelist: semvers}, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + } + matcherType := reflect.TypeOf(matcher).String() + + if matcherType != "*matchers.InListSemverMatcher" { + t.Errorf("Incorrect matcher constructed. Should be *matchers.InListSemverMatcher and was %s", matcherType) + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.2.2" + if matcher.Match("asd", attributes, nil) { + t.Error("2.2.2-rc.1.2", " in list ", semvers, " should not match") + } +} + +func TestInListInvalidSemvers(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeLessThanOrEqualToSemver, + Whitelist: &dtos.WhitelistMatcherDataDTO{Whitelist: nil}, + } + _, err := BuildMatcher(dto, nil, logger) + if err == nil { + t.Error("There should be errors when building the matcher") + } +} From 5cdd9354559d41cfb4f654828ea71260bd8d25ed Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 7 May 2024 17:48:25 -0300 Subject: [PATCH 39/56] Use set.ThreadUnsafeSet for in list, pr suggestion --- engine/grammar/matchers/semver.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index ef026c6e..3846ff34 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "github.com/splitio/go-toolkit/v5/datastructures/set" ) // EqualToSemverMatcher struct to hold the semver to compare @@ -199,7 +200,7 @@ func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attrib // InListSemverMatcher struct to hold the semver to compare type InListSemverMatcher struct { Matcher - semvers []datatypes.Semver + semvers *set.ThreadUnsafeSet } // Match will match if the comparisonValue is in list to the matchingValue @@ -221,26 +222,16 @@ func (i *InListSemverMatcher) Match(key string, attributes map[string]interface{ i.logger.Error("InListSemverMatcher: Error parsing semver") return false } - - for _, semsemver := range i.semvers { - result := semsemver.Version() == semver.Version() - if result { - i.logger.Debug(fmt.Sprintf("%s in list | Result: %t", semver.Version(), result)) - return result - } - - } - i.logger.Debug(fmt.Sprintf("%s in list | Result: %t", semver.Version(), false)) - return false + return i.semvers.Has(semver.Version()) } // NewInListSemverMatcher returns a pointer to a new instance of InListSemverMatcher func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string) *InListSemverMatcher { - semvers := make([]datatypes.Semver, 0, len(cmpList)) + semvers := set.NewSet() for _, str := range cmpList { semver, err := datatypes.BuildSemver(str) if err == nil { - semvers = append(semvers, *semver) + semvers.Add(semver.Version()) } } return &InListSemverMatcher{ From 2bb3312b49d8395bc9b55be31d0f353c89af950e Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Wed, 8 May 2024 11:43:55 -0300 Subject: [PATCH 40/56] Add semver validation errors and update semver to build version --- engine/grammar/matchers/datatypes/semver.go | 20 ++++++++++- .../grammar/matchers/datatypes/semver_test.go | 10 ++++++ .../matchers/datatypes/semvererrors.go | 11 ++++++ engine/grammar/matchers/matchers.go | 35 ++++++++++++++++--- engine/grammar/matchers/semver.go | 33 +++++++++-------- engine/grammar/matchers/semver_test.go | 30 ++++++++++++++++ 6 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 engine/grammar/matchers/datatypes/semvererrors.go diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index 7459daf1..238294a5 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -46,9 +46,10 @@ func BuildSemver(version string) (*Semver, error) { return nil, err } + version, preReleaseClean := processVersion(major, minor, patch, preRelease, metadata) return &Semver{ metadata: metadata, - preRelease: preRelease, + preRelease: preReleaseClean, major: major, minor: minor, patch: patch, @@ -123,6 +124,23 @@ func processComponents(version string) (int64, int64, int64, error) { return major, minor, patch, nil } +func processVersion(major int64, minor int64, patch int64, preRelease []string, metadata string) (string, []string) { + toReturnVersion := strconv.FormatInt(major, 10) + valueDelimiter + strconv.FormatInt(minor, 10) + valueDelimiter + strconv.FormatInt(patch, 10) + if len(preRelease) != 0 { + for i, _ := range preRelease { + preReleaseNumeric, err := strconv.ParseInt(preRelease[i], 10, 64) + if err == nil { + preRelease[i] = strconv.FormatInt(preReleaseNumeric, 10) + } + } + toReturnVersion = toReturnVersion + preReleaseDelimiter + strings.Join(preRelease, valueDelimiter) + } + if len(metadata) != 0 { + toReturnVersion = toReturnVersion + metadataDelimiter + metadata + } + return toReturnVersion, preRelease +} + // Compare compares two semver versions func (s *Semver) Compare(toCompare Semver) int { if s.version == toCompare.version { diff --git a/engine/grammar/matchers/datatypes/semver_test.go b/engine/grammar/matchers/datatypes/semver_test.go index b5fd8fa7..39019bc1 100644 --- a/engine/grammar/matchers/datatypes/semver_test.go +++ b/engine/grammar/matchers/datatypes/semver_test.go @@ -105,6 +105,16 @@ func TestBetween(t *testing.T) { } } +func TestGetVersion(t *testing.T) { + semver, err := BuildSemver("02.03.04-02.04") + if err != nil { + t.Error("should create semver1") + } + if semver.Version() != "2.3.4-2.4" { + t.Error("semver should build 2.3.4-2.4") + } +} + func parseCSVOneSemver(file string) ([]string, error) { f, err := os.Open(file) if err != nil { diff --git a/engine/grammar/matchers/datatypes/semvererrors.go b/engine/grammar/matchers/datatypes/semvererrors.go new file mode 100644 index 00000000..56553f02 --- /dev/null +++ b/engine/grammar/matchers/datatypes/semvererrors.go @@ -0,0 +1,11 @@ +package datatypes + +// SemverValidatonError represents a semver validaton error +type SemverValidatonError struct { + Message string +} + +// Error implements golang error interface +func (f SemverValidatonError) Error() string { + return f.Message +} diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 3653604c..63793450 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" @@ -360,11 +361,15 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building EqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) - matcher = NewEqualToSemverMatcher( + matcherSemver, err := NewEqualToSemverMatcher( *dto.String, dto.Negate, attributeName, ) + if err != nil { + return nil, err + } + matcher = matcherSemver case MatcherTypeGreaterThanOrEqualToSemver: if dto.String == nil { return nil, ErrInvalidGTOESemver @@ -373,11 +378,15 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building GreaterThanOrEqualToSemverMatcher with negate=%t, semver=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) - matcher = NewGreaterThanOrEqualToSemverMatcher( + matcherSemver, err := NewGreaterThanOrEqualToSemverMatcher( dto.Negate, *dto.String, attributeName, ) + if err != nil { + return nil, err + } + matcher = matcherSemver case MatcherTypeLessThanOrEqualToSemver: if dto.String == nil { return nil, ErrInvalidLTOESemver @@ -386,11 +395,15 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building LessThanOrEqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) - matcher = NewLessThanOrEqualToSemverMatcher( + matcherSemver, err := NewLessThanOrEqualToSemverMatcher( *dto.String, dto.Negate, attributeName, ) + if err != nil { + return nil, err + } + matcher = matcherSemver case MatcherTypeBetweenSemver: if dto.BetweenString.Start == nil || dto.BetweenString.End == nil { return nil, ErrInvalidLBetweenSemver @@ -399,12 +412,16 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building BetweenSemverMatcher with negate=%t, regexStart=%s, regexEnd=%s, attributeName=%v", dto.Negate, *dto.BetweenString.Start, *dto.BetweenString.End, attributeName, )) - matcher = NewBetweenSemverMatcher( + matcherSemver, err := NewBetweenSemverMatcher( *dto.BetweenString.Start, *dto.BetweenString.End, dto.Negate, attributeName, ) + if err != nil { + return nil, err + } + matcher = matcherSemver case MatcherTypeInListSemver: if dto.Whitelist == nil { return nil, ErrInvalidLInListSemver @@ -413,11 +430,19 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building ErrInvalidLInListSemver with negate=%t, regex=%v, attributeName=%v", dto.Negate, dto.Whitelist.Whitelist, attributeName, )) - matcher = NewInListSemverMatcher( + matcherSemver, warnings := NewInListSemverMatcher( dto.Whitelist.Whitelist, dto.Negate, attributeName, ) + if len(warnings) != 0 { + for _, err := range warnings { + if errType, ok := err.(datatypes.SemverValidatonError); ok { + logger.Warning(errType.Message) + } + } + } + matcher = matcherSemver default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 3846ff34..bb5680f2 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -39,10 +39,10 @@ func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface } // NewEqualToSemverMatcher returns a pointer to a new instance of EqualToSemverMatcher -func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) *EqualToSemverMatcher { +func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) (*EqualToSemverMatcher, error) { semver, err := datatypes.BuildSemver(cmpVal) if err != nil { - return nil + return nil, err } return &EqualToSemverMatcher{ Matcher: Matcher{ @@ -50,7 +50,7 @@ func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) attributeName: attributeName, }, semver: *semver, - } + }, nil } // GreaterThanOrEqualToSemverMatcher struct to hold the semver to compare @@ -85,10 +85,10 @@ func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[str } // NewGreaterThanOrEqualToSemverMatcher returns an instance of GreaterThanOrEqualToSemverMatcher -func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attributeName *string) *GreaterThanOrEqualToSemverMatcher { +func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attributeName *string) (*GreaterThanOrEqualToSemverMatcher, error) { semver, err := datatypes.BuildSemver(compareTo) if err != nil { - return nil + return nil, err } return &GreaterThanOrEqualToSemverMatcher{ Matcher: Matcher{ @@ -96,7 +96,7 @@ func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attribu attributeName: attributeName, }, semver: *semver, - } + }, nil } // LessThanOrEqualToSemverMatcher struct to hold the semver to compare @@ -131,10 +131,10 @@ func (l *LessThanOrEqualToSemverMatcher) Match(key string, attributes map[string } // NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher -func NewLessThanOrEqualToSemverMatcher(compareTo string, negate bool, attributeName *string) *LessThanOrEqualToSemverMatcher { +func NewLessThanOrEqualToSemverMatcher(compareTo string, negate bool, attributeName *string) (*LessThanOrEqualToSemverMatcher, error) { semver, err := datatypes.BuildSemver(compareTo) if err != nil { - return nil + return nil, err } return &LessThanOrEqualToSemverMatcher{ Matcher: Matcher{ @@ -142,7 +142,7 @@ func NewLessThanOrEqualToSemverMatcher(compareTo string, negate bool, attributeN attributeName: attributeName, }, semver: *semver, - } + }, nil } // BetweenSemverMatcher struct to hold the semver to compare @@ -178,14 +178,14 @@ func (b *BetweenSemverMatcher) Match(key string, attributes map[string]interface } // NewBetweenSemverMatcher returns a pointer to a new instance of BetweenSemverMatcher -func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string) *BetweenSemverMatcher { +func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string) (*BetweenSemverMatcher, error) { startSemver, err := datatypes.BuildSemver(startVal) if err != nil { - return nil + return nil, err } endSemver, err := datatypes.BuildSemver(endVal) if err != nil { - return nil + return nil, err } return &BetweenSemverMatcher{ Matcher: Matcher{ @@ -194,7 +194,7 @@ func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attrib }, startSemver: *startSemver, endSemver: *endSemver, - } + }, nil } // InListSemverMatcher struct to hold the semver to compare @@ -226,12 +226,15 @@ func (i *InListSemverMatcher) Match(key string, attributes map[string]interface{ } // NewInListSemverMatcher returns a pointer to a new instance of InListSemverMatcher -func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string) *InListSemverMatcher { +func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string) (*InListSemverMatcher, []error) { semvers := set.NewSet() + var errs []error for _, str := range cmpList { semver, err := datatypes.BuildSemver(str) if err == nil { semvers.Add(semver.Version()) + } else { + errs = append(errs, err) } } return &InListSemverMatcher{ @@ -240,5 +243,5 @@ func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string attributeName: attributeName, }, semvers: semvers, - } + }, errs } diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index ebb96901..e556ff6e 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -428,4 +428,34 @@ func TestInListInvalidSemvers(t *testing.T) { if err == nil { t.Error("There should be errors when building the matcher") } + + semvers := make([]string, 0, 3) + semvers = append(semvers, "1.alpha.2") + semvers = append(semvers, "alpha.beta.1") + semvers = append(semvers, "1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788") + dto = &dtos.MatcherDTO{ + MatcherType: MatcherTypeLessThanOrEqualToSemver, + Whitelist: &dtos.WhitelistMatcherDataDTO{Whitelist: semvers}, + } + _, err = BuildMatcher(dto, nil, logger) + if err == nil { + t.Error("There should be errors when building the matcher") + } +} + +func TestNewInListMatcherInvalidSemvers(t *testing.T) { + semvers := make([]string, 0, 3) + semvers = append(semvers, "1.alpha.2") + semvers = append(semvers, "alpha.beta.1") + semvers = append(semvers, "1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788") + attrName := "version" + _, warnings := NewInListSemverMatcher( + semvers, + false, + &attrName, + ) + + if len(warnings) != 3 { + t.Error("There should be warnings when building the matcher") + } } From f8fa3cb4eb827734feb91bb52e1254336e43102e Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Wed, 8 May 2024 12:05:22 -0300 Subject: [PATCH 41/56] added unsupported improvements --- engine/validator/matchers.go | 21 ++++++++++++++------- engine/validator/matchers_test.go | 13 +++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 8a47f77e..2c18eecd 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -11,12 +11,18 @@ import ( ) // OverrideWithUnsupported overrides the split with an unsupported matcher type -func OverrideWithUnsupported(split *dtos.SplitDTO, idx int, jdx int) { - split.Conditions[idx].ConditionType = grammar.ConditionTypeWhitelist - split.Conditions[idx].MatcherGroup.Matchers[jdx].MatcherType = matchers.MatcherTypeAllKeys - split.Conditions[idx].MatcherGroup.Matchers[jdx].String = nil - split.Conditions[idx].Label = impressionlabels.UnsupportedMatcherType - split.Conditions[idx].Partitions = []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}} +func OverrideWithUnsupported() dtos.ConditionDTO { + return dtos.ConditionDTO{ + ConditionType: grammar.ConditionTypeWhitelist, + Label: impressionlabels.UnsupportedMatcherType, + Partitions: []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Combiner: "AND", + Matchers: []dtos.MatcherDTO{{ + MatcherType: matchers.MatcherTypeAllKeys, + }}, + }, + } } // ProcessMatchers processes the matchers of a split and validates them @@ -25,8 +31,9 @@ func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) { for jdx := range split.Conditions[idx].MatcherGroup.Matchers { _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, logger) if err != nil { - OverrideWithUnsupported(split, idx, jdx) + split.Conditions = []dtos.ConditionDTO{OverrideWithUnsupported()} } + return } } } diff --git a/engine/validator/matchers_test.go b/engine/validator/matchers_test.go index 709c0ef7..01cbd992 100644 --- a/engine/validator/matchers_test.go +++ b/engine/validator/matchers_test.go @@ -6,12 +6,22 @@ import ( "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-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) func TestProcessMatchers(t *testing.T) { split := &dtos.SplitDTO{ Conditions: []dtos.ConditionDTO{ + { + ConditionType: grammar.ConditionTypeRollout, + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Matchers: []dtos.MatcherDTO{ + {MatcherType: matchers.MatcherTypeEndsWith, KeySelector: nil, String: common.StringRef("test")}, + }, + }, + }, { ConditionType: "NEW_MATCHER", Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, @@ -24,6 +34,9 @@ func TestProcessMatchers(t *testing.T) { }, } ProcessMatchers(split, logging.NewLogger(nil)) + if len(split.Conditions) != 1 { + t.Error("Conditions should have been overridden") + } if split.Conditions[0].ConditionType != grammar.ConditionTypeWhitelist { t.Error("ConditionType should be WHITELIST") } From a002876fb1d344d56377cc37187e94701839e647 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Thu, 9 May 2024 17:18:40 -0300 Subject: [PATCH 42/56] Apply changes in new matchers to return a matcher with a nil semver --- engine/grammar/matchers/datatypes/semver.go | 20 +++-- .../matchers/datatypes/semvererrors.go | 11 --- engine/grammar/matchers/matchers.go | 40 +++------- engine/grammar/matchers/semver.go | 76 +++++++++++-------- engine/grammar/matchers/semver_test.go | 17 ----- 5 files changed, 67 insertions(+), 97 deletions(-) delete mode 100644 engine/grammar/matchers/datatypes/semvererrors.go diff --git a/engine/grammar/matchers/datatypes/semver.go b/engine/grammar/matchers/datatypes/semver.go index 238294a5..68710c06 100644 --- a/engine/grammar/matchers/datatypes/semver.go +++ b/engine/grammar/matchers/datatypes/semver.go @@ -2,6 +2,7 @@ package datatypes import ( "errors" + "fmt" "strconv" "strings" @@ -46,10 +47,10 @@ func BuildSemver(version string) (*Semver, error) { return nil, err } - version, preReleaseClean := processVersion(major, minor, patch, preRelease, metadata) + version, preRelease = processVersion(major, minor, patch, preRelease, metadata) return &Semver{ metadata: metadata, - preRelease: preReleaseClean, + preRelease: preRelease, major: major, minor: minor, patch: patch, @@ -125,13 +126,10 @@ func processComponents(version string) (int64, int64, int64, error) { } func processVersion(major int64, minor int64, patch int64, preRelease []string, metadata string) (string, []string) { - toReturnVersion := strconv.FormatInt(major, 10) + valueDelimiter + strconv.FormatInt(minor, 10) + valueDelimiter + strconv.FormatInt(patch, 10) + toReturnVersion := fmt.Sprintf("%d.%d.%d", major, minor, patch) if len(preRelease) != 0 { for i, _ := range preRelease { - preReleaseNumeric, err := strconv.ParseInt(preRelease[i], 10, 64) - if err == nil { - preRelease[i] = strconv.FormatInt(preReleaseNumeric, 10) - } + preRelease = sanitizeIntStr(preRelease, i) } toReturnVersion = toReturnVersion + preReleaseDelimiter + strings.Join(preRelease, valueDelimiter) } @@ -141,6 +139,14 @@ func processVersion(major int64, minor int64, patch int64, preRelease []string, return toReturnVersion, preRelease } +func sanitizeIntStr(preRelease []string, i int) []string { + preReleaseNumeric, err := strconv.ParseInt(preRelease[i], 10, 64) + if err == nil { + preRelease[i] = strconv.FormatInt(preReleaseNumeric, 10) + } + return preRelease +} + // Compare compares two semver versions func (s *Semver) Compare(toCompare Semver) int { if s.version == toCompare.version { diff --git a/engine/grammar/matchers/datatypes/semvererrors.go b/engine/grammar/matchers/datatypes/semvererrors.go deleted file mode 100644 index 56553f02..00000000 --- a/engine/grammar/matchers/datatypes/semvererrors.go +++ /dev/null @@ -1,11 +0,0 @@ -package datatypes - -// SemverValidatonError represents a semver validaton error -type SemverValidatonError struct { - Message string -} - -// Error implements golang error interface -func (f SemverValidatonError) Error() string { - return f.Message -} diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 63793450..46ae6699 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" @@ -361,15 +360,12 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building EqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) - matcherSemver, err := NewEqualToSemverMatcher( + matcher = NewEqualToSemverMatcher( *dto.String, dto.Negate, attributeName, + logger, ) - if err != nil { - return nil, err - } - matcher = matcherSemver case MatcherTypeGreaterThanOrEqualToSemver: if dto.String == nil { return nil, ErrInvalidGTOESemver @@ -378,15 +374,12 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building GreaterThanOrEqualToSemverMatcher with negate=%t, semver=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) - matcherSemver, err := NewGreaterThanOrEqualToSemverMatcher( + matcher = NewGreaterThanOrEqualToSemverMatcher( dto.Negate, *dto.String, attributeName, + logger, ) - if err != nil { - return nil, err - } - matcher = matcherSemver case MatcherTypeLessThanOrEqualToSemver: if dto.String == nil { return nil, ErrInvalidLTOESemver @@ -395,15 +388,12 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building LessThanOrEqualToSemverMatcher with negate=%t, regex=%s, attributeName=%v", dto.Negate, *dto.String, attributeName, )) - matcherSemver, err := NewLessThanOrEqualToSemverMatcher( + matcher = NewLessThanOrEqualToSemverMatcher( *dto.String, dto.Negate, attributeName, + logger, ) - if err != nil { - return nil, err - } - matcher = matcherSemver case MatcherTypeBetweenSemver: if dto.BetweenString.Start == nil || dto.BetweenString.End == nil { return nil, ErrInvalidLBetweenSemver @@ -412,16 +402,13 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building BetweenSemverMatcher with negate=%t, regexStart=%s, regexEnd=%s, attributeName=%v", dto.Negate, *dto.BetweenString.Start, *dto.BetweenString.End, attributeName, )) - matcherSemver, err := NewBetweenSemverMatcher( + matcher = NewBetweenSemverMatcher( *dto.BetweenString.Start, *dto.BetweenString.End, dto.Negate, attributeName, + logger, ) - if err != nil { - return nil, err - } - matcher = matcherSemver case MatcherTypeInListSemver: if dto.Whitelist == nil { return nil, ErrInvalidLInListSemver @@ -430,19 +417,12 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L "Building ErrInvalidLInListSemver with negate=%t, regex=%v, attributeName=%v", dto.Negate, dto.Whitelist.Whitelist, attributeName, )) - matcherSemver, warnings := NewInListSemverMatcher( + matcher = NewInListSemverMatcher( dto.Whitelist.Whitelist, dto.Negate, attributeName, + logger, ) - if len(warnings) != 0 { - for _, err := range warnings { - if errType, ok := err.(datatypes.SemverValidatonError); ok { - logger.Warning(errType.Message) - } - } - } - matcher = matcherSemver default: return nil, errors.New("Matcher not found") } diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index bb5680f2..6b80b8c1 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -5,16 +5,20 @@ import ( "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/datastructures/set" + "github.com/splitio/go-toolkit/v5/logging" ) // EqualToSemverMatcher struct to hold the semver to compare type EqualToSemverMatcher struct { Matcher - semver datatypes.Semver + semver *datatypes.Semver } // Match will match if the comparisonValue is equal to the matchingValue func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + if e.semver == nil { + return false + } matchingKey, err := e.matchingKey(key, attributes) if err != nil { e.logger.Warning(fmt.Sprintf("EqualToSemverMatcher: %s", err.Error())) @@ -39,24 +43,24 @@ func (e *EqualToSemverMatcher) Match(key string, attributes map[string]interface } // NewEqualToSemverMatcher returns a pointer to a new instance of EqualToSemverMatcher -func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string) (*EqualToSemverMatcher, error) { +func NewEqualToSemverMatcher(cmpVal string, negate bool, attributeName *string, logger logging.LoggerInterface) *EqualToSemverMatcher { semver, err := datatypes.BuildSemver(cmpVal) if err != nil { - return nil, err + logger.Error(fmt.Sprintf("couldnt't build semver %s for EQUAL_TO_SEMVER matcher: %s", cmpVal, err.Error())) } return &EqualToSemverMatcher{ Matcher: Matcher{ negate: negate, attributeName: attributeName, }, - semver: *semver, - }, nil + semver: semver, + } } // GreaterThanOrEqualToSemverMatcher struct to hold the semver to compare type GreaterThanOrEqualToSemverMatcher struct { Matcher - semver datatypes.Semver + semver *datatypes.Semver } // Match compares the semver of the key with the semver in the feature flag @@ -79,34 +83,37 @@ func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[str return false } - result := semver.Compare(g.semver) >= 0 + result := semver.Compare(*g.semver) >= 0 g.logger.Debug(fmt.Sprintf("%s >= %s | Result: %t", semver.Version(), g.semver.Version(), result)) return result } // NewGreaterThanOrEqualToSemverMatcher returns an instance of GreaterThanOrEqualToSemverMatcher -func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attributeName *string) (*GreaterThanOrEqualToSemverMatcher, error) { +func NewGreaterThanOrEqualToSemverMatcher(negate bool, compareTo string, attributeName *string, logger logging.LoggerInterface) *GreaterThanOrEqualToSemverMatcher { semver, err := datatypes.BuildSemver(compareTo) if err != nil { - return nil, err + logger.Error(fmt.Sprintf("couldnt't build semver %s for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher: %s", compareTo, err.Error())) } return &GreaterThanOrEqualToSemverMatcher{ Matcher: Matcher{ negate: negate, attributeName: attributeName, }, - semver: *semver, - }, nil + semver: semver, + } } // LessThanOrEqualToSemverMatcher struct to hold the semver to compare type LessThanOrEqualToSemverMatcher struct { Matcher - semver datatypes.Semver + semver *datatypes.Semver } // Match will match if the comparisonValue is less or equal to the matchingValue func (l *LessThanOrEqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + if l.semver == nil { + return false + } matchingKey, err := l.matchingKey(key, attributes) if err != nil { l.logger.Warning(fmt.Sprintf("LessThanOrEqualToSemverMatcher: %s", err.Error())) @@ -125,35 +132,38 @@ func (l *LessThanOrEqualToSemverMatcher) Match(key string, attributes map[string return false } - result := semver.Compare(l.semver) <= 0 + result := semver.Compare(*l.semver) <= 0 l.logger.Debug(fmt.Sprintf("%s >= %s | Result: %t", semver.Version(), l.semver.Version(), result)) return result } // NewLessThanOrEqualToSemverMatcher returns a pointer to a new instance of LessThanOrEqualToSemverMatcher -func NewLessThanOrEqualToSemverMatcher(compareTo string, negate bool, attributeName *string) (*LessThanOrEqualToSemverMatcher, error) { +func NewLessThanOrEqualToSemverMatcher(compareTo string, negate bool, attributeName *string, logger logging.LoggerInterface) *LessThanOrEqualToSemverMatcher { semver, err := datatypes.BuildSemver(compareTo) if err != nil { - return nil, err + logger.Error(fmt.Sprintf("couldnt't build semver %s for LESS_THAN_OR_EQUAL_TO_SEMVER matcher: %s", compareTo, err.Error())) } return &LessThanOrEqualToSemverMatcher{ Matcher: Matcher{ negate: negate, attributeName: attributeName, }, - semver: *semver, - }, nil + semver: semver, + } } // BetweenSemverMatcher struct to hold the semver to compare type BetweenSemverMatcher struct { Matcher - startSemver datatypes.Semver - endSemver datatypes.Semver + startSemver *datatypes.Semver + endSemver *datatypes.Semver } // Match will match if the comparisonValue is between to the matchingValue func (b *BetweenSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + if b.startSemver == nil || b.endSemver == nil { + return false + } matchingKey, err := b.matchingKey(key, attributes) if err != nil { b.logger.Warning(fmt.Sprintf("BetweenSemverMatcher: %s", err.Error())) @@ -172,29 +182,29 @@ func (b *BetweenSemverMatcher) Match(key string, attributes map[string]interface return false } - result := semver.Compare(b.startSemver) >= 0 && semver.Compare(b.endSemver) <= 0 + result := semver.Compare(*b.startSemver) >= 0 && semver.Compare(*b.endSemver) <= 0 b.logger.Debug(fmt.Sprintf("%s between %s and %s | Result: %t", semver.Version(), b.startSemver.Version(), b.endSemver.Version(), result)) return result } // NewBetweenSemverMatcher returns a pointer to a new instance of BetweenSemverMatcher -func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string) (*BetweenSemverMatcher, error) { +func NewBetweenSemverMatcher(startVal string, endVal string, negate bool, attributeName *string, logger logging.LoggerInterface) *BetweenSemverMatcher { startSemver, err := datatypes.BuildSemver(startVal) if err != nil { - return nil, err + logger.Error(fmt.Sprintf("couldnt't build semver %s for BETWEEN_SEMVER matcher, ignoring: %s", startVal, err.Error())) } endSemver, err := datatypes.BuildSemver(endVal) if err != nil { - return nil, err + logger.Error(fmt.Sprintf("couldnt't build semver %s for BETWEEN_SEMVER matcher, ignoring: %s", endVal, err.Error())) } return &BetweenSemverMatcher{ Matcher: Matcher{ negate: negate, attributeName: attributeName, }, - startSemver: *startSemver, - endSemver: *endSemver, - }, nil + startSemver: startSemver, + endSemver: endSemver, + } } // InListSemverMatcher struct to hold the semver to compare @@ -205,6 +215,9 @@ type InListSemverMatcher struct { // Match will match if the comparisonValue is in list to the matchingValue func (i *InListSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + if i.semvers.IsEmpty() { + return false + } matchingKey, err := i.matchingKey(key, attributes) if err != nil { i.logger.Warning(fmt.Sprintf("InListSemverMatcher: %s", err.Error())) @@ -226,15 +239,14 @@ func (i *InListSemverMatcher) Match(key string, attributes map[string]interface{ } // NewInListSemverMatcher returns a pointer to a new instance of InListSemverMatcher -func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string) (*InListSemverMatcher, []error) { +func NewInListSemverMatcher(setVersions []string, negate bool, attributeName *string, logger logging.LoggerInterface) *InListSemverMatcher { semvers := set.NewSet() - var errs []error - for _, str := range cmpList { - semver, err := datatypes.BuildSemver(str) + for _, version := range setVersions { + semver, err := datatypes.BuildSemver(version) if err == nil { semvers.Add(semver.Version()) } else { - errs = append(errs, err) + logger.Error(fmt.Sprintf("couldnt't build semver %s for IN_LIST_SEMVER matcher, ignoring: %s", version, err.Error())) } } return &InListSemverMatcher{ @@ -243,5 +255,5 @@ func NewInListSemverMatcher(cmpList []string, negate bool, attributeName *string attributeName: attributeName, }, semvers: semvers, - }, errs + } } diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index e556ff6e..e97c0164 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -442,20 +442,3 @@ func TestInListInvalidSemvers(t *testing.T) { t.Error("There should be errors when building the matcher") } } - -func TestNewInListMatcherInvalidSemvers(t *testing.T) { - semvers := make([]string, 0, 3) - semvers = append(semvers, "1.alpha.2") - semvers = append(semvers, "alpha.beta.1") - semvers = append(semvers, "1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788") - attrName := "version" - _, warnings := NewInListSemverMatcher( - semvers, - false, - &attrName, - ) - - if len(warnings) != 3 { - t.Error("There should be warnings when building the matcher") - } -} From 95f2a2b220861ba9286aebacc8f597d9a05df318 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Thu, 9 May 2024 17:20:36 -0300 Subject: [PATCH 43/56] Update match for equal to semver --- engine/grammar/matchers/semver.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index 6b80b8c1..e8fa85b8 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -65,6 +65,9 @@ type GreaterThanOrEqualToSemverMatcher struct { // Match compares the semver of the key with the semver in the feature flag func (g *GreaterThanOrEqualToSemverMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool { + if g.semver == nil { + return false + } matchingKey, err := g.matchingKey(key, attributes) if err != nil { g.logger.Warning(fmt.Sprintf("GreaterThanOrEqualToSemverMatcher: %s", err.Error())) From 4da8f06e9dd4db3e89a50a9a4efadf5d9186fbf3 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Thu, 9 May 2024 17:53:17 -0300 Subject: [PATCH 44/56] Add test cases --- engine/grammar/matchers/semver_test.go | 128 ++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 15 deletions(-) diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index e97c0164..43d821cc 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -140,6 +140,29 @@ func TestPreReleaseShouldReturnTrueWhenVersionsAreEqual(t *testing.T) { } } +func TestPreReleaseShouldReturnFalseWhenSemverIsNil(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + str := "1.2-SNAPSHOT" + dto := &dtos.MatcherDTO{ + MatcherType: MatcherEqualToSemver, + String: &str, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should be no errors when building the matcher") + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "1.2.3" + if matcher.Match("ass", attributes, nil) { + t.Error("Equal should match") + } +} + func TestPreReleaseShouldReturnFalseWhenVersionsDiffer(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) attrName := "version" @@ -258,6 +281,29 @@ func TestGreaterThanOrEqualToSemverMatcher(t *testing.T) { } } +func TestGreaterThanOrEqualToSemverMatcherWithNilSemver(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + semvers := "1.2-SNAPSHOT" + dto := &dtos.MatcherDTO{ + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + MatcherType: MatcherTypeGreaterThanOrEqualToSemver, + String: &semvers, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should not be errors when building the matcher") + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.3.4" + if matcher.Match("asd", attributes, nil) { + t.Error("2.3.4 should not match") + } +} + func TestLessThanOrEqualToSemverMatcher(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) attrName := "version" @@ -304,6 +350,29 @@ func TestLessThanOrEqualToSemverMatcherWithInvalidSemver(t *testing.T) { } } +func TestLessThanOrEqualToSemverMatcherWithNilSemver(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + attrName := "version" + semvers := "1.2-SNAPSHOT" + dto := &dtos.MatcherDTO{ + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + MatcherType: MatcherTypeLessThanOrEqualToSemver, + String: &semvers, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should not be errors when building the matcher") + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.3.4" + if matcher.Match("asd", attributes, nil) { + t.Error("2.3.4 should not match") + } +} + func TestBetweenSemverMatcher(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) attrName := "version" @@ -341,10 +410,10 @@ func TestBetweenSemverMatcher(t *testing.T) { } } -func TestBetweenSemverWithInvalidSemvers(t *testing.T) { +func TestBetweenSemverWithNilSemvers(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) dto := &dtos.MatcherDTO{ - MatcherType: MatcherTypeLessThanOrEqualToSemver, + MatcherType: MatcherTypeBetweenSemver, BetweenString: &dtos.BetweenStringMatcherDataDTO{ Start: nil, End: nil, @@ -356,6 +425,33 @@ func TestBetweenSemverWithInvalidSemvers(t *testing.T) { } } +func TestBetweenSemverWithInvalidSemvers(t *testing.T) { + attrName := "version" + logger := logging.NewLogger(&logging.LoggerOptions{}) + start := "1.alpha.2" + end := "3.4.5" + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeBetweenSemver, + BetweenString: &dtos.BetweenStringMatcherDataDTO{ + Start: &start, + End: &end, + }, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, + } + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should not be errors when building the matcher") + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.2.2-rc.1.2" + if matcher.Match("asd", attributes, nil) { + t.Error("2.2.2-rc.1.2", " between should not match") + } +} + func TestInListSemvers(t *testing.T) { semvers := make([]string, 0, 3) semvers = append(semvers, "1.0.0-rc.1") @@ -419,26 +515,28 @@ func TestInListSemversNotMatch(t *testing.T) { } func TestInListInvalidSemvers(t *testing.T) { + attrName := "version" logger := logging.NewLogger(&logging.LoggerOptions{}) - dto := &dtos.MatcherDTO{ - MatcherType: MatcherTypeLessThanOrEqualToSemver, - Whitelist: &dtos.WhitelistMatcherDataDTO{Whitelist: nil}, - } - _, err := BuildMatcher(dto, nil, logger) - if err == nil { - t.Error("There should be errors when building the matcher") - } semvers := make([]string, 0, 3) semvers = append(semvers, "1.alpha.2") semvers = append(semvers, "alpha.beta.1") semvers = append(semvers, "1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788") - dto = &dtos.MatcherDTO{ - MatcherType: MatcherTypeLessThanOrEqualToSemver, + dto := &dtos.MatcherDTO{ + MatcherType: MatcherTypeInListSemver, Whitelist: &dtos.WhitelistMatcherDataDTO{Whitelist: semvers}, + KeySelector: &dtos.KeySelectorDTO{ + Attribute: &attrName, + }, } - _, err = BuildMatcher(dto, nil, logger) - if err == nil { - t.Error("There should be errors when building the matcher") + matcher, err := BuildMatcher(dto, nil, logger) + if err != nil { + t.Error("There should not be errors when building the matcher") + } + + attributes := make(map[string]interface{}) + attributes[attrName] = "2.2.2" + if matcher.Match("asd", attributes, nil) { + t.Error("2.2.2", " in list ", semvers, " should not match") } } From 954315d6df53ee876ca0832db0d59bbc68450fbd Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 9 May 2024 18:11:46 -0300 Subject: [PATCH 45/56] clean code of validator --- engine/validator/matchers.go | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 2c18eecd..1dff881e 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -10,30 +10,31 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) -// OverrideWithUnsupported overrides the split with an unsupported matcher type -func OverrideWithUnsupported() dtos.ConditionDTO { - return dtos.ConditionDTO{ - ConditionType: grammar.ConditionTypeWhitelist, - Label: impressionlabels.UnsupportedMatcherType, - Partitions: []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}}, - MatcherGroup: dtos.MatcherGroupDTO{ - Combiner: "AND", - Matchers: []dtos.MatcherDTO{{ - MatcherType: matchers.MatcherTypeAllKeys, - }}, - }, +var unsupportedMatcherConditionReplacement []dtos.ConditionDTO = []dtos.ConditionDTO{{ + ConditionType: grammar.ConditionTypeWhitelist, + Label: impressionlabels.UnsupportedMatcherType, + Partitions: []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Combiner: "AND", + Matchers: []dtos.MatcherDTO{{MatcherType: matchers.MatcherTypeAllKeys, Negate: false}}, + }, +}} + +func shouldOverrideConditions(conditions []dtos.ConditionDTO, logger logging.LoggerInterface) bool { + for _, condition := range conditions { + for _, matcher := range condition.MatcherGroup.Matchers { + _, err := matchers.BuildMatcher(&matcher, &injection.Context{}, logger) + if err != nil { + return true + } + } } + return false } // ProcessMatchers processes the matchers of a split and validates them func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) { - for idx := range split.Conditions { - for jdx := range split.Conditions[idx].MatcherGroup.Matchers { - _, err := matchers.BuildMatcher(&split.Conditions[idx].MatcherGroup.Matchers[jdx], &injection.Context{}, logger) - if err != nil { - split.Conditions = []dtos.ConditionDTO{OverrideWithUnsupported()} - } - return - } + if shouldOverrideConditions(split.Conditions, logger) { + split.Conditions = unsupportedMatcherConditionReplacement } } From 0cc917daf2713110e342051d60744fa1adfd0add Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 10 May 2024 12:48:12 -0300 Subject: [PATCH 46/56] made Unsupported replacement public for multiple usages --- engine/validator/matchers.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 1dff881e..8887adbd 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -10,7 +10,8 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) -var unsupportedMatcherConditionReplacement []dtos.ConditionDTO = []dtos.ConditionDTO{{ +// UnsupportedMatcherConditionReplacement is the default condition to be used when a matcher is not supported +var UnsupportedMatcherConditionReplacement []dtos.ConditionDTO = []dtos.ConditionDTO{{ ConditionType: grammar.ConditionTypeWhitelist, Label: impressionlabels.UnsupportedMatcherType, Partitions: []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}}, @@ -35,6 +36,6 @@ func shouldOverrideConditions(conditions []dtos.ConditionDTO, logger logging.Log // ProcessMatchers processes the matchers of a split and validates them func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) { if shouldOverrideConditions(split.Conditions, logger) { - split.Conditions = unsupportedMatcherConditionReplacement + split.Conditions = UnsupportedMatcherConditionReplacement } } From e183b598fb5b1e2b4b6b07fcf91369617658eb97 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 10 May 2024 13:55:24 -0300 Subject: [PATCH 47/56] public function --- engine/validator/matchers.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 8887adbd..3cc49da7 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -10,8 +10,8 @@ import ( "github.com/splitio/go-toolkit/v5/logging" ) -// UnsupportedMatcherConditionReplacement is the default condition to be used when a matcher is not supported -var UnsupportedMatcherConditionReplacement []dtos.ConditionDTO = []dtos.ConditionDTO{{ +// unsupportedMatcherConditionReplacement is the default condition to be used when a matcher is not supported +var unsupportedMatcherConditionReplacement []dtos.ConditionDTO = []dtos.ConditionDTO{{ ConditionType: grammar.ConditionTypeWhitelist, Label: impressionlabels.UnsupportedMatcherType, Partitions: []dtos.PartitionDTO{{Treatment: evaluator.Control, Size: 100}}, @@ -36,6 +36,11 @@ func shouldOverrideConditions(conditions []dtos.ConditionDTO, logger logging.Log // ProcessMatchers processes the matchers of a split and validates them func ProcessMatchers(split *dtos.SplitDTO, logger logging.LoggerInterface) { if shouldOverrideConditions(split.Conditions, logger) { - split.Conditions = UnsupportedMatcherConditionReplacement + split.Conditions = unsupportedMatcherConditionReplacement } } + +// MakeUnsupportedMatcherConditionReplacement returns the default condition to be used when a matcher is not supported +func MakeUnsupportedMatcherConditionReplacement() []dtos.ConditionDTO { + return unsupportedMatcherConditionReplacement +} From c6399baacf089dba99079f4b29f363ca4047cd68 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 10 May 2024 14:22:30 -0300 Subject: [PATCH 48/56] Add unsuported matcher error --- .../matchers/datatypes/unsupportedmatchererror.go | 11 +++++++++++ engine/grammar/matchers/matchers.go | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 engine/grammar/matchers/datatypes/unsupportedmatchererror.go diff --git a/engine/grammar/matchers/datatypes/unsupportedmatchererror.go b/engine/grammar/matchers/datatypes/unsupportedmatchererror.go new file mode 100644 index 00000000..87ffa2f2 --- /dev/null +++ b/engine/grammar/matchers/datatypes/unsupportedmatchererror.go @@ -0,0 +1,11 @@ +package datatypes + +// UnsupportedMatcherError represents a flag set validaton error +type UnsupportedMatcherError struct { + Message string +} + +// Error implements golang error interface +func (f UnsupportedMatcherError) Error() string { + return f.Message +} diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index 46ae6699..e99ae646 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" @@ -424,7 +425,9 @@ func BuildMatcher(dto *dtos.MatcherDTO, ctx *injection.Context, logger logging.L logger, ) default: - return nil, errors.New("Matcher not found") + return nil, datatypes.UnsupportedMatcherError{ + Message: fmt.Sprintf("Unable to create matcher for matcher type: %s", dto.MatcherType), + } } if ctx != nil { From f3ccef6d083156c656dc7f1edea32f6d558ff7db Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 10 May 2024 14:41:39 -0300 Subject: [PATCH 49/56] WIP: adding changes in condition --- engine/grammar/condition.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/engine/grammar/condition.go b/engine/grammar/condition.go index 65f3732e..e55dec5d 100644 --- a/engine/grammar/condition.go +++ b/engine/grammar/condition.go @@ -3,6 +3,7 @@ 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/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" ) @@ -39,6 +40,18 @@ func NewCondition(cond *dtos.ConditionDTO, ctx *injection.Context, logger loggin } } +func proccessMatchers(condMatchers []dtos.MatcherDTO, ctx *injection.Context, logger logging.LoggerInterface) []matchers.MatcherInterface { + matcherObjs := make([]matchers.MatcherInterface, 0) + for _, matcher := range condMatchers { + m, err := matchers.BuildMatcher(&matcher, ctx, logger) + if err == nil { + matcherObjs = append(matcherObjs, m) + } else if errType, ok := err.(datatypes.UnsupportedMatcherError); ok { + + } + } +} + // Partition struct with added logic that wraps around a DTO type Partition struct { partitionData dtos.PartitionDTO From 82c933c079d5358dc1d336da2a573dbdfbf0208d Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 10 May 2024 16:44:29 -0300 Subject: [PATCH 50/56] Add unssuported matcher logic in NewSplit and tets cases --- engine/grammar/condition.go | 22 ++--- engine/grammar/condition_test.go | 99 +++++++++++++++++++++- engine/grammar/split.go | 28 ++++-- engine/grammar/split_test.go | 141 +++++++++++++++++++++++++++++++ engine/validator/matchers.go | 3 +- 5 files changed, 273 insertions(+), 20 deletions(-) diff --git a/engine/grammar/condition.go b/engine/grammar/condition.go index e55dec5d..a1f9463a 100644 --- a/engine/grammar/condition.go +++ b/engine/grammar/condition.go @@ -18,17 +18,14 @@ 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 { + return nil, err } return &Condition{ @@ -37,19 +34,22 @@ func NewCondition(cond *dtos.ConditionDTO, ctx *injection.Context, logger loggin partitions: partitions, label: cond.Label, conditionType: cond.ConditionType, - } + }, nil } -func proccessMatchers(condMatchers []dtos.MatcherDTO, ctx *injection.Context, logger logging.LoggerInterface) []matchers.MatcherInterface { +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 if errType, ok := err.(datatypes.UnsupportedMatcherError); ok { - + } else { + if _, ok := err.(datatypes.UnsupportedMatcherError); ok { + return nil, err + } } } + return matcherObjs, nil } // Partition struct with added logic that wraps around a DTO diff --git a/engine/grammar/condition_test.go b/engine/grammar/condition_test.go index 43f38a62..2350fcee 100644 --- a/engine/grammar/condition_test.go +++ b/engine/grammar/condition_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" "github.com/splitio/go-toolkit/v5/logging" ) @@ -46,7 +47,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") @@ -113,7 +118,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") @@ -141,3 +149,90 @@ 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") + } +} + +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") + } +} diff --git a/engine/grammar/split.go b/engine/grammar/split.go index 30a65efd..0eacf729 100644 --- a/engine/grammar/split.go +++ b/engine/grammar/split.go @@ -2,6 +2,8 @@ package grammar import ( "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/evaluator/impressionlabels" + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" @@ -13,21 +15,35 @@ type Split struct { conditions []*Condition } +var conditionReplacementUnsupportedMatcher []*Condition = []*Condition{{ + conditionType: ConditionTypeWhitelist, + label: impressionlabels.UnsupportedMatcherType, + partitions: []Partition{{partitionData: dtos.PartitionDTO{Treatment: "control", Size: 100}}}, + matchers: []matchers.MatcherInterface{matchers.NewAllKeysMatcher(false)}, +}} + // NewSplit instantiates a new Split object and all it's internal structures mapped to model classes func NewSplit(splitDTO *dtos.SplitDTO, ctx *injection.Context, logger logging.LoggerInterface) *Split { - conditions := make([]*Condition, 0) - for _, cond := range splitDTO.Conditions { - conditions = append(conditions, NewCondition(&cond, ctx, logger)) - } - split := Split{ - conditions: conditions, + conditions: processConditions(splitDTO.Conditions, splitDTO, ctx, logger), splitData: splitDTO, } return &split } +func processConditions(conditions []dtos.ConditionDTO, splitDTO *dtos.SplitDTO, ctx *injection.Context, logger logging.LoggerInterface) []*Condition { + conditionsToReturn := make([]*Condition, 0) + for _, cond := range splitDTO.Conditions { + condition, err := NewCondition(&cond, ctx, logger) + if err != nil { + return conditionReplacementUnsupportedMatcher + } + conditionsToReturn = append(conditionsToReturn, condition) + } + return conditionsToReturn +} + // Name returns the name of the feature func (s *Split) Name() string { return s.splitData.Name diff --git a/engine/grammar/split_test.go b/engine/grammar/split_test.go index 5b054c16..544ae14b 100644 --- a/engine/grammar/split_test.go +++ b/engine/grammar/split_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" "github.com/splitio/go-toolkit/v5/logging" ) @@ -57,3 +58,143 @@ func TestSplitCreation(t *testing.T) { t.Error("Traffic allocation should be 100") } } + +func TestSplitCreationWithConditionsMatcher(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := dtos.SplitDTO{ + Algo: 1, + ChangeNumber: 123, + Conditions: []dtos.ConditionDTO{{ + ConditionType: ConditionTypeWhitelist, + Label: "test", + Partitions: []dtos.PartitionDTO{{Treatment: "off", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Combiner: "AND", + Matchers: []dtos.MatcherDTO{{MatcherType: matchers.MatcherTypeAllKeys, Negate: false}}, + }, + }, { + ConditionType: ConditionTypeWhitelist, + Label: "test", + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Combiner: "AND", + Matchers: []dtos.MatcherDTO{{MatcherType: matchers.MatcherTypeAllKeys, Negate: false}}, + }, + }}, + DefaultTreatment: "def", + Killed: false, + Name: "split1", + Seed: 1234, + Status: "ACTIVE", + TrafficAllocation: 100, + TrafficAllocationSeed: 333, + TrafficTypeName: "tt1", + } + split := NewSplit(&dto, nil, logger) + + if split.Algo() != SplitAlgoLegacy { + t.Error("Algo() should return legacy") + } + + if split.ChangeNumber() != 123 { + t.Error("Incorrect changenumber returned") + } + + if split.DefaultTreatment() != "def" { + t.Error("Incorrect default treatment") + } + + if split.Killed() { + t.Error("Split should not be marked as killed") + } + + if split.Seed() != 1234 { + t.Error("Incorrect seed") + } + + if split.Name() != "split1" { + t.Error("Incorrect split name") + } + + if split.Status() != SplitStatusActive { + t.Error("Status should be active") + } + + if split.TrafficAllocation() != 100 { + t.Error("Traffic allocation should be 100") + } + + if len(split.conditions) != 2 { + t.Error("conditions length should be 2") + } +} + +func TestSplitCreationWithUnsupportedMatcher(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + dto := dtos.SplitDTO{ + Algo: 1, + ChangeNumber: 123, + Conditions: []dtos.ConditionDTO{{ + ConditionType: ConditionTypeWhitelist, + Label: "test", + Partitions: []dtos.PartitionDTO{{Treatment: "control", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Combiner: "AND", + Matchers: []dtos.MatcherDTO{{MatcherType: "unssuported", Negate: false}}, + }, + }, { + ConditionType: ConditionTypeWhitelist, + Label: "test", + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, + MatcherGroup: dtos.MatcherGroupDTO{ + Combiner: "AND", + Matchers: []dtos.MatcherDTO{{MatcherType: matchers.MatcherTypeAllKeys, Negate: false}}, + }, + }}, + DefaultTreatment: "def", + Killed: false, + Name: "split1", + Seed: 1234, + Status: "ACTIVE", + TrafficAllocation: 100, + TrafficAllocationSeed: 333, + TrafficTypeName: "tt1", + } + split := NewSplit(&dto, nil, logger) + + if split.Algo() != SplitAlgoLegacy { + t.Error("Algo() should return legacy") + } + + if split.ChangeNumber() != 123 { + t.Error("Incorrect changenumber returned") + } + + if split.DefaultTreatment() != "def" { + t.Error("Incorrect default treatment") + } + + if split.Killed() { + t.Error("Split should not be marked as killed") + } + + if split.Seed() != 1234 { + t.Error("Incorrect seed") + } + + if split.Name() != "split1" { + t.Error("Incorrect split name") + } + + if split.Status() != SplitStatusActive { + t.Error("Status should be active") + } + + if split.TrafficAllocation() != 100 { + t.Error("Traffic allocation should be 100") + } + + if len(split.conditions) != 1 { + t.Error("conditions length should be 1") + } +} diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 3cc49da7..3a804e16 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -6,6 +6,7 @@ import ( "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/grammar/matchers" + "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" ) @@ -25,7 +26,7 @@ func shouldOverrideConditions(conditions []dtos.ConditionDTO, logger logging.Log for _, condition := range conditions { for _, matcher := range condition.MatcherGroup.Matchers { _, err := matchers.BuildMatcher(&matcher, &injection.Context{}, logger) - if err != nil { + if _, ok := err.(datatypes.UnsupportedMatcherError); ok { return true } } From 90936aff0865cb3164a68c876c717b6db9f1192e Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 10 May 2024 16:47:32 -0300 Subject: [PATCH 51/56] Remove paramater not using --- engine/grammar/split.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/grammar/split.go b/engine/grammar/split.go index 0eacf729..7bc14936 100644 --- a/engine/grammar/split.go +++ b/engine/grammar/split.go @@ -25,14 +25,14 @@ var conditionReplacementUnsupportedMatcher []*Condition = []*Condition{{ // NewSplit instantiates a new Split object and all it's internal structures mapped to model classes func NewSplit(splitDTO *dtos.SplitDTO, ctx *injection.Context, logger logging.LoggerInterface) *Split { split := Split{ - conditions: processConditions(splitDTO.Conditions, splitDTO, ctx, logger), + conditions: processConditions(splitDTO, ctx, logger), splitData: splitDTO, } return &split } -func processConditions(conditions []dtos.ConditionDTO, splitDTO *dtos.SplitDTO, ctx *injection.Context, logger logging.LoggerInterface) []*Condition { +func processConditions(splitDTO *dtos.SplitDTO, ctx *injection.Context, logger logging.LoggerInterface) []*Condition { conditionsToReturn := make([]*Condition, 0) for _, cond := range splitDTO.Conditions { condition, err := NewCondition(&cond, ctx, logger) From dc30b2ccda2800766d83d002066ccc02c3f7dc6c Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 10 May 2024 18:05:30 -0300 Subject: [PATCH 52/56] Add log message --- engine/grammar/condition.go | 2 ++ engine/grammar/condition_test.go | 5 +++++ engine/grammar/split.go | 1 + 3 files changed, 8 insertions(+) diff --git a/engine/grammar/condition.go b/engine/grammar/condition.go index a1f9463a..fbdd3a36 100644 --- a/engine/grammar/condition.go +++ b/engine/grammar/condition.go @@ -25,6 +25,7 @@ func NewCondition(cond *dtos.ConditionDTO, ctx *injection.Context, logger loggin } matcherObjs, err := processMatchers(cond.MatcherGroup.Matchers, ctx, logger) if err != nil { + // At this point the only error forwarded is UnsupportedMatcherError return nil, err } @@ -44,6 +45,7 @@ func processMatchers(condMatchers []dtos.MatcherDTO, ctx *injection.Context, log if err == nil { matcherObjs = append(matcherObjs, m) } else { + logger.Debug("error in BuildMaycher, reason: ", err.Error()) if _, ok := err.(datatypes.UnsupportedMatcherError); ok { return nil, err } diff --git a/engine/grammar/condition_test.go b/engine/grammar/condition_test.go index 2350fcee..86a8c9b8 100644 --- a/engine/grammar/condition_test.go +++ b/engine/grammar/condition_test.go @@ -5,6 +5,7 @@ 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/v5/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/logging" ) @@ -193,6 +194,10 @@ func TestConditionUnsupportedMatcherWrapperObject(t *testing.T) { 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) { diff --git a/engine/grammar/split.go b/engine/grammar/split.go index 7bc14936..9214e93a 100644 --- a/engine/grammar/split.go +++ b/engine/grammar/split.go @@ -37,6 +37,7 @@ func processConditions(splitDTO *dtos.SplitDTO, ctx *injection.Context, logger l for _, cond := range splitDTO.Conditions { condition, err := NewCondition(&cond, ctx, logger) if err != nil { + logger.Debug("Overriding conditions due unexpected matcher received") return conditionReplacementUnsupportedMatcher } conditionsToReturn = append(conditionsToReturn, condition) From cb6b1aee96c6ae0f8bc751deff7207fd62b03b58 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 10 May 2024 18:07:50 -0300 Subject: [PATCH 53/56] Update debug message --- engine/grammar/condition.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/grammar/condition.go b/engine/grammar/condition.go index fbdd3a36..07693c9f 100644 --- a/engine/grammar/condition.go +++ b/engine/grammar/condition.go @@ -45,7 +45,7 @@ func processMatchers(condMatchers []dtos.MatcherDTO, ctx *injection.Context, log if err == nil { matcherObjs = append(matcherObjs, m) } else { - logger.Debug("error in BuildMaycher, reason: ", err.Error()) + logger.Debug("error in BuildMatcher, reason: ", err.Error()) if _, ok := err.(datatypes.UnsupportedMatcherError); ok { return nil, err } From 9e60c1ddc0f3df048aa2e836a08ef1a6eb7d9096 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Mon, 13 May 2024 16:22:00 -0300 Subject: [PATCH 54/56] Update unsupported matcher in conditionReplacementUnsupportedMatcher --- engine/grammar/split.go | 1 + engine/grammar/split_test.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/grammar/split.go b/engine/grammar/split.go index 9214e93a..66b04def 100644 --- a/engine/grammar/split.go +++ b/engine/grammar/split.go @@ -20,6 +20,7 @@ var conditionReplacementUnsupportedMatcher []*Condition = []*Condition{{ label: impressionlabels.UnsupportedMatcherType, partitions: []Partition{{partitionData: dtos.PartitionDTO{Treatment: "control", Size: 100}}}, matchers: []matchers.MatcherInterface{matchers.NewAllKeysMatcher(false)}, + combiner: "AND", }} // NewSplit instantiates a new Split object and all it's internal structures mapped to model classes diff --git a/engine/grammar/split_test.go b/engine/grammar/split_test.go index 544ae14b..6052da55 100644 --- a/engine/grammar/split_test.go +++ b/engine/grammar/split_test.go @@ -137,7 +137,7 @@ func TestSplitCreationWithUnsupportedMatcher(t *testing.T) { Conditions: []dtos.ConditionDTO{{ ConditionType: ConditionTypeWhitelist, Label: "test", - Partitions: []dtos.PartitionDTO{{Treatment: "control", Size: 100}}, + Partitions: []dtos.PartitionDTO{{Treatment: "on", Size: 100}}, MatcherGroup: dtos.MatcherGroupDTO{ Combiner: "AND", Matchers: []dtos.MatcherDTO{{MatcherType: "unssuported", Negate: false}}, @@ -197,4 +197,8 @@ func TestSplitCreationWithUnsupportedMatcher(t *testing.T) { if len(split.conditions) != 1 { t.Error("conditions length should be 1") } + + if split.conditions[0].combiner != "AND" { + t.Error("combiner should be AND") + } } From 79be26ffe00cf54b167aa90b5db7823585a6a123 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 14 May 2024 12:44:18 -0300 Subject: [PATCH 55/56] Update to version v6 --- engine/engine.go | 6 ++-- engine/engine_test.go | 6 ++-- engine/evaluator/evaluator.go | 10 +++--- engine/evaluator/evaluator_test.go | 8 ++--- engine/evaluator/mocks/mocks.go | 2 +- engine/grammar/condition.go | 6 ++-- engine/grammar/condition_test.go | 6 ++-- engine/grammar/matchers/allkeys_test.go | 2 +- engine/grammar/matchers/allofset_test.go | 2 +- engine/grammar/matchers/anyofset_test.go | 2 +- engine/grammar/matchers/between.go | 2 +- engine/grammar/matchers/between_test.go | 2 +- engine/grammar/matchers/boolean_test.go | 2 +- engine/grammar/matchers/contains_test.go | 2 +- .../dependency_test/dependency_test.go | 12 +++---- engine/grammar/matchers/endswith_test.go | 2 +- engine/grammar/matchers/equalto.go | 2 +- engine/grammar/matchers/equalto_test.go | 2 +- engine/grammar/matchers/equaltoset_test.go | 2 +- engine/grammar/matchers/gtoet.go | 2 +- engine/grammar/matchers/gtoet_test.go | 2 +- engine/grammar/matchers/insegment.go | 2 +- engine/grammar/matchers/insegment_test.go | 4 +-- engine/grammar/matchers/ltoet.go | 2 +- engine/grammar/matchers/ltoet_test.go | 2 +- engine/grammar/matchers/matcher_test.go | 2 +- engine/grammar/matchers/matchers.go | 4 +-- engine/grammar/matchers/partofset_test.go | 2 +- engine/grammar/matchers/regex_test.go | 2 +- engine/grammar/matchers/semver.go | 2 +- engine/grammar/matchers/semver_test.go | 2 +- engine/grammar/matchers/startswith_test.go | 2 +- engine/grammar/matchers/whitelist_test.go | 2 +- engine/grammar/split.go | 6 ++-- engine/grammar/split_test.go | 4 +-- engine/validator/matchers.go | 12 +++---- engine/validator/matchers_test.go | 6 ++-- flagsets/featuresbyset.go | 2 +- flagsets/featuresbyset_test.go | 2 +- flagsets/flag_set_validator.go | 2 +- go.mod | 4 +-- provisional/impmanager.go | 4 +-- provisional/impmanager_test.go | 10 +++--- provisional/strategy/debug.go | 2 +- provisional/strategy/debug_test.go | 2 +- provisional/strategy/impcounter.go | 2 +- provisional/strategy/imphasher.go | 2 +- provisional/strategy/imphasher_test.go | 2 +- provisional/strategy/impobserver.go | 2 +- provisional/strategy/impobserver_test.go | 2 +- provisional/strategy/interfaces.go | 2 +- provisional/strategy/none.go | 2 +- provisional/strategy/none_test.go | 6 ++-- provisional/strategy/optimized.go | 8 ++--- provisional/strategy/optimized_test.go | 4 +-- provisional/strategy/uniquekeystracker.go | 4 +-- .../strategy/uniquekeystracker_test.go | 2 +- push/borrowed.go | 2 +- push/manager.go | 12 +++---- push/manager_test.go | 16 +++++----- push/mocks/parser.go | 2 +- push/mocks/sync.go | 2 +- push/parser.go | 4 +-- push/parser_test.go | 2 +- push/processor.go | 2 +- push/processor_test.go | 4 +-- push/segment.go | 2 +- push/segment_test.go | 4 +-- push/split.go | 2 +- push/split_test.go | 4 +-- push/statustracker.go | 6 ++-- push/statustracker_test.go | 6 ++-- service/api/auth.go | 8 ++--- service/api/auth_test.go | 8 ++--- service/api/client.go | 6 ++-- service/api/client_test.go | 6 ++-- service/api/helpers.go | 2 +- service/api/helpers_test.go | 2 +- service/api/http_fetchers.go | 8 ++--- service/api/http_fetchers_test.go | 8 ++--- service/api/http_recorders.go | 4 +-- service/api/http_recorders_test.go | 4 +-- service/api/mocks/client.go | 2 +- service/api/specs/splitversionfilter.go | 2 +- service/api/specs/splitversionfilter_test.go | 3 +- service/api/split.go | 6 ++-- service/api/sse/client.go | 6 ++-- service/api/sse/client_test.go | 4 +-- service/api/sse/mocks/mock.go | 2 +- service/commons_test.go | 2 +- service/interfaces.go | 2 +- service/local/sanitizer.go | 2 +- service/local/segmentFetcher.go | 4 +-- service/local/segmentFetcher_test.go | 6 ++-- service/local/splitFetcher.go | 4 +-- service/local/splitFetcher_test.go | 4 +-- service/mocks/auth.go | 2 +- service/mocks/event.go | 2 +- service/mocks/impression.go | 2 +- service/mocks/segment.go | 4 +-- service/mocks/split.go | 4 +-- service/mocks/telemetry.go | 2 +- storage/filter/bloom_filter.go | 2 +- storage/inmemory/mutexmap/mutexmap_test.go | 4 +-- storage/inmemory/mutexmap/segments_test.go | 4 +-- storage/inmemory/mutexmap/splits.go | 6 ++-- storage/inmemory/mutexmap/splits_test.go | 4 +-- storage/inmemory/mutexqueue/events.go | 6 ++-- storage/inmemory/mutexqueue/events_test.go | 6 ++-- storage/inmemory/mutexqueue/impressions.go | 6 ++-- .../inmemory/mutexqueue/impressions_test.go | 6 ++-- storage/inmemory/telemetry.go | 6 ++-- storage/inmemory/telemetry_test.go | 4 +-- storage/interfaces.go | 2 +- storage/mocks/event.go | 2 +- storage/mocks/impression.go | 2 +- storage/mocks/impressionscount.go | 2 +- storage/mocks/split.go | 2 +- storage/mocks/telemetry.go | 2 +- storage/redis/events.go | 2 +- storage/redis/events_test.go | 2 +- storage/redis/helpers.go | 4 +-- storage/redis/impressions.go | 4 +-- storage/redis/impressions_test.go | 2 +- storage/redis/impressionscount.go | 4 +-- storage/redis/impressionscount_test.go | 2 +- storage/redis/redis.go | 2 +- storage/redis/redis_test.go | 2 +- storage/redis/segments.go | 2 +- storage/redis/splits.go | 6 ++-- storage/redis/splits_test.go | 6 ++-- storage/redis/telemetry.go | 6 ++-- storage/redis/telemetry_test.go | 4 +-- storage/redis/uniquekeys.go | 2 +- storage/redis/uniquekeys_test.go | 2 +- synchronizer/local.go | 16 +++++----- synchronizer/local_test.go | 12 +++---- synchronizer/manager.go | 14 ++++---- synchronizer/manager_test.go | 20 ++++++------ synchronizer/mocks/mocks.go | 2 +- synchronizer/redis_test.go | 2 +- synchronizer/synchronizer.go | 18 +++++------ synchronizer/synchronizer_test.go | 32 +++++++++---------- synchronizer/worker/event/single.go | 8 ++--- synchronizer/worker/event/single_test.go | 16 +++++----- synchronizer/worker/impression/redis.go | 2 +- synchronizer/worker/impression/redis_test.go | 4 +-- synchronizer/worker/impression/single.go | 8 ++--- synchronizer/worker/impression/single_test.go | 16 +++++----- synchronizer/worker/impressionscount/redis.go | 4 +-- .../worker/impressionscount/redis_test.go | 6 ++-- .../worker/impressionscount/single.go | 10 +++--- .../worker/impressionscount/single_test.go | 12 +++---- synchronizer/worker/segment/segment.go | 10 +++--- synchronizer/worker/segment/segment_test.go | 20 ++++++------ synchronizer/worker/split/split.go | 14 ++++---- synchronizer/worker/split/split_test.go | 22 ++++++------- tasks/cleanfiltersync.go | 2 +- tasks/cleanfiltersync_test.go | 2 +- tasks/eventsync.go | 2 +- tasks/eventsync_test.go | 10 +++--- tasks/impressionscountsync.go | 2 +- tasks/impressionscountsync_test.go | 12 +++---- tasks/impressionsync.go | 2 +- tasks/impressionsync_test.go | 12 +++---- tasks/segmentsync.go | 2 +- tasks/segmentsync_test.go | 14 ++++---- tasks/splitsync.go | 2 +- tasks/splitsync_test.go | 16 +++++----- tasks/telemetrysync.go | 2 +- tasks/telemetrysync_test.go | 8 ++--- tasks/uniquekeyssync.go | 4 +-- tasks/uniquekeyssync_test.go | 10 +++--- telemetry/constants.go | 2 +- telemetry/helpers.go | 4 +-- telemetry/helpers_test.go | 2 +- telemetry/interface.go | 2 +- telemetry/localhost.go | 2 +- telemetry/memory.go | 6 ++-- telemetry/memory_test.go | 10 +++--- telemetry/redis.go | 4 +-- telemetry/redis_test.go | 4 +-- 182 files changed, 459 insertions(+), 460 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index a153308b..acef99ae 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -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" diff --git a/engine/engine_test.go b/engine/engine_test.go index cd379dd4..d89e8887 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -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" diff --git a/engine/evaluator/evaluator.go b/engine/evaluator/evaluator.go index 22e3dcbb..7a5ef334 100644 --- a/engine/evaluator/evaluator.go +++ b/engine/evaluator/evaluator.go @@ -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" diff --git a/engine/evaluator/evaluator_test.go b/engine/evaluator/evaluator_test.go index 12eed512..61ccc615 100644 --- a/engine/evaluator/evaluator_test.go +++ b/engine/evaluator/evaluator_test.go @@ -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" diff --git a/engine/evaluator/mocks/mocks.go b/engine/evaluator/mocks/mocks.go index 77c7232f..fc343355 100644 --- a/engine/evaluator/mocks/mocks.go +++ b/engine/evaluator/mocks/mocks.go @@ -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 { diff --git a/engine/grammar/condition.go b/engine/grammar/condition.go index 07693c9f..ef51248e 100644 --- a/engine/grammar/condition.go +++ b/engine/grammar/condition.go @@ -1,9 +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/v5/engine/grammar/matchers/datatypes" + "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" ) diff --git a/engine/grammar/condition_test.go b/engine/grammar/condition_test.go index 86a8c9b8..f63ea0fc 100644 --- a/engine/grammar/condition_test.go +++ b/engine/grammar/condition_test.go @@ -3,9 +3,9 @@ package grammar import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "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" ) diff --git a/engine/grammar/matchers/allkeys_test.go b/engine/grammar/matchers/allkeys_test.go index 22a283dd..d93a14e0 100644 --- a/engine/grammar/matchers/allkeys_test.go +++ b/engine/grammar/matchers/allkeys_test.go @@ -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" ) diff --git a/engine/grammar/matchers/allofset_test.go b/engine/grammar/matchers/allofset_test.go index 18a09b50..cf74754c 100644 --- a/engine/grammar/matchers/allofset_test.go +++ b/engine/grammar/matchers/allofset_test.go @@ -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" ) diff --git a/engine/grammar/matchers/anyofset_test.go b/engine/grammar/matchers/anyofset_test.go index 846ce5b0..1a0f7a65 100644 --- a/engine/grammar/matchers/anyofset_test.go +++ b/engine/grammar/matchers/anyofset_test.go @@ -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" ) diff --git a/engine/grammar/matchers/between.go b/engine/grammar/matchers/between.go index 734f6ad4..729c92f3 100644 --- a/engine/grammar/matchers/between.go +++ b/engine/grammar/matchers/between.go @@ -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 diff --git a/engine/grammar/matchers/between_test.go b/engine/grammar/matchers/between_test.go index 697f1585..6eaf3784 100644 --- a/engine/grammar/matchers/between_test.go +++ b/engine/grammar/matchers/between_test.go @@ -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" ) diff --git a/engine/grammar/matchers/boolean_test.go b/engine/grammar/matchers/boolean_test.go index 4690beb4..8dc3bb43 100644 --- a/engine/grammar/matchers/boolean_test.go +++ b/engine/grammar/matchers/boolean_test.go @@ -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" ) diff --git a/engine/grammar/matchers/contains_test.go b/engine/grammar/matchers/contains_test.go index 5a2bc789..68dadcca 100644 --- a/engine/grammar/matchers/contains_test.go +++ b/engine/grammar/matchers/contains_test.go @@ -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" ) diff --git a/engine/grammar/matchers/dependency_test/dependency_test.go b/engine/grammar/matchers/dependency_test/dependency_test.go index 85ffa801..97e8831c 100644 --- a/engine/grammar/matchers/dependency_test/dependency_test.go +++ b/engine/grammar/matchers/dependency_test/dependency_test.go @@ -7,12 +7,12 @@ import ( "reflect" "testing" - "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" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" - "github.com/splitio/go-split-commons/v5/flagsets" - "github.com/splitio/go-split-commons/v5/storage/inmemory/mutexmap" + "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" + "github.com/splitio/go-split-commons/v6/engine/grammar/matchers" + "github.com/splitio/go-split-commons/v6/flagsets" + "github.com/splitio/go-split-commons/v6/storage/inmemory/mutexmap" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" diff --git a/engine/grammar/matchers/endswith_test.go b/engine/grammar/matchers/endswith_test.go index 71690413..e639f86e 100644 --- a/engine/grammar/matchers/endswith_test.go +++ b/engine/grammar/matchers/endswith_test.go @@ -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" ) diff --git a/engine/grammar/matchers/equalto.go b/engine/grammar/matchers/equalto.go index 03820087..78699103 100644 --- a/engine/grammar/matchers/equalto.go +++ b/engine/grammar/matchers/equalto.go @@ -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" ) // EqualToMatcher will match if two numbers or two datetimes are equal diff --git a/engine/grammar/matchers/equalto_test.go b/engine/grammar/matchers/equalto_test.go index 0c32c123..c6814d08 100644 --- a/engine/grammar/matchers/equalto_test.go +++ b/engine/grammar/matchers/equalto_test.go @@ -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" ) diff --git a/engine/grammar/matchers/equaltoset_test.go b/engine/grammar/matchers/equaltoset_test.go index 8da2a4ba..4d735dab 100644 --- a/engine/grammar/matchers/equaltoset_test.go +++ b/engine/grammar/matchers/equaltoset_test.go @@ -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" ) diff --git a/engine/grammar/matchers/gtoet.go b/engine/grammar/matchers/gtoet.go index 05716721..14426a0a 100644 --- a/engine/grammar/matchers/gtoet.go +++ b/engine/grammar/matchers/gtoet.go @@ -3,7 +3,7 @@ package matchers import ( "fmt" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "github.com/splitio/go-split-commons/v6/engine/grammar/matchers/datatypes" ) // GreaterThanOrEqualToMatcher will match if two numbers or two datetimes are equal diff --git a/engine/grammar/matchers/gtoet_test.go b/engine/grammar/matchers/gtoet_test.go index 2ee1603f..fcbd8c8e 100644 --- a/engine/grammar/matchers/gtoet_test.go +++ b/engine/grammar/matchers/gtoet_test.go @@ -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" ) diff --git a/engine/grammar/matchers/insegment.go b/engine/grammar/matchers/insegment.go index 1f869983..44f87251 100644 --- a/engine/grammar/matchers/insegment.go +++ b/engine/grammar/matchers/insegment.go @@ -3,7 +3,7 @@ package matchers import ( "fmt" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/storage" ) // InSegmentMatcher matches if the key passed is in the segment which the matcher was constructed with diff --git a/engine/grammar/matchers/insegment_test.go b/engine/grammar/matchers/insegment_test.go index 69fab4cd..f96cdb50 100644 --- a/engine/grammar/matchers/insegment_test.go +++ b/engine/grammar/matchers/insegment_test.go @@ -4,8 +4,8 @@ import ( "reflect" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/inmemory/mutexmap" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/inmemory/mutexmap" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/injection" diff --git a/engine/grammar/matchers/ltoet.go b/engine/grammar/matchers/ltoet.go index cfb0467b..fd198dc2 100644 --- a/engine/grammar/matchers/ltoet.go +++ b/engine/grammar/matchers/ltoet.go @@ -3,7 +3,7 @@ package matchers import ( "fmt" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "github.com/splitio/go-split-commons/v6/engine/grammar/matchers/datatypes" ) // LessThanOrEqualToMatcher will match if two numbers or two datetimes are equal diff --git a/engine/grammar/matchers/ltoet_test.go b/engine/grammar/matchers/ltoet_test.go index 8dcb0a50..5ea66c30 100644 --- a/engine/grammar/matchers/ltoet_test.go +++ b/engine/grammar/matchers/ltoet_test.go @@ -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" ) diff --git a/engine/grammar/matchers/matcher_test.go b/engine/grammar/matchers/matcher_test.go index d7fd33b9..3c5f3ae2 100644 --- a/engine/grammar/matchers/matcher_test.go +++ b/engine/grammar/matchers/matcher_test.go @@ -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/injection" "github.com/splitio/go-toolkit/v5/logging" diff --git a/engine/grammar/matchers/matchers.go b/engine/grammar/matchers/matchers.go index e99ae646..92ee972a 100644 --- a/engine/grammar/matchers/matchers.go +++ b/engine/grammar/matchers/matchers.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "github.com/splitio/go-split-commons/v6/dtos" + "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" diff --git a/engine/grammar/matchers/partofset_test.go b/engine/grammar/matchers/partofset_test.go index eeb4517f..afa3482c 100644 --- a/engine/grammar/matchers/partofset_test.go +++ b/engine/grammar/matchers/partofset_test.go @@ -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" ) diff --git a/engine/grammar/matchers/regex_test.go b/engine/grammar/matchers/regex_test.go index 8e168509..01badb9d 100644 --- a/engine/grammar/matchers/regex_test.go +++ b/engine/grammar/matchers/regex_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/engine/grammar/matchers/semver.go b/engine/grammar/matchers/semver.go index e8fa85b8..eeb39b36 100644 --- a/engine/grammar/matchers/semver.go +++ b/engine/grammar/matchers/semver.go @@ -3,7 +3,7 @@ package matchers import ( "fmt" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "github.com/splitio/go-split-commons/v6/engine/grammar/matchers/datatypes" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/engine/grammar/matchers/semver_test.go b/engine/grammar/matchers/semver_test.go index 43d821cc..4bf0ba26 100644 --- a/engine/grammar/matchers/semver_test.go +++ b/engine/grammar/matchers/semver_test.go @@ -7,7 +7,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" ) diff --git a/engine/grammar/matchers/startswith_test.go b/engine/grammar/matchers/startswith_test.go index 8855a09f..060e8761 100644 --- a/engine/grammar/matchers/startswith_test.go +++ b/engine/grammar/matchers/startswith_test.go @@ -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" ) diff --git a/engine/grammar/matchers/whitelist_test.go b/engine/grammar/matchers/whitelist_test.go index e8e23e46..ce0bb45e 100644 --- a/engine/grammar/matchers/whitelist_test.go +++ b/engine/grammar/matchers/whitelist_test.go @@ -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" ) diff --git a/engine/grammar/split.go b/engine/grammar/split.go index 66b04def..43e85a21 100644 --- a/engine/grammar/split.go +++ b/engine/grammar/split.go @@ -1,9 +1,9 @@ package grammar import ( - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/evaluator/impressionlabels" - "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/evaluator/impressionlabels" + "github.com/splitio/go-split-commons/v6/engine/grammar/matchers" "github.com/splitio/go-toolkit/v5/injection" "github.com/splitio/go-toolkit/v5/logging" diff --git a/engine/grammar/split_test.go b/engine/grammar/split_test.go index 6052da55..18b93434 100644 --- a/engine/grammar/split_test.go +++ b/engine/grammar/split_test.go @@ -3,8 +3,8 @@ package grammar import ( "testing" - "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-toolkit/v5/logging" ) diff --git a/engine/validator/matchers.go b/engine/validator/matchers.go index 3a804e16..688dfec5 100644 --- a/engine/validator/matchers.go +++ b/engine/validator/matchers.go @@ -1,12 +1,12 @@ package validator import ( - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/evaluator" - "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/grammar/matchers" - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers/datatypes" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/engine/evaluator" + "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/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" ) diff --git a/engine/validator/matchers_test.go b/engine/validator/matchers_test.go index 01cbd992..6dc9f8c3 100644 --- a/engine/validator/matchers_test.go +++ b/engine/validator/matchers_test.go @@ -3,9 +3,9 @@ package validator import ( "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/grammar/matchers" + "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/grammar/matchers" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/flagsets/featuresbyset.go b/flagsets/featuresbyset.go index 7773bc0b..e2b27871 100644 --- a/flagsets/featuresbyset.go +++ b/flagsets/featuresbyset.go @@ -1,6 +1,6 @@ package flagsets -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" type FeaturesBySet struct { data map[string]map[string]struct{} diff --git a/flagsets/featuresbyset_test.go b/flagsets/featuresbyset_test.go index 24e98ea6..e8251eaf 100644 --- a/flagsets/featuresbyset_test.go +++ b/flagsets/featuresbyset_test.go @@ -3,7 +3,7 @@ package flagsets import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) func TestFeaturesBySet(t *testing.T) { diff --git a/flagsets/flag_set_validator.go b/flagsets/flag_set_validator.go index daf8bdf8..7e5b844e 100644 --- a/flagsets/flag_set_validator.go +++ b/flagsets/flag_set_validator.go @@ -6,7 +6,7 @@ import ( "sort" "strings" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "golang.org/x/exp/slices" ) diff --git a/go.mod b/go.mod index cb39d0cd..eee90a9f 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,7 @@ -module github.com/splitio/go-split-commons/v5 +module github.com/splitio/go-split-commons/v6 go 1.18 -retract v5.2.0 // Version generates a breaking change and displays scan keys in a wrong way for adapters. - require ( github.com/bits-and-blooms/bloom/v3 v3.3.1 github.com/splitio/go-toolkit/v5 v5.4.0 diff --git a/provisional/impmanager.go b/provisional/impmanager.go index e00bd519..d6c8d3d0 100644 --- a/provisional/impmanager.go +++ b/provisional/impmanager.go @@ -1,8 +1,8 @@ package provisional import ( - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" ) // ImpressionManager interface diff --git a/provisional/impmanager_test.go b/provisional/impmanager_test.go index c0a1df2d..c1abca4c 100644 --- a/provisional/impmanager_test.go +++ b/provisional/impmanager_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/storage/filter" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/storage/filter" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/telemetry" ) func TestImpManagerInMemoryDebugListenerDisabled(t *testing.T) { diff --git a/provisional/strategy/debug.go b/provisional/strategy/debug.go index fb857c9e..af97bd30 100644 --- a/provisional/strategy/debug.go +++ b/provisional/strategy/debug.go @@ -1,7 +1,7 @@ package strategy import ( - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) // DebugImpl struct for debug impression mode strategy. diff --git a/provisional/strategy/debug_test.go b/provisional/strategy/debug_test.go index 0cedd13f..84f8a6a2 100644 --- a/provisional/strategy/debug_test.go +++ b/provisional/strategy/debug_test.go @@ -3,7 +3,7 @@ package strategy import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) func TestDebugMode(t *testing.T) { diff --git a/provisional/strategy/impcounter.go b/provisional/strategy/impcounter.go index a4a0b5ba..9663d973 100644 --- a/provisional/strategy/impcounter.go +++ b/provisional/strategy/impcounter.go @@ -3,7 +3,7 @@ package strategy import ( "sync" - "github.com/splitio/go-split-commons/v5/util" + "github.com/splitio/go-split-commons/v6/util" ) // Key struct for mapping each key to an amount diff --git a/provisional/strategy/imphasher.go b/provisional/strategy/imphasher.go index 56c1eed1..5875f53d 100644 --- a/provisional/strategy/imphasher.go +++ b/provisional/strategy/imphasher.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/provisional/hashing" ) diff --git a/provisional/strategy/imphasher_test.go b/provisional/strategy/imphasher_test.go index 28b1bd96..20c1afc1 100644 --- a/provisional/strategy/imphasher_test.go +++ b/provisional/strategy/imphasher_test.go @@ -3,7 +3,7 @@ package strategy import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) func TestHasher(t *testing.T) { diff --git a/provisional/strategy/impobserver.go b/provisional/strategy/impobserver.go index 0b03f7ca..7169eba9 100644 --- a/provisional/strategy/impobserver.go +++ b/provisional/strategy/impobserver.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/provisional/int64cache" ) diff --git a/provisional/strategy/impobserver_test.go b/provisional/strategy/impobserver_test.go index aa00f271..31a744cf 100644 --- a/provisional/strategy/impobserver_test.go +++ b/provisional/strategy/impobserver_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/provisional/int64cache" ) diff --git a/provisional/strategy/interfaces.go b/provisional/strategy/interfaces.go index c2c90d97..550a7b90 100644 --- a/provisional/strategy/interfaces.go +++ b/provisional/strategy/interfaces.go @@ -1,6 +1,6 @@ package strategy -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // ProcessStrategyInterface interface type ProcessStrategyInterface interface { diff --git a/provisional/strategy/none.go b/provisional/strategy/none.go index c444c651..7bfe16bd 100644 --- a/provisional/strategy/none.go +++ b/provisional/strategy/none.go @@ -3,7 +3,7 @@ package strategy import ( "time" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) // NoneImpl struct for none impression mode strategy. diff --git a/provisional/strategy/none_test.go b/provisional/strategy/none_test.go index fcd11d63..ee90b59b 100644 --- a/provisional/strategy/none_test.go +++ b/provisional/strategy/none_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/filter" - "github.com/splitio/go-split-commons/v5/util" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/filter" + "github.com/splitio/go-split-commons/v6/util" ) func TestNoneMode(t *testing.T) { diff --git a/provisional/strategy/optimized.go b/provisional/strategy/optimized.go index 986cc5c3..aca14fad 100644 --- a/provisional/strategy/optimized.go +++ b/provisional/strategy/optimized.go @@ -3,10 +3,10 @@ package strategy import ( "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" - "github.com/splitio/go-split-commons/v5/util" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" + "github.com/splitio/go-split-commons/v6/util" ) // OptimizedImpl struct for optimized impression mode strategy. diff --git a/provisional/strategy/optimized_test.go b/provisional/strategy/optimized_test.go index a4a3b0dc..27198024 100644 --- a/provisional/strategy/optimized_test.go +++ b/provisional/strategy/optimized_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/inmemory" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/inmemory" ) func TestOptimizedMode(t *testing.T) { diff --git a/provisional/strategy/uniquekeystracker.go b/provisional/strategy/uniquekeystracker.go index 3e2a68af..acae45a5 100644 --- a/provisional/strategy/uniquekeystracker.go +++ b/provisional/strategy/uniquekeystracker.go @@ -3,8 +3,8 @@ package strategy import ( "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/datastructures/set" ) diff --git a/provisional/strategy/uniquekeystracker_test.go b/provisional/strategy/uniquekeystracker_test.go index 8494decc..f2ec0992 100644 --- a/provisional/strategy/uniquekeystracker_test.go +++ b/provisional/strategy/uniquekeystracker_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/splitio/go-split-commons/v5/storage/filter" + "github.com/splitio/go-split-commons/v6/storage/filter" ) func Test(t *testing.T) { diff --git a/push/borrowed.go b/push/borrowed.go index 54ad52d1..c9b65167 100644 --- a/push/borrowed.go +++ b/push/borrowed.go @@ -1,6 +1,6 @@ package push -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // Borrowed synchronizer interface to break circular dependencies type synchronizerInterface interface { diff --git a/push/manager.go b/push/manager.go index 5c140e8d..e783555b 100644 --- a/push/manager.go +++ b/push/manager.go @@ -7,12 +7,12 @@ import ( "sync" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/sse" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api/sse" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/struct/traits/lifecycle" diff --git a/push/manager_test.go b/push/manager_test.go index 48d56ff5..15ad1bfe 100644 --- a/push/manager_test.go +++ b/push/manager_test.go @@ -6,14 +6,14 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - pushMocks "github.com/splitio/go-split-commons/v5/push/mocks" - "github.com/splitio/go-split-commons/v5/service/api/sse" - sseMocks "github.com/splitio/go-split-commons/v5/service/api/sse/mocks" - serviceMocks "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + pushMocks "github.com/splitio/go-split-commons/v6/push/mocks" + "github.com/splitio/go-split-commons/v6/service/api/sse" + sseMocks "github.com/splitio/go-split-commons/v6/service/api/sse/mocks" + serviceMocks "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" diff --git a/push/mocks/parser.go b/push/mocks/parser.go index decc0125..11a59e2c 100644 --- a/push/mocks/parser.go +++ b/push/mocks/parser.go @@ -1,7 +1,7 @@ package mocks import ( - "github.com/splitio/go-split-commons/v5/service/api/sse" + "github.com/splitio/go-split-commons/v6/service/api/sse" ) type NotificationParserMock struct { diff --git a/push/mocks/sync.go b/push/mocks/sync.go index aa7489bf..002b0fa3 100644 --- a/push/mocks/sync.go +++ b/push/mocks/sync.go @@ -1,7 +1,7 @@ package mocks import ( - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) type LocalSyncMock struct { diff --git a/push/parser.go b/push/parser.go index f0b842fa..abf64311 100644 --- a/push/parser.go +++ b/push/parser.go @@ -5,8 +5,8 @@ import ( "errors" "fmt" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service/api/sse" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service/api/sse" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/datautils" diff --git a/push/parser_test.go b/push/parser_test.go index 9115021a..651184d8 100644 --- a/push/parser_test.go +++ b/push/parser_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" sseMocks "github.com/splitio/go-toolkit/v5/sse/mocks" diff --git a/push/processor.go b/push/processor.go index f6f5cdba..8a1fed74 100644 --- a/push/processor.go +++ b/push/processor.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/push/processor_test.go b/push/processor_test.go index 0f5860ba..68127016 100644 --- a/push/processor_test.go +++ b/push/processor_test.go @@ -3,8 +3,8 @@ package push import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/push/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/push/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/push/segment.go b/push/segment.go index 64468f36..376a38b6 100644 --- a/push/segment.go +++ b/push/segment.go @@ -5,7 +5,7 @@ import ( "fmt" "sync/atomic" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/struct/traits/lifecycle" diff --git a/push/segment_test.go b/push/segment_test.go index 9d54acb5..a406dac1 100644 --- a/push/segment_test.go +++ b/push/segment_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/push/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/push/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/push/split.go b/push/split.go index 5850ff4a..67e969ff 100644 --- a/push/split.go +++ b/push/split.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/struct/traits/lifecycle" ) diff --git a/push/split_test.go b/push/split_test.go index c4d5fc3f..2e783bb7 100644 --- a/push/split_test.go +++ b/push/split_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/push/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/push/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/push/statustracker.go b/push/statustracker.go index dccfcd64..970d4330 100644 --- a/push/statustracker.go +++ b/push/statustracker.go @@ -4,9 +4,9 @@ import ( "fmt" "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/push/statustracker_test.go b/push/statustracker_test.go index 60de9fcf..0fc32e9c 100644 --- a/push/statustracker_test.go +++ b/push/statustracker_test.go @@ -3,9 +3,9 @@ package push import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/auth.go b/service/api/auth.go index d3d72fb7..61991828 100644 --- a/service/api/auth.go +++ b/service/api/auth.go @@ -3,10 +3,10 @@ package api import ( "encoding/json" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/specs" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api/specs" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/auth_test.go b/service/api/auth_test.go index a43cb074..4611c18e 100644 --- a/service/api/auth_test.go +++ b/service/api/auth_test.go @@ -6,10 +6,10 @@ import ( "net/http/httptest" "testing" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/mocks" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/client.go b/service/api/client.go index 11093738..c90ae257 100644 --- a/service/api/client.go +++ b/service/api/client.go @@ -9,9 +9,9 @@ import ( "net/http" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/client_test.go b/service/api/client_test.go index 53fda322..d2bf7b49 100644 --- a/service/api/client_test.go +++ b/service/api/client_test.go @@ -8,9 +8,9 @@ import ( "net/http/httptest" "testing" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/helpers.go b/service/api/helpers.go index 2b0c715e..a20232fe 100644 --- a/service/api/helpers.go +++ b/service/api/helpers.go @@ -1,6 +1,6 @@ package api -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" const ( splitSDKVersion = "SplitSDKVersion" diff --git a/service/api/helpers_test.go b/service/api/helpers_test.go index 333d7a2d..9f91ad9d 100644 --- a/service/api/helpers_test.go +++ b/service/api/helpers_test.go @@ -3,7 +3,7 @@ package api import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) func TestAddMetadataToHeaders(t *testing.T) { diff --git a/service/api/http_fetchers.go b/service/api/http_fetchers.go index 1929714c..d16ebe66 100644 --- a/service/api/http_fetchers.go +++ b/service/api/http_fetchers.go @@ -5,10 +5,10 @@ import ( "encoding/json" "strings" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/specs" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api/specs" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/http_fetchers_test.go b/service/api/http_fetchers_test.go index f480144b..0b812245 100644 --- a/service/api/http_fetchers_test.go +++ b/service/api/http_fetchers_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api/specs" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api/specs" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/http_recorders.go b/service/api/http_recorders.go index beee640f..cff61039 100644 --- a/service/api/http_recorders.go +++ b/service/api/http_recorders.go @@ -3,8 +3,8 @@ package api import ( "encoding/json" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/http_recorders_test.go b/service/api/http_recorders_test.go index cf2da45d..04b311fd 100644 --- a/service/api/http_recorders_test.go +++ b/service/api/http_recorders_test.go @@ -9,8 +9,8 @@ import ( "net/http/httptest" "testing" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/mocks/client.go b/service/api/mocks/client.go index 21f6668c..454e571a 100644 --- a/service/api/mocks/client.go +++ b/service/api/mocks/client.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/service" +import "github.com/splitio/go-split-commons/v6/service" // ClientMock mocks client type ClientMock struct { diff --git a/service/api/specs/splitversionfilter.go b/service/api/specs/splitversionfilter.go index 984ed8b9..aaea9b84 100644 --- a/service/api/specs/splitversionfilter.go +++ b/service/api/specs/splitversionfilter.go @@ -1,6 +1,6 @@ package specs -import "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" +import "github.com/splitio/go-split-commons/v6/engine/grammar/matchers" type SplitVersionFilter struct { excluded map[mkey]struct{} diff --git a/service/api/specs/splitversionfilter_test.go b/service/api/specs/splitversionfilter_test.go index f7503dd2..8d076783 100644 --- a/service/api/specs/splitversionfilter_test.go +++ b/service/api/specs/splitversionfilter_test.go @@ -1,8 +1,9 @@ package specs import ( - "github.com/splitio/go-split-commons/v5/engine/grammar/matchers" "testing" + + "github.com/splitio/go-split-commons/v6/engine/grammar/matchers" ) func Test_splitVersionFilter(t *testing.T) { diff --git a/service/api/split.go b/service/api/split.go index 4cc6d3eb..6c0d4271 100644 --- a/service/api/split.go +++ b/service/api/split.go @@ -1,9 +1,9 @@ package api import ( - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/api/sse/client.go b/service/api/sse/client.go index 341c27a3..45ebb2c6 100644 --- a/service/api/sse/client.go +++ b/service/api/sse/client.go @@ -4,9 +4,9 @@ import ( "errors" "strings" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service/api" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service/api" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/sse" "github.com/splitio/go-toolkit/v5/struct/traits/lifecycle" diff --git a/service/api/sse/client_test.go b/service/api/sse/client_test.go index 6b361b54..bee13ddb 100644 --- a/service/api/sse/client_test.go +++ b/service/api/sse/client_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/sse" ) diff --git a/service/api/sse/mocks/mock.go b/service/api/sse/mocks/mock.go index fe69ec36..75fe99fd 100644 --- a/service/api/sse/mocks/mock.go +++ b/service/api/sse/mocks/mock.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/service/api/sse" +import "github.com/splitio/go-split-commons/v6/service/api/sse" type StreamingClientMock struct { ConnectStreamingCall func(token string, streamingStatus chan int, channelList []string, handleIncomingMessage func(sse.IncomingMessage)) diff --git a/service/commons_test.go b/service/commons_test.go index 1991d5bb..ec940ebe 100644 --- a/service/commons_test.go +++ b/service/commons_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/splitio/go-split-commons/v5/service/api/specs" + "github.com/splitio/go-split-commons/v6/service/api/specs" "github.com/splitio/go-toolkit/v5/common" ) diff --git a/service/interfaces.go b/service/interfaces.go index 8d702bee..0199bd59 100644 --- a/service/interfaces.go +++ b/service/interfaces.go @@ -1,7 +1,7 @@ package service import ( - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) // AuthClient inteface to be implemneted by AuthClient diff --git a/service/local/sanitizer.go b/service/local/sanitizer.go index df45a5c7..38e2f5cb 100644 --- a/service/local/sanitizer.go +++ b/service/local/sanitizer.go @@ -4,7 +4,7 @@ import ( "fmt" "math/rand" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) func splitSanitization(splitChange dtos.SplitChangesDTO) *dtos.SplitChangesDTO { diff --git a/service/local/segmentFetcher.go b/service/local/segmentFetcher.go index 0c0caf15..952a7426 100644 --- a/service/local/segmentFetcher.go +++ b/service/local/segmentFetcher.go @@ -7,8 +7,8 @@ import ( "fmt" "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/local/segmentFetcher_test.go b/service/local/segmentFetcher_test.go index 45d4d91e..1311805e 100644 --- a/service/local/segmentFetcher_test.go +++ b/service/local/segmentFetcher_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/local/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/local/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/local/splitFetcher.go b/service/local/splitFetcher.go index d5b12d27..5906bf16 100644 --- a/service/local/splitFetcher.go +++ b/service/local/splitFetcher.go @@ -9,8 +9,8 @@ import ( "strings" "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" "github.com/splitio/go-toolkit/v5/logging" yaml "gopkg.in/yaml.v3" diff --git a/service/local/splitFetcher_test.go b/service/local/splitFetcher_test.go index 5353c792..1fd3b7d9 100644 --- a/service/local/splitFetcher_test.go +++ b/service/local/splitFetcher_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/local/mocks" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/local/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/service/mocks/auth.go b/service/mocks/auth.go index 1e52fd8c..015c5adb 100644 --- a/service/mocks/auth.go +++ b/service/mocks/auth.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // MockAuthClient mocked implementation of auth type MockAuthClient struct { diff --git a/service/mocks/event.go b/service/mocks/event.go index 5e28d95a..bfbf0aea 100644 --- a/service/mocks/event.go +++ b/service/mocks/event.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // MockEventRecorder mocked implementation of event recorder type MockEventRecorder struct { diff --git a/service/mocks/impression.go b/service/mocks/impression.go index 1e5a5e64..ea7252af 100644 --- a/service/mocks/impression.go +++ b/service/mocks/impression.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // MockImpressionRecorder mocked implementation of impression recorder type MockImpressionRecorder struct { diff --git a/service/mocks/segment.go b/service/mocks/segment.go index 5c78ffd2..e34b4f45 100644 --- a/service/mocks/segment.go +++ b/service/mocks/segment.go @@ -1,8 +1,8 @@ package mocks import ( - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" ) // MockSegmentFetcher mocked implementation of segment fetcher diff --git a/service/mocks/split.go b/service/mocks/split.go index d915776e..b1558eeb 100644 --- a/service/mocks/split.go +++ b/service/mocks/split.go @@ -1,8 +1,8 @@ package mocks import ( - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" ) // MockSplitFetcher mocked implementation of split fetcher diff --git a/service/mocks/telemetry.go b/service/mocks/telemetry.go index 4cffbd48..bc24d9db 100644 --- a/service/mocks/telemetry.go +++ b/service/mocks/telemetry.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // MockTelemetryRecorder mocked implementation of telemetry recorder type MockTelemetryRecorder struct { diff --git a/storage/filter/bloom_filter.go b/storage/filter/bloom_filter.go index 58c753f6..97503a84 100644 --- a/storage/filter/bloom_filter.go +++ b/storage/filter/bloom_filter.go @@ -4,7 +4,7 @@ import ( "sync" "github.com/bits-and-blooms/bloom/v3" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/storage" ) // BloomFilter description diff --git a/storage/inmemory/mutexmap/mutexmap_test.go b/storage/inmemory/mutexmap/mutexmap_test.go index 51214ca2..1d2bb08d 100644 --- a/storage/inmemory/mutexmap/mutexmap_test.go +++ b/storage/inmemory/mutexmap/mutexmap_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" ) func TestSplitMutexMapConcurrency(t *testing.T) { diff --git a/storage/inmemory/mutexmap/segments_test.go b/storage/inmemory/mutexmap/segments_test.go index 678e50e0..3ac7d20a 100644 --- a/storage/inmemory/mutexmap/segments_test.go +++ b/storage/inmemory/mutexmap/segments_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" "github.com/splitio/go-toolkit/v5/datastructures/set" ) diff --git a/storage/inmemory/mutexmap/splits.go b/storage/inmemory/mutexmap/splits.go index d077e360..228a7402 100644 --- a/storage/inmemory/mutexmap/splits.go +++ b/storage/inmemory/mutexmap/splits.go @@ -3,9 +3,9 @@ package mutexmap import ( "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/datastructures/set" ) diff --git a/storage/inmemory/mutexmap/splits_test.go b/storage/inmemory/mutexmap/splits_test.go index 8b7881b8..ece86171 100644 --- a/storage/inmemory/mutexmap/splits_test.go +++ b/storage/inmemory/mutexmap/splits_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" "github.com/splitio/go-toolkit/v5/datastructures/set" ) diff --git a/storage/inmemory/mutexqueue/events.go b/storage/inmemory/mutexqueue/events.go index 9eafe81c..84a1dcab 100644 --- a/storage/inmemory/mutexqueue/events.go +++ b/storage/inmemory/mutexqueue/events.go @@ -5,9 +5,9 @@ import ( "fmt" "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/storage/inmemory/mutexqueue/events_test.go b/storage/inmemory/mutexqueue/events_test.go index 1ca416da..73ecc1f0 100644 --- a/storage/inmemory/mutexqueue/events_test.go +++ b/storage/inmemory/mutexqueue/events_test.go @@ -4,9 +4,9 @@ import ( "strconv" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/storage/inmemory/mutexqueue/impressions.go b/storage/inmemory/mutexqueue/impressions.go index 520edc49..eaf52a3c 100644 --- a/storage/inmemory/mutexqueue/impressions.go +++ b/storage/inmemory/mutexqueue/impressions.go @@ -4,9 +4,9 @@ import ( "container/list" "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/storage/inmemory/mutexqueue/impressions_test.go b/storage/inmemory/mutexqueue/impressions_test.go index 4a663ca0..5d408ed1 100644 --- a/storage/inmemory/mutexqueue/impressions_test.go +++ b/storage/inmemory/mutexqueue/impressions_test.go @@ -4,9 +4,9 @@ import ( "strconv" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/storage/inmemory/telemetry.go b/storage/inmemory/telemetry.go index eec8d006..2e6d5ff4 100644 --- a/storage/inmemory/telemetry.go +++ b/storage/inmemory/telemetry.go @@ -6,9 +6,9 @@ import ( "sync/atomic" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" - constants "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" + constants "github.com/splitio/go-split-commons/v6/telemetry" ) type latencies struct { diff --git a/storage/inmemory/telemetry_test.go b/storage/inmemory/telemetry_test.go index 107a8ce8..fffa1c76 100644 --- a/storage/inmemory/telemetry_test.go +++ b/storage/inmemory/telemetry_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/telemetry" ) func TestTelemetryStorage(t *testing.T) { diff --git a/storage/interfaces.go b/storage/interfaces.go index 84b447fe..7d4e9f51 100644 --- a/storage/interfaces.go +++ b/storage/interfaces.go @@ -3,7 +3,7 @@ package storage import ( "time" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/datastructures/set" ) diff --git a/storage/mocks/event.go b/storage/mocks/event.go index 7e4e9e19..8e4e45cb 100644 --- a/storage/mocks/event.go +++ b/storage/mocks/event.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // MockEventStorage is a mocked implementation of Event Storage type MockEventStorage struct { diff --git a/storage/mocks/impression.go b/storage/mocks/impression.go index 44049f90..01d49313 100644 --- a/storage/mocks/impression.go +++ b/storage/mocks/impression.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // MockImpressionStorage is a mocked implementation of Impression Storage type MockImpressionStorage struct { diff --git a/storage/mocks/impressionscount.go b/storage/mocks/impressionscount.go index 77be33e8..eeb9121f 100644 --- a/storage/mocks/impressionscount.go +++ b/storage/mocks/impressionscount.go @@ -1,6 +1,6 @@ package mocks -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" type MockImpressionsCountStorage struct { RecordImpressionsCountCall func(impressions dtos.ImpressionsCountDTO) error diff --git a/storage/mocks/split.go b/storage/mocks/split.go index 75db5277..43cf1f8c 100644 --- a/storage/mocks/split.go +++ b/storage/mocks/split.go @@ -1,7 +1,7 @@ package mocks import ( - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/datastructures/set" ) diff --git a/storage/mocks/telemetry.go b/storage/mocks/telemetry.go index 6bb5080d..49032e0b 100644 --- a/storage/mocks/telemetry.go +++ b/storage/mocks/telemetry.go @@ -3,7 +3,7 @@ package mocks import ( "time" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) // MockTelemetryStorage is a mocked implementation of Telemetry Storage diff --git a/storage/redis/events.go b/storage/redis/events.go index 14346196..d31a9ef6 100644 --- a/storage/redis/events.go +++ b/storage/redis/events.go @@ -6,7 +6,7 @@ import ( "math" "sync" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/queuecache" "github.com/splitio/go-toolkit/v5/redis" diff --git a/storage/redis/events_test.go b/storage/redis/events_test.go index ee83494d..b98a5eaf 100644 --- a/storage/redis/events_test.go +++ b/storage/redis/events_test.go @@ -5,7 +5,7 @@ import ( "errors" "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" "github.com/splitio/go-toolkit/v5/redis/mocks" diff --git a/storage/redis/helpers.go b/storage/redis/helpers.go index 9a16cc04..5b59b8d6 100644 --- a/storage/redis/helpers.go +++ b/storage/redis/helpers.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" "github.com/splitio/go-toolkit/v5/redis" ) diff --git a/storage/redis/impressions.go b/storage/redis/impressions.go index 9d938c28..0e2b367d 100644 --- a/storage/redis/impressions.go +++ b/storage/redis/impressions.go @@ -5,8 +5,8 @@ import ( "sync" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" ) diff --git a/storage/redis/impressions_test.go b/storage/redis/impressions_test.go index 524691e9..3bae5c26 100644 --- a/storage/redis/impressions_test.go +++ b/storage/redis/impressions_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" "github.com/splitio/go-toolkit/v5/redis/mocks" diff --git a/storage/redis/impressionscount.go b/storage/redis/impressionscount.go index 5cfbbdb2..77b84d00 100644 --- a/storage/redis/impressionscount.go +++ b/storage/redis/impressionscount.go @@ -7,8 +7,8 @@ import ( "sync" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" ) diff --git a/storage/redis/impressionscount_test.go b/storage/redis/impressionscount_test.go index d99fa245..5a514488 100644 --- a/storage/redis/impressionscount_test.go +++ b/storage/redis/impressionscount_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" "github.com/splitio/go-toolkit/v5/redis/mocks" diff --git a/storage/redis/redis.go b/storage/redis/redis.go index f938c7b9..da1437c7 100644 --- a/storage/redis/redis.go +++ b/storage/redis/redis.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/splitio/go-split-commons/v5/conf" + "github.com/splitio/go-split-commons/v6/conf" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" ) diff --git a/storage/redis/redis_test.go b/storage/redis/redis_test.go index 323de93c..76f0528f 100644 --- a/storage/redis/redis_test.go +++ b/storage/redis/redis_test.go @@ -5,7 +5,7 @@ import ( "net" "testing" - "github.com/splitio/go-split-commons/v5/conf" + "github.com/splitio/go-split-commons/v6/conf" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/storage/redis/segments.go b/storage/redis/segments.go index 4e0d58d0..54547fc7 100644 --- a/storage/redis/segments.go +++ b/storage/redis/segments.go @@ -6,7 +6,7 @@ import ( "strings" "sync" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" diff --git a/storage/redis/splits.go b/storage/redis/splits.go index b0ff592a..150d2b44 100644 --- a/storage/redis/splits.go +++ b/storage/redis/splits.go @@ -8,9 +8,9 @@ import ( "strings" "sync" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" diff --git a/storage/redis/splits_test.go b/storage/redis/splits_test.go index 01fa8fd3..5e9ec939 100644 --- a/storage/redis/splits_test.go +++ b/storage/redis/splits_test.go @@ -8,11 +8,11 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" + "github.com/splitio/go-split-commons/v6/conf" "golang.org/x/exp/slices" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" diff --git a/storage/redis/telemetry.go b/storage/redis/telemetry.go index 90048c7e..3f699425 100644 --- a/storage/redis/telemetry.go +++ b/storage/redis/telemetry.go @@ -7,9 +7,9 @@ import ( "strings" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" ) diff --git a/storage/redis/telemetry_test.go b/storage/redis/telemetry_test.go index c79de511..f99f81c6 100644 --- a/storage/redis/telemetry_test.go +++ b/storage/redis/telemetry_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" "github.com/splitio/go-toolkit/v5/redis/mocks" diff --git a/storage/redis/uniquekeys.go b/storage/redis/uniquekeys.go index 13b36f3e..ad9afeea 100644 --- a/storage/redis/uniquekeys.go +++ b/storage/redis/uniquekeys.go @@ -3,7 +3,7 @@ package redis import ( "sync" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" ) diff --git a/storage/redis/uniquekeys_test.go b/storage/redis/uniquekeys_test.go index ef322bac..2563b8d1 100644 --- a/storage/redis/uniquekeys_test.go +++ b/storage/redis/uniquekeys_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "testing" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/redis" "github.com/splitio/go-toolkit/v5/redis/mocks" diff --git a/synchronizer/local.go b/synchronizer/local.go index b5fe587b..131f0291 100644 --- a/synchronizer/local.go +++ b/synchronizer/local.go @@ -3,14 +3,14 @@ package synchronizer import ( "time" - "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" - "github.com/splitio/go-split-commons/v5/service/api" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/segment" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/split" - "github.com/splitio/go-split-commons/v5/tasks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" + "github.com/splitio/go-split-commons/v6/healthcheck/application" + "github.com/splitio/go-split-commons/v6/service/api" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/segment" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/split" + "github.com/splitio/go-split-commons/v6/tasks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/local_test.go b/synchronizer/local_test.go index 6d6da7f6..2e7a1990 100644 --- a/synchronizer/local_test.go +++ b/synchronizer/local_test.go @@ -6,12 +6,12 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api" - httpMocks "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api" + httpMocks "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/manager.go b/synchronizer/manager.go index 843a30bc..a7642fc4 100644 --- a/synchronizer/manager.go +++ b/synchronizer/manager.go @@ -6,13 +6,13 @@ import ( "sync/atomic" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/healthcheck/application" - "github.com/splitio/go-split-commons/v5/push" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/healthcheck/application" + "github.com/splitio/go-split-commons/v6/push" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/backoff" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/struct/traits/lifecycle" diff --git a/synchronizer/manager_test.go b/synchronizer/manager_test.go index ce29dc48..c925bd67 100644 --- a/synchronizer/manager_test.go +++ b/synchronizer/manager_test.go @@ -6,16 +6,16 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/healthcheck/application" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/push" - pushMocks "github.com/splitio/go-split-commons/v5/push/mocks" - apiMocks "github.com/splitio/go-split-commons/v5/service/mocks" - storageMocks "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/healthcheck/application" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/push" + pushMocks "github.com/splitio/go-split-commons/v6/push/mocks" + apiMocks "github.com/splitio/go-split-commons/v6/service/mocks" + storageMocks "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/mocks/mocks.go b/synchronizer/mocks/mocks.go index 292ff246..183b8283 100644 --- a/synchronizer/mocks/mocks.go +++ b/synchronizer/mocks/mocks.go @@ -3,7 +3,7 @@ package mocks import ( "time" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) // MockSynchronizer mock implementation diff --git a/synchronizer/redis_test.go b/synchronizer/redis_test.go index 47086e28..85247cbb 100644 --- a/synchronizer/redis_test.go +++ b/synchronizer/redis_test.go @@ -3,7 +3,7 @@ package synchronizer import ( "testing" - "github.com/splitio/go-split-commons/v5/synchronizer/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 61c6f97e..48ae99d7 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -3,15 +3,15 @@ package synchronizer import ( "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/event" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impression" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impressionscount" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/segment" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/split" - "github.com/splitio/go-split-commons/v5/tasks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/event" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impression" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impressionscount" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/segment" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/split" + "github.com/splitio/go-split-commons/v6/tasks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index 892fd832..324cd852 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -7,22 +7,22 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/push" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/service/api" - httpMocks "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - storageMock "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/event" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impression" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/segment" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/split" - "github.com/splitio/go-split-commons/v5/tasks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/push" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/service/api" + httpMocks "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + storageMock "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/event" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impression" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/segment" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/split" + "github.com/splitio/go-split-commons/v6/tasks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" diff --git a/synchronizer/worker/event/single.go b/synchronizer/worker/event/single.go index 467e93e5..571874ee 100644 --- a/synchronizer/worker/event/single.go +++ b/synchronizer/worker/event/single.go @@ -4,10 +4,10 @@ import ( "errors" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/event/single_test.go b/synchronizer/worker/event/single_test.go index 013c4e8f..5b2e237a 100644 --- a/synchronizer/worker/event/single_test.go +++ b/synchronizer/worker/event/single_test.go @@ -10,14 +10,14 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service/api" - recorderMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "github.com/splitio/go-split-commons/v5/storage/inmemory/mutexqueue" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service/api" + recorderMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/storage/inmemory/mutexqueue" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impression/redis.go b/synchronizer/worker/impression/redis.go index 4d9fe16e..bd0a81f4 100644 --- a/synchronizer/worker/impression/redis.go +++ b/synchronizer/worker/impression/redis.go @@ -3,7 +3,7 @@ package impression import ( "errors" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impression/redis_test.go b/synchronizer/worker/impression/redis_test.go index 23c06ea0..abb591c4 100644 --- a/synchronizer/worker/impression/redis_test.go +++ b/synchronizer/worker/impression/redis_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impression/single.go b/synchronizer/worker/impression/single.go index e89012d7..720e9816 100644 --- a/synchronizer/worker/impression/single.go +++ b/synchronizer/worker/impression/single.go @@ -4,10 +4,10 @@ import ( "errors" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impression/single_test.go b/synchronizer/worker/impression/single_test.go index c67f4faf..bb8c9688 100644 --- a/synchronizer/worker/impression/single_test.go +++ b/synchronizer/worker/impression/single_test.go @@ -10,14 +10,14 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service/api" - recorderMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "github.com/splitio/go-split-commons/v5/storage/inmemory/mutexqueue" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service/api" + recorderMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/storage/inmemory/mutexqueue" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impressionscount/redis.go b/synchronizer/worker/impressionscount/redis.go index f64dffea..7ac27e74 100644 --- a/synchronizer/worker/impressionscount/redis.go +++ b/synchronizer/worker/impressionscount/redis.go @@ -1,8 +1,8 @@ package impressionscount import ( - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impressionscount/redis_test.go b/synchronizer/worker/impressionscount/redis_test.go index 402908b7..82a55e34 100644 --- a/synchronizer/worker/impressionscount/redis_test.go +++ b/synchronizer/worker/impressionscount/redis_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/storage/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/storage/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impressionscount/single.go b/synchronizer/worker/impressionscount/single.go index 21af934a..813da7e3 100644 --- a/synchronizer/worker/impressionscount/single.go +++ b/synchronizer/worker/impressionscount/single.go @@ -3,11 +3,11 @@ package impressionscount import ( "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/impressionscount/single_test.go b/synchronizer/worker/impressionscount/single_test.go index 55d90e25..dae1664a 100644 --- a/synchronizer/worker/impressionscount/single_test.go +++ b/synchronizer/worker/impressionscount/single_test.go @@ -4,12 +4,12 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/service/mocks" - st "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" - "github.com/splitio/go-split-commons/v5/util" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/service/mocks" + st "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" + "github.com/splitio/go-split-commons/v6/util" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/synchronizer/worker/segment/segment.go b/synchronizer/worker/segment/segment.go index 8e15e545..d6fc41f8 100644 --- a/synchronizer/worker/segment/segment.go +++ b/synchronizer/worker/segment/segment.go @@ -6,11 +6,11 @@ import ( "sync" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/healthcheck/application" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/healthcheck/application" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/backoff" "github.com/splitio/go-toolkit/v5/common" diff --git a/synchronizer/worker/segment/segment_test.go b/synchronizer/worker/segment/segment_test.go index 035fa59b..4d700318 100644 --- a/synchronizer/worker/segment/segment_test.go +++ b/synchronizer/worker/segment/segment_test.go @@ -8,16 +8,16 @@ import ( "testing" "time" - "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" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/service" - fetcherMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "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/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" + "github.com/splitio/go-split-commons/v6/healthcheck/application" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/service" + fetcherMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/storage/inmemory/mutexmap" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" diff --git a/synchronizer/worker/split/split.go b/synchronizer/worker/split/split.go index b21aead3..d5e8eceb 100644 --- a/synchronizer/worker/split/split.go +++ b/synchronizer/worker/split/split.go @@ -4,13 +4,13 @@ import ( "fmt" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/engine/validator" - "github.com/splitio/go-split-commons/v5/flagsets" - "github.com/splitio/go-split-commons/v5/healthcheck/application" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/engine/validator" + "github.com/splitio/go-split-commons/v6/flagsets" + "github.com/splitio/go-split-commons/v6/healthcheck/application" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/backoff" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" diff --git a/synchronizer/worker/split/split_test.go b/synchronizer/worker/split/split_test.go index f9afa415..8863023a 100644 --- a/synchronizer/worker/split/split_test.go +++ b/synchronizer/worker/split/split_test.go @@ -7,17 +7,17 @@ import ( "testing" "time" - "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/flagsets" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/service" - fetcherMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/inmemory" - "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/v5/telemetry" + "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/grammar/matchers" + "github.com/splitio/go-split-commons/v6/flagsets" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/service" + fetcherMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/inmemory" + "github.com/splitio/go-split-commons/v6/storage/inmemory/mutexmap" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/common" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/cleanfiltersync.go b/tasks/cleanfiltersync.go index 7dbc23ba..a8fafb61 100644 --- a/tasks/cleanfiltersync.go +++ b/tasks/cleanfiltersync.go @@ -1,7 +1,7 @@ package tasks import ( - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/cleanfiltersync_test.go b/tasks/cleanfiltersync_test.go index 2de68b47..00a86de4 100644 --- a/tasks/cleanfiltersync_test.go +++ b/tasks/cleanfiltersync_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - st "github.com/splitio/go-split-commons/v5/storage/mocks" + st "github.com/splitio/go-split-commons/v6/storage/mocks" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/eventsync.go b/tasks/eventsync.go index bf53c001..2a844f0d 100644 --- a/tasks/eventsync.go +++ b/tasks/eventsync.go @@ -3,7 +3,7 @@ package tasks import ( "fmt" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/event" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/event" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/eventsync_test.go b/tasks/eventsync_test.go index e0ecb142..bde2084c 100644 --- a/tasks/eventsync_test.go +++ b/tasks/eventsync_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - recorderMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/event" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + recorderMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/event" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/impressionscountsync.go b/tasks/impressionscountsync.go index ba5ba5e1..1aa58d65 100644 --- a/tasks/impressionscountsync.go +++ b/tasks/impressionscountsync.go @@ -1,7 +1,7 @@ package tasks import ( - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impressionscount" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impressionscount" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/impressionscountsync_test.go b/tasks/impressionscountsync_test.go index 7b30ff32..7e49d392 100644 --- a/tasks/impressionscountsync_test.go +++ b/tasks/impressionscountsync_test.go @@ -4,12 +4,12 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/service/mocks" - st "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impressionscount" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/service/mocks" + st "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impressionscount" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/impressionsync.go b/tasks/impressionsync.go index 7636bf04..833a133d 100644 --- a/tasks/impressionsync.go +++ b/tasks/impressionsync.go @@ -3,7 +3,7 @@ package tasks import ( "fmt" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impression" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impression" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/impressionsync_test.go b/tasks/impressionsync_test.go index 765929a4..5d8065aa 100644 --- a/tasks/impressionsync_test.go +++ b/tasks/impressionsync_test.go @@ -5,12 +5,12 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - recorderMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/impression" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + recorderMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/impression" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/segmentsync.go b/tasks/segmentsync.go index de75f0fa..8a21d6bf 100644 --- a/tasks/segmentsync.go +++ b/tasks/segmentsync.go @@ -5,7 +5,7 @@ import ( "fmt" "sync/atomic" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/segment" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/segment" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" "github.com/splitio/go-toolkit/v5/workerpool" diff --git a/tasks/segmentsync_test.go b/tasks/segmentsync_test.go index 34031db6..adeedfaa 100644 --- a/tasks/segmentsync_test.go +++ b/tasks/segmentsync_test.go @@ -5,13 +5,13 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/service" - fetcherMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/segment" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/service" + fetcherMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/segment" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/splitsync.go b/tasks/splitsync.go index d64b6f85..77e04b54 100644 --- a/tasks/splitsync.go +++ b/tasks/splitsync.go @@ -1,7 +1,7 @@ package tasks import ( - "github.com/splitio/go-split-commons/v5/synchronizer/worker/split" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/split" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/splitsync_test.go b/tasks/splitsync_test.go index 8a33d65b..882d0d94 100644 --- a/tasks/splitsync_test.go +++ b/tasks/splitsync_test.go @@ -6,14 +6,14 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/flagsets" - hcMock "github.com/splitio/go-split-commons/v5/healthcheck/mocks" - "github.com/splitio/go-split-commons/v5/service" - fetcherMock "github.com/splitio/go-split-commons/v5/service/mocks" - "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/synchronizer/worker/split" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/flagsets" + hcMock "github.com/splitio/go-split-commons/v6/healthcheck/mocks" + "github.com/splitio/go-split-commons/v6/service" + fetcherMock "github.com/splitio/go-split-commons/v6/service/mocks" + "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/synchronizer/worker/split" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/telemetrysync.go b/tasks/telemetrysync.go index 879cc051..5d53d20f 100644 --- a/tasks/telemetrysync.go +++ b/tasks/telemetrysync.go @@ -1,7 +1,7 @@ package tasks import ( - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/telemetrysync_test.go b/tasks/telemetrysync_test.go index 751c0d8e..455fff4b 100644 --- a/tasks/telemetrysync_test.go +++ b/tasks/telemetrysync_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service/mocks" - st "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service/mocks" + st "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/uniquekeyssync.go b/tasks/uniquekeyssync.go index 5611c42c..a2c2b598 100644 --- a/tasks/uniquekeyssync.go +++ b/tasks/uniquekeyssync.go @@ -1,8 +1,8 @@ package tasks import ( - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/asynctask" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/tasks/uniquekeyssync_test.go b/tasks/uniquekeyssync_test.go index 2536ee27..9046466b 100644 --- a/tasks/uniquekeyssync_test.go +++ b/tasks/uniquekeyssync_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/provisional/strategy" - "github.com/splitio/go-split-commons/v5/service/mocks" - st "github.com/splitio/go-split-commons/v5/storage/mocks" - "github.com/splitio/go-split-commons/v5/telemetry" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/provisional/strategy" + "github.com/splitio/go-split-commons/v6/service/mocks" + st "github.com/splitio/go-split-commons/v6/storage/mocks" + "github.com/splitio/go-split-commons/v6/telemetry" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/telemetry/constants.go b/telemetry/constants.go index 0506a0c2..022dc62a 100644 --- a/telemetry/constants.go +++ b/telemetry/constants.go @@ -1,7 +1,7 @@ package telemetry import ( - "github.com/splitio/go-split-commons/v5/conf" + "github.com/splitio/go-split-commons/v6/conf" ) const ( diff --git a/telemetry/helpers.go b/telemetry/helpers.go index 756cd33e..c9cf9ca6 100644 --- a/telemetry/helpers.go +++ b/telemetry/helpers.go @@ -3,8 +3,8 @@ package telemetry import ( "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" ) // GetStreamingEvent get streaming event diff --git a/telemetry/helpers_test.go b/telemetry/helpers_test.go index 8e492a8f..de7ac1f1 100644 --- a/telemetry/helpers_test.go +++ b/telemetry/helpers_test.go @@ -3,7 +3,7 @@ package telemetry import ( "testing" - "github.com/splitio/go-split-commons/v5/conf" + "github.com/splitio/go-split-commons/v6/conf" ) func TestGetURLOVerrides(t *testing.T) { diff --git a/telemetry/interface.go b/telemetry/interface.go index 4c34e847..ca6e0b13 100644 --- a/telemetry/interface.go +++ b/telemetry/interface.go @@ -1,6 +1,6 @@ package telemetry -import "github.com/splitio/go-split-commons/v5/dtos" +import "github.com/splitio/go-split-commons/v6/dtos" // TelemetrySynchronizer interface type TelemetrySynchronizer interface { diff --git a/telemetry/localhost.go b/telemetry/localhost.go index 545a1332..fb95d74c 100644 --- a/telemetry/localhost.go +++ b/telemetry/localhost.go @@ -1,7 +1,7 @@ package telemetry import ( - "github.com/splitio/go-split-commons/v5/dtos" + "github.com/splitio/go-split-commons/v6/dtos" ) type NoOp struct{} diff --git a/telemetry/memory.go b/telemetry/memory.go index 4f9f7dde..f7fa3d1d 100644 --- a/telemetry/memory.go +++ b/telemetry/memory.go @@ -5,9 +5,9 @@ import ( "strings" "time" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/telemetry/memory_test.go b/telemetry/memory_test.go index 48769637..850957ab 100644 --- a/telemetry/memory_test.go +++ b/telemetry/memory_test.go @@ -9,11 +9,11 @@ import ( "testing" "time" - "github.com/splitio/go-split-commons/v5/conf" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/service/api" - "github.com/splitio/go-split-commons/v5/service/mocks" - st "github.com/splitio/go-split-commons/v5/storage/mocks" + "github.com/splitio/go-split-commons/v6/conf" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/service/api" + "github.com/splitio/go-split-commons/v6/service/mocks" + st "github.com/splitio/go-split-commons/v6/storage/mocks" "github.com/splitio/go-toolkit/v5/datastructures/set" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/telemetry/redis.go b/telemetry/redis.go index 587b83fe..fb63cee5 100644 --- a/telemetry/redis.go +++ b/telemetry/redis.go @@ -1,8 +1,8 @@ package telemetry import ( - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage" "github.com/splitio/go-toolkit/v5/logging" ) diff --git a/telemetry/redis_test.go b/telemetry/redis_test.go index e02650f3..b6b9c288 100644 --- a/telemetry/redis_test.go +++ b/telemetry/redis_test.go @@ -3,8 +3,8 @@ package telemetry import ( "testing" - "github.com/splitio/go-split-commons/v5/dtos" - "github.com/splitio/go-split-commons/v5/storage/mocks" + "github.com/splitio/go-split-commons/v6/dtos" + "github.com/splitio/go-split-commons/v6/storage/mocks" "github.com/splitio/go-toolkit/v5/logging" ) From 150ade638cf847a400e60c9feda40cdc93b21dbd Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Tue, 14 May 2024 13:55:26 -0300 Subject: [PATCH 56/56] Update changelog --- CHANGES | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 09bbeff8..e27f5438 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ -6.X.X ( XX, 2024) -- Changed FetchOptions and Fetch API. +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.