Skip to content

Conversation

yasirfolio3
Copy link
Contributor

Summary

This PR adds support for ODPEventManager.

Test plan

  • Unit tests added

Issues

  • FSSDK-8515

Copy link

@jaeopt jaeopt left a 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.

const DefaultEventQueueSize = 10000

// DefaultEventFlushInterval holds the default value for the event flush interval
const DefaultEventFlushInterval = 30 * time.Second
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const DefaultEventFlushInterval = 30 * time.Second
const DefaultEventFlushInterval = 1 * time.Second

Consistent (flush interval = 1sec) with other SDKs

Comment on lines 335 to 338
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
Copy link

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".

Copy link

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?

if len(a) != len(b) {
return false
}
for i, v := range a {
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixing this.

@yasirfolio3 yasirfolio3 requested a review from jaeopt November 17, 2022 07:15
Copy link

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@msohailhussain msohailhussain left a 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.

func (s *DefaultEventAPIManager) SendODPEvents(config Config, events []Event) (canRetry bool, err error) {

// Creating request
apiEndpoint := config.GetAPIHost() + eventsAPIEndpointPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use fmt.Sprintf


// Creating request
apiEndpoint := config.GetAPIHost() + eventsAPIEndpointPath
headers := []utils.Header{{Name: "Content-Type", Value: "application/json"}, {Name: ODPAPIKeyHeader, Value: config.GetAPIKey()}}
Copy link
Contributor

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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

// 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
Copy link
Contributor

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intentional?

Copy link
Contributor Author

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

)

// 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)
Copy link
Contributor

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

Copy link
Contributor Author

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{}))
Copy link
Contributor

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{}

@msohailhussain msohailhussain merged commit 74474c9 into master Nov 23, 2022
@msohailhussain msohailhussain deleted the yasir/odp-event-manager branch November 23, 2022 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants