Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Flagsets -- Base branch #243

Merged
merged 38 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
50b6d68
pointed to flagSet redis storage support
mmelograno Aug 31, 2023
9ed4ca5
added flagSetsFilter for producer
mmelograno Oct 4, 2023
afcffa2
add historic storage for keeping track of flagsets
mredolatti Oct 17, 2023
dee7ebc
update images
mredolatti Oct 17, 2023
f2a7a49
fixes & more test
mredolatti Oct 19, 2023
88b12f0
prepare base branch for flagsets project
mredolatti Oct 19, 2023
15857e3
bump go version in docker images
mredolatti Oct 19, 2023
7dbd8cc
bump runner stage alpine version
mredolatti Oct 19, 2023
a1e8ff7
Merge branch 'project/flagsets' into feat/proxy_flagset_optimized_sto…
mredolatti Oct 19, 2023
353237e
Merge pull request #242 from splitio/feat/proxy_flagset_optimized_sto…
mredolatti Oct 19, 2023
03a9105
Merge branch 'project/flagsets' into task/flagSet
ldecheverz-split Oct 24, 2023
30983e0
no message
ldecheverz-split Oct 24, 2023
4867a2d
wip
mredolatti Oct 31, 2023
bf63315
Merge pull request #244 from splitio/task/flagSet
mredolatti Nov 7, 2023
bd5e350
Adding new methods
ldecheverz-split Nov 9, 2023
fd643a5
Merge pull request #249 from splitio/flagset-telemetry
ldecheverz-split Nov 9, 2023
de4a57d
Adding flagsets on hash
ldecheverz-split Nov 10, 2023
ef035eb
controller wip
mredolatti Nov 11, 2023
c114120
Merge remote-tracking branch 'origin/project/flagsets' into task/sdk-…
mredolatti Nov 11, 2023
12fd3b0
more uts, enable integration
mredolatti Nov 11, 2023
76010ef
remove unnecessary todo
mredolatti Nov 11, 2023
e56a541
handle empty sets
mredolatti Nov 12, 2023
6e26721
Merge pull request #250 from splitio/sets-hashing-clear
ldecheverz-split Nov 13, 2023
0cd1a69
Moving log attempts
ldecheverz-split Nov 15, 2023
b6b17e0
Merge pull request #252 from splitio/move-log-attempts
ldecheverz-split Nov 15, 2023
3d3bf05
Merge remote-tracking branch 'origin/project/flagsets' into task/sdk-…
mredolatti Nov 27, 2023
d119f8d
Adding telemetry init
ldecheverz-split Nov 29, 2023
0318306
Merge pull request #256 from splitio/telemetry-init-config
ldecheverz-split Nov 29, 2023
5b22e14
more controller work
mredolatti Nov 30, 2023
0484f05
Merge remote-tracking branch 'origin/project/flagsets' into task/sdk-…
mredolatti Nov 30, 2023
5b37ef1
test split removal
mredolatti Nov 30, 2023
ab424cc
polishing
mredolatti Dec 4, 2023
ddc168e
Merge pull request #251 from splitio/task/sdk-controller-fagsets
mredolatti Dec 4, 2023
f10ddf1
polishing
mredolatti Dec 5, 2023
fccb322
Merge remote-tracking branch 'origin/project/flagsets' into project/f…
mredolatti Dec 5, 2023
cf3da63
prepare for release
mredolatti Dec 6, 2023
6daf2c0
merge with master
mredolatti Dec 6, 2023
a28a70c
update CHANGELOG date
mredolatti Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
5.5.0 (Dec 12, 2023)
- Added support for Flag Sets on Split Proxy and Synchronizer, which enables SDKs to interacting with the flag sets features (more details in our documentation):
- Updated Proxy endpoints used by SDKs to fetch flags have been updated to handle any SDKs downloading flags in certain flag sets.
- Updated Syncrhonizer to properly handle flagsets in redis.
- Added configuration options to specify which flagsets to use as a filter when downloading flag definitions. Please refer to our docs to learn more

5.4.2 (Nov 7, 2023)
- Updated docker images for vulnerability fixes.
- Updated dependencies for vulnerability fixes.
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ images_release: # entrypoints
go.sum: go.mod
$(GO) mod tidy

coverage.out: test_coverage

# because of windows .exe suffix, we need a macro on the right side, which needs to be executed
# after the `%` evaluation, therefore, in a second expansion
.SECONDEXPANSION:
Expand Down
14 changes: 11 additions & 3 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func setupConfig(cliArgs *cconf.CliFlags) (*conf.Main, error) {
}

cconf.PopulateFromArguments(&proxyConf, cliArgs.RawConfig)
return &proxyConf, nil

var err error
proxyConf.FlagSetsFilter, err = cconf.ValidateFlagsets(proxyConf.FlagSetsFilter)
return &proxyConf, err
}

func main() {
Expand All @@ -57,8 +60,13 @@ func main() {

cfg, err := setupConfig(cliArgs)
if err != nil {
fmt.Println("error processing config: ", err)
os.Exit(exitCodeConfigError)
var fsErr cconf.FlagSetValidationError
if errors.As(err, &fsErr) {
fmt.Println("error processing flagsets: ", err.Error())
} else {
fmt.Println("error processing config: ", err)
os.Exit(exitCodeConfigError)
}
}

logger := log.BuildFromConfig(&cfg.Logging, "Split-Proxy", &cfg.Integrations.Slack)
Expand Down
14 changes: 11 additions & 3 deletions cmd/synchronizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func setupConfig(cliArgs *cconf.CliFlags) (*conf.Main, error) {
}

cconf.PopulateFromArguments(&syncConf, cliArgs.RawConfig)
return &syncConf, nil

var err error
syncConf.FlagSetsFilter, err = cconf.ValidateFlagsets(syncConf.FlagSetsFilter)
return &syncConf, err
}

func main() {
Expand All @@ -57,8 +60,13 @@ func main() {

cfg, err := setupConfig(cliArgs)
if err != nil {
fmt.Println("error processing config: ", err)
os.Exit(exitCodeConfigError)
var fsErr cconf.FlagSetValidationError
if errors.As(err, &fsErr) {
fmt.Println("error processing flagset: ", err.Error())
} else {
fmt.Println("error processing config: ", err)
os.Exit(exitCodeConfigError)
}
}

logger := log.BuildFromConfig(&cfg.Logging, "Split-Sync", &cfg.Integrations.Slack)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ require (
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.3.0
github.com/splitio/gincache v1.0.1
github.com/splitio/go-split-commons/v5 v5.0.0
github.com/splitio/go-toolkit/v5 v5.3.1
github.com/stretchr/testify v1.8.3
github.com/splitio/go-split-commons/v5 v5.1.0
github.com/splitio/go-toolkit/v5 v5.3.2
github.com/stretchr/testify v1.8.4
go.etcd.io/bbolt v1.3.6
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)

require (
Expand All @@ -28,7 +29,6 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -90,10 +90,10 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/splitio/gincache v1.0.1 h1:dLYdANY/BqH4KcUMCe/LluLyV5WtuE/LEdQWRE06IXU=
github.com/splitio/gincache v1.0.1/go.mod h1:CcgJDSM9Af75kyBH0724v55URVwMBuSj5x1eCWIOECY=
github.com/splitio/go-split-commons/v5 v5.0.0 h1:bGRi0cf1JP5VNSi0a4BPQEWv/DACkeSKliazhPMVDPk=
github.com/splitio/go-split-commons/v5 v5.0.0/go.mod h1:lzoVmYJaCqB8UPSxWva0BZe7fF+bRJD+eP0rNi/lL7c=
github.com/splitio/go-toolkit/v5 v5.3.1 h1:9J/byd0fRxWj5/Zg0QZOnUxKBDIAMCGr7rySYzJKdJg=
github.com/splitio/go-toolkit/v5 v5.3.1/go.mod h1:xYhUvV1gga9/1029Wbp5pjnR6Cy8nvBpjw99wAbsMko=
github.com/splitio/go-split-commons/v5 v5.1.0 h1:mki1235gjXwuxcXdv/bKVduX1Lv09uXJogds+BspqSM=
github.com/splitio/go-split-commons/v5 v5.1.0/go.mod h1:9vAZrlhKvhensyRC11hyVFdgLIBrkX9D5vdYc9qB13w=
github.com/splitio/go-toolkit/v5 v5.3.2 h1:Yy9YBcHRmK5WVZjeA/klLGEdF38xpsL1ejnC3ro8a2M=
github.com/splitio/go-toolkit/v5 v5.3.2/go.mod h1:xYhUvV1gga9/1029Wbp5pjnR6Cy8nvBpjw99wAbsMko=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
Expand All @@ -105,8 +105,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
Expand All @@ -123,6 +124,8 @@ golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
Expand All @@ -143,7 +146,6 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Expand Down
2 changes: 1 addition & 1 deletion splitio/commitversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ This file is created automatically, please do not edit
*/

// CommitVersion is the version of the last commit previous to release
const CommitVersion = "2db6c6e"
const CommitVersion = "cf3da63"
28 changes: 28 additions & 0 deletions splitio/common/conf/validators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package conf

import (
"strings"

"github.com/splitio/go-split-commons/v5/flagsets"
)

type FlagSetValidationError struct {
wrapped []error
}

func (f FlagSetValidationError) Error() string {
var errors []string
for _, err := range f.wrapped {
errors = append(errors, err.Error())
}
return strings.Join(errors, ".|| ")
}

func ValidateFlagsets(sets []string) ([]string, error) {
var toRet error
sanitizedFlagSets, fsErr := flagsets.SanitizeMany(sets)
if fsErr != nil {
toRet = FlagSetValidationError{wrapped: fsErr}
}
return sanitizedFlagSets, toRet
}
24 changes: 24 additions & 0 deletions splitio/common/conf/validators_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package conf

import (
"testing"

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

func TestFlagSetValidationError(t *testing.T) {

sanitized, err := ValidateFlagsets([]string{"Flagset1", " flagset2 ", "123#@flagset"})
assert.NotNil(t, err)
assert.Equal(t, []string{"flagset1", "flagset2"}, sanitized)

asFVE := err.(FlagSetValidationError)
assert.Equal(t, 3, len(asFVE.wrapped))
assert.ElementsMatch(t, []error{
dtos.FlagSetValidatonError{Message: "Flag Set name Flagset1 should be all lowercase - converting string to lowercase"},
dtos.FlagSetValidatonError{Message: "Flag Set name flagset2 has extra whitespace, trimming"},
dtos.FlagSetValidatonError{Message: "you passed 123#@flagset, Flag Set must adhere to the regular expressions ^[a-z0-9][_a-z0-9]{0,49}$. This means a Flag Set must " +
"start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. 123#@flagset was discarded."},
}, asFVE.wrapped)
}
1 change: 1 addition & 0 deletions splitio/producer/conf/sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type Main struct {
Apikey string `json:"apikey" s-cli:"apikey" s-def:"" s-desc:"Split server side SDK key"`
IPAddressEnabled bool `json:"ipAddressEnabled" s-cli:"ip-address-enabled" s-def:"true" s-desc:"Bundle host's ip address when sending data to Split"`
FlagSetsFilter []string `json:"flagSetsFilter" s-cli:"flag-sets-filter" s-def:"" s-desc:"Flag Sets Filter provided"`
Initialization Initialization `json:"initialization" s-nested:"true"`
Storage Storage `json:"storage" s-nested:"true"`
Sync Sync `json:"sync" s-nested:"true"`
Expand Down
9 changes: 7 additions & 2 deletions splitio/producer/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

cconf "github.com/splitio/go-split-commons/v5/conf"
"github.com/splitio/go-split-commons/v5/dtos"
"github.com/splitio/go-split-commons/v5/flagsets"
"github.com/splitio/go-split-commons/v5/provisional/strategy"
"github.com/splitio/go-split-commons/v5/service/api"
"github.com/splitio/go-split-commons/v5/storage/filter"
Expand Down Expand Up @@ -46,6 +47,7 @@ const (
func Start(logger logging.LoggerInterface, cfg *conf.Main) error {
// Getting initial config data
advanced := cfg.BuildAdvancedConfig()
advanced.FlagSetsFilter = cfg.FlagSetsFilter
metadata := util.GetMetadata(false, cfg.IPAddressEnabled)

clientKey, err := util.GetClientKey(cfg.Apikey)
Expand Down Expand Up @@ -84,8 +86,11 @@ func Start(logger logging.LoggerInterface, cfg *conf.Main) error {
syncTelemetryStorage, _ := inmemory.NewTelemetryStorage()
sdkTelemetryStorage := storage.NewRedisTelemetryCosumerclient(redisClient, logger)

// FlagSetsFilter
flagSetsFilter := flagsets.NewFlagSetFilter(cfg.FlagSetsFilter)

// These storages are forwarded to the dashboard, the sdk-telemetry is irrelevant there
splitStorage, err := observability.NewObservableSplitStorage(redis.NewSplitStorage(redisClient, logger), logger)
splitStorage, err := observability.NewObservableSplitStorage(redis.NewSplitStorage(redisClient, logger, flagSetsFilter), logger)
if err != nil {
return fmt.Errorf("error instantiating observable feature flag storage: %w", err)
}
Expand Down Expand Up @@ -118,7 +123,7 @@ func Start(logger logging.LoggerInterface, cfg *conf.Main) error {
eventEvictionMonitor := evcalc.New(1)

workers := synchronizer.Workers{
SplitUpdater: split.NewSplitUpdater(storages.SplitStorage, splitAPI.SplitFetcher, logger, syncTelemetryStorage, appMonitor),
SplitUpdater: split.NewSplitUpdater(storages.SplitStorage, splitAPI.SplitFetcher, logger, syncTelemetryStorage, appMonitor, flagSetsFilter),
SegmentUpdater: segment.NewSegmentUpdater(storages.SplitStorage, storages.SegmentStorage, splitAPI.SegmentFetcher,
logger, syncTelemetryStorage, appMonitor),
ImpressionsCountRecorder: impressionscount.NewRecorderSingle(impressionsCounter, splitAPI.ImpressionRecorder,
Expand Down
54 changes: 54 additions & 0 deletions splitio/producer/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http"
"net/http/httptest"
"os"
"strconv"
"strings"
"testing"

config "github.com/splitio/go-split-commons/v5/conf"
Expand Down Expand Up @@ -198,6 +200,58 @@ func TestSanitizeRedisWithRedisDifferentApiKey(t *testing.T) {
redisClient.Del("SPLITIO.test1")
}

func TestSanitizeRedisWithForcedCleanupByFlagSets(t *testing.T) {
cfg := getDefaultConf()
cfg.Apikey = "983564etyrudhijfgknf9i08euh"
cfg.Initialization.ForceFreshStartup = true
cfg.FlagSetsFilter = []string{"flagset1", "flagset2"}

hash := util.HashAPIKey(cfg.Apikey + strings.Join(cfg.FlagSetsFilter, "::"))

logger := logging.NewLogger(nil)

redisClient, err := predis.NewRedisClient(&config.RedisConfig{
Host: "localhost",
Port: 6379,
Prefix: "some_prefix",
Database: 1,
}, logger)
if err != nil {
t.Error("It should be nil")
}

err = redisClient.Set("SPLITIO.test1", "123", 0)
redisClient.Set("SPLITIO.hash", hash, 0)
if err != nil {
t.Error("It should be nil")
}
value, err := redisClient.Get("SPLITIO.test1")
if value != "123" {
t.Error("Value should have been set properly")
}

cfg.FlagSetsFilter = []string{"flagset7"}
miscStorage := predis.NewMiscStorage(redisClient, logger)
value, err = redisClient.Get("SPLITIO.test1")
err = sanitizeRedis(cfg, miscStorage, logger)
if err != nil {
t.Error("It should be nil", err)
}

value, _ = redisClient.Get("SPLITIO.test1")
if value != "" {
t.Error("Value should have been removed.")
}

val, _ := redisClient.Get("SPLITIO.hash")
parsedHash, _ := strconv.ParseUint(val, 10, 64)
if uint32(parsedHash) == hash {
t.Error("ApiHash should have been updated.")
}
redisClient.Del("SPLITIO.hash")
redisClient.Del("SPLITIO.test1")
}

func getDefaultConf() *conf.Main {
var c conf.Main
cconf.PopulateDefaults(&c)
Expand Down
30 changes: 25 additions & 5 deletions splitio/producer/storage/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ func setLatency(result MultiMethodLatencies, metadata *dtos.Metadata, method str

if _, ok := result[*metadata]; !ok {
result[*metadata] = dtos.MethodLatencies{
Treatment: make([]int64, telemetry.LatencyBucketCount),
Treatments: make([]int64, telemetry.LatencyBucketCount),
TreatmentWithConfig: make([]int64, telemetry.LatencyBucketCount),
TreatmentsWithConfig: make([]int64, telemetry.LatencyBucketCount),
Track: make([]int64, telemetry.LatencyBucketCount),
Treatment: make([]int64, telemetry.LatencyBucketCount),
Treatments: make([]int64, telemetry.LatencyBucketCount),
TreatmentWithConfig: make([]int64, telemetry.LatencyBucketCount),
TreatmentsWithConfig: make([]int64, telemetry.LatencyBucketCount),
TreatmentsByFlagSet: make([]int64, telemetry.LatencyBucketCount),
TreatmentsByFlagSets: make([]int64, telemetry.LatencyBucketCount),
TreatmentsWithConfigByFlagSet: make([]int64, telemetry.LatencyBucketCount),
TreatmentsWithConfigByFlagSets: make([]int64, telemetry.LatencyBucketCount),
Track: make([]int64, telemetry.LatencyBucketCount),
}
}

Expand All @@ -194,6 +198,14 @@ func setLatency(result MultiMethodLatencies, metadata *dtos.Metadata, method str
result[*metadata].TreatmentWithConfig[bucket] = count
case telemetry.TreatmentsWithConfig:
result[*metadata].TreatmentsWithConfig[bucket] = count
case telemetry.TreatmentsByFlagSet:
result[*metadata].TreatmentsByFlagSet[bucket] = count
case telemetry.TreatmentsByFlagSets:
result[*metadata].TreatmentsByFlagSets[bucket] = count
case telemetry.TreatmentsWithConfigByFlagSet:
result[*metadata].TreatmentsWithConfigByFlagSet[bucket] = count
case telemetry.TreatmentsWithConfigByFlagSets:
result[*metadata].TreatmentsWithConfigByFlagSets[bucket] = count
case telemetry.Track:
result[*metadata].Track[bucket] = count
default:
Expand Down Expand Up @@ -232,6 +244,14 @@ func setException(result MultiMethodExceptions, metadata *dtos.Metadata, method
curr.TreatmentWithConfig = count
case telemetry.TreatmentsWithConfig:
curr.TreatmentsWithConfig = count
case telemetry.TreatmentsByFlagSet:
curr.TreatmentsByFlagSet = count
case telemetry.TreatmentsByFlagSets:
curr.TreatmentsByFlagSets = count
case telemetry.TreatmentsWithConfigByFlagSet:
curr.TreatmentsWithConfigByFlagSet = count
case telemetry.TreatmentsWithConfigByFlagSets:
curr.TreatmentsWithConfigByFlagSets = count
case telemetry.Track:
curr.Track = count
default:
Expand Down
Loading