-
Notifications
You must be signed in to change notification settings - Fork 19
feat(event-manager): Adds implementation for ODPEventManager #354
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
Conversation
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.
Looks great! A few small changes suggested.
pkg/odp/event_manager.go
Outdated
const DefaultEventQueueSize = 10000 | ||
|
||
// DefaultEventFlushInterval holds the default value for the event flush interval | ||
const DefaultEventFlushInterval = 30 * time.Second |
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.
const DefaultEventFlushInterval = 30 * time.Second | |
const DefaultEventFlushInterval = 1 * time.Second |
Consistent (flush interval = 1sec) with other SDKs
pkg/odp/event_manager.go
Outdated
odpEvent.Data["idempotence_id"] = guuid.New().String() | ||
odpEvent.Data["data_source_type"] = "sdk" | ||
odpEvent.Data["data_source"] = event.ClientName | ||
odpEvent.Data["data_source_version"] = event.Version |
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.
Client-provided data has higher priority if it has key-conflict with common-data.
For example, if "data_source" data provided in the data, it should not be overwritten to "go-sdk".
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.
Can we have a unit test to cover this case?
pkg/utils/utils.go
Outdated
if len(a) != len(b) { | ||
return false | ||
} | ||
for i, v := range a { |
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.
This will return false for same array values with different order. Wondering if we're ok for all use cases.
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.
good catch, fixing 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.
LGTM
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.
lgtm. some minor nits. please address before merge.
pkg/odp/event_api_manager.go
Outdated
func (s *DefaultEventAPIManager) SendODPEvents(config Config, events []Event) (canRetry bool, err error) { | ||
|
||
// Creating request | ||
apiEndpoint := config.GetAPIHost() + eventsAPIEndpointPath |
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.
use fmt.Sprintf
pkg/odp/event_api_manager.go
Outdated
|
||
// Creating request | ||
apiEndpoint := config.GetAPIHost() + eventsAPIEndpointPath | ||
headers := []utils.Header{{Name: "Content-Type", Value: "application/json"}, {Name: ODPAPIKeyHeader, Value: config.GetAPIKey()}} |
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.
add these as const
|
||
// Start does not do any initialization, just starts the ticker | ||
func (bm *BatchEventManager) Start(ctx context.Context) { | ||
if !bm.IsOdpServiceIntegrated() { |
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.
I think this should be ready? please check in other sdks.
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.
This is similar to odpServiceIntegrated
property in swift-sdk
pkg/odp/segment_api_manager.go
Outdated
// Creating request | ||
apiEndpoint := config.GetAPIHost() + "/v3/graphql" | ||
headers := []utils.Header{{Name: "Content-Type", Value: "application/json"}, {Name: "x-api-key", Value: config.GetAPIKey()}} | ||
apiEndpoint := config.GetAPIHost() + graphqlAPIEndpointPath |
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.
fmt
s.NoError(err) | ||
s.Empty(segments, "none of the test segments in the live ODP server") | ||
} | ||
// func (s *SegmentAPIManagerTestSuite) TestLiveOdpGraphQL() { |
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.
is this intentional?
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.
Yes, have put these here for debug purposes similar to swift-sdk
pkg/odp/segment_manager.go
Outdated
) | ||
|
||
// SMOptionConfig are the SegmentManager options that give you the ability to add one more more options before the segment manager is initialized. | ||
type SMOptionConfig func(em *DefaultSegmentManager) |
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.
shouldn't this be SMConfigOptions
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.
Changing it into SMOptionFunc
which is in sync with the older options in the sdk.
|
||
func TestCompareSlices(t *testing.T) { | ||
assert.True(t, CompareSlices(nil, nil)) | ||
assert.True(t, CompareSlices([]string{}, []string{})) |
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.
can you try
make and []string{}
Summary
This PR adds support for ODPEventManager.
Test plan
Issues