-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat(segment-manager): Adds implementation for ODPSegmentManager #353
Changes from 1 commit
11c17ed
85ae342
0193ad0
60a1a78
d76e74c
303e50d
2e2b804
e283e8e
b97aab1
1c3a3ec
4b5cb0c
960fc07
dc881db
e9ad97b
fed7ebe
e558d03
5b94bc8
18faec2
9e82b09
d55cf26
cdf8385
be5e080
7dc9c44
201eacc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,42 +23,28 @@ import ( | |
"github.com/optimizely/go-sdk/pkg/odp/utils" | ||
) | ||
|
||
// ConfigState is used to represent state of odp | ||
type ConfigState int64 | ||
|
||
const ( | ||
// NotDetermined represents that odp service state is currently not determined | ||
NotDetermined ConfigState = iota | ||
// Integrated represents that odp service is integrated | ||
Integrated | ||
// NotIntegrated represents that odp service is not integrated | ||
NotIntegrated | ||
) | ||
|
||
// Config is used to represent odp config | ||
type Config interface { | ||
Update(apiKey, apiHost string, segmentsToCheck []string) bool | ||
GetAPIKey() string | ||
GetAPIHost() string | ||
GetSegmentsToCheck() []string | ||
IsEventQueueingAllowed() bool | ||
IsOdpServiceIntegrated() bool | ||
} | ||
|
||
// DefaultConfig represents default implementation of odp config | ||
type DefaultConfig struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i need to check name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couldn't name this |
||
apiKey, apiHost string | ||
segmentsToCheck []string | ||
odpServiceIntegrated ConfigState | ||
lock sync.RWMutex | ||
apiKey, apiHost string | ||
segmentsToCheck []string | ||
lock sync.RWMutex | ||
} | ||
|
||
// NewConfig creates and returns a new instance of DefaultConfig. | ||
func NewConfig(apiKey, apiHost string, segmentsToCheck []string) *DefaultConfig { | ||
return &DefaultConfig{ | ||
apiKey: apiKey, | ||
apiHost: apiHost, | ||
segmentsToCheck: segmentsToCheck, | ||
odpServiceIntegrated: NotDetermined, // initially queueing allowed until the first datafile is parsed | ||
apiKey: apiKey, | ||
apiHost: apiHost, | ||
segmentsToCheck: segmentsToCheck, | ||
} | ||
} | ||
|
||
|
@@ -67,12 +53,6 @@ func (s *DefaultConfig) Update(apiKey, apiHost string, segmentsToCheck []string) | |
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
// disable future event queueing if datafile has no ODP integrations. | ||
s.odpServiceIntegrated = NotIntegrated | ||
if apiKey != "" && apiHost != "" { | ||
s.odpServiceIntegrated = Integrated | ||
} | ||
|
||
if s.apiKey == apiKey && s.apiHost == apiHost && utils.Equal(s.segmentsToCheck, segmentsToCheck) { | ||
return false | ||
} | ||
|
@@ -108,13 +88,7 @@ func (s *DefaultConfig) GetSegmentsToCheck() []string { | |
return segmentsToCheck | ||
} | ||
|
||
// IsEventQueueingAllowed returns true if event queueing is allowed | ||
func (s *DefaultConfig) IsEventQueueingAllowed() bool { | ||
s.lock.RLock() | ||
defer s.lock.RUnlock() | ||
value := true | ||
if s.odpServiceIntegrated == NotIntegrated { | ||
value = false | ||
} | ||
return value | ||
// IsOdpServiceIntegrated returns true if odp service is integrated | ||
func (s *DefaultConfig) IsOdpServiceIntegrated() bool { | ||
return s.GetAPIHost() != "" && s.GetAPIKey() != "" | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ import ( | |||||||||||||||
|
||||||||||||||||
// SegmentManager represents the odp segment manager. | ||||||||||||||||
type SegmentManager interface { | ||||||||||||||||
FetchQualifiedSegments(userKey, userValue string, options []SegmentOption) (segments []string, err error) | ||||||||||||||||
FetchQualifiedSegments(userKey, userValue string, options []OptimizelySegmentOption) (segments []string, err error) | ||||||||||||||||
Reset() | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -37,11 +37,14 @@ type DefaultSegmentManager struct { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// NewSegmentManager creates and returns a new instance of DefaultSegmentManager. | ||||||||||||||||
func NewSegmentManager(cacheSize int, cacheTimeoutInSecs int64, odpConfig Config, apiManager SegmentAPIManager) *DefaultSegmentManager { | ||||||||||||||||
func NewSegmentManager(cache Cache, cacheSize int, cacheTimeoutInSecs int64, odpConfig Config, apiManager SegmentAPIManager) *DefaultSegmentManager { | ||||||||||||||||
segmentManager := DefaultSegmentManager{ | ||||||||||||||||
odpConfig: odpConfig, | ||||||||||||||||
segmentAPIManager: apiManager, | ||||||||||||||||
segmentsCache: NewLRUCache(cacheSize, cacheTimeoutInSecs), | ||||||||||||||||
segmentsCache: cache, | ||||||||||||||||
} | ||||||||||||||||
if segmentManager.segmentsCache == nil { | ||||||||||||||||
segmentManager.segmentsCache = NewLRUCache(cacheSize, cacheTimeoutInSecs) | ||||||||||||||||
} | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. golang does not support ternary operators such as |
||||||||||||||||
if segmentManager.odpConfig == nil { | ||||||||||||||||
segmentManager.odpConfig = NewConfig("", "", nil) | ||||||||||||||||
|
@@ -53,8 +56,8 @@ func NewSegmentManager(cacheSize int, cacheTimeoutInSecs int64, odpConfig Config | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// FetchQualifiedSegments fetches and returns qualified segments | ||||||||||||||||
func (s *DefaultSegmentManager) FetchQualifiedSegments(userKey, userValue string, options []SegmentOption) (segments []string, err error) { | ||||||||||||||||
if s.odpConfig == nil || s.odpConfig.GetAPIHost() == "" || s.odpConfig.GetAPIKey() == "" { | ||||||||||||||||
func (s *DefaultSegmentManager) FetchQualifiedSegments(userKey, userValue string, options []OptimizelySegmentOption) (segments []string, err error) { | ||||||||||||||||
if s.odpConfig == nil || !s.odpConfig.IsOdpServiceIntegrated() { | ||||||||||||||||
return nil, fmt.Errorf(fetchSegmentsFailedError, "apiKey/apiHost not defined") | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to differentiate cloning vs new context creation (so we can send IdenfityUser event only for the first creation not for cloing). We can keep it as is and fix it later when we work on the top-level integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what change you made for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be adding this in a separate PR which will be focused on integrating
odpManager
inuserContext
.