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

feat: onboard new destination bing_ads_offline_conversion destination #4674

Merged
merged 17 commits into from
May 23, 2024

Conversation

anantjain45823
Copy link
Contributor

@anantjain45823 anantjain45823 commented May 10, 2024

Description

Onboarding a new batch router bulk upload O-Auth destination Bing Ads Offline Conversions.
-> using transform utility to validate the incoming payload with destination specific required parameters
-> Keeping the batch size as 1000 as a single CSV can at most contain 100 batch records.
-> We have three actions for this integrations insert, update and delete and for each of them we create a file separately if the batch of 1000 has atleast a single specific action
-> The procedure for bulk API is as follows:
1. Transform/Validate the payload ( having necessary keys or not ) and create a csv file based on action type and add records to that file
2. Get an upload url : URL where the file will be uploaded
3. Upload file: Upload the files from step 1
4. Poll: Fetch file status if failed with errors or with success
If failed with errors we dive into the result file given in the poll response and check which jobId's that got failed
and which one got passed.

Linear Ticket

https://linear.app/rudderstack/issue/INT-1922/rudder-server-changes-in-async-destination-to-deliver-events

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Important

Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented May 12, 2024

Codecov Report

Attention: Patch coverage is 69.83547% with 165 lines in your changes are missing coverage. Please review.

Project coverage is 74.45%. Comparing base (73f7275) to head (0c04207).
Report is 8 commits behind head on master.

Files Patch % Lines
...nationmanager/bing-ads/offline-conversions/util.go 63.56% 53 Missing and 37 partials ⚠️
...ager/bing-ads/offline-conversions/bulk_uploader.go 82.66% 26 Missing and 13 partials ⚠️
...r/asyncdestinationmanager/bing-ads/common/token.go 31.81% 15 Missing ⚠️
...ionmanager/bing-ads/offline-conversions/manager.go 61.11% 11 Missing and 3 partials ⚠️
...ter/batchrouter/asyncdestinationmanager/manager.go 0.00% 3 Missing ⚠️
router/batchrouter/handle.go 25.00% 1 Missing and 2 partials ⚠️
router/batchrouter/handle_async.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4674      +/-   ##
==========================================
- Coverage   74.47%   74.45%   -0.03%     
==========================================
  Files         413      416       +3     
  Lines       48752    49261     +509     
==========================================
+ Hits        36310    36676     +366     
- Misses      10056    10136      +80     
- Partials     2386     2449      +63     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@achettyiitr achettyiitr self-requested a review May 13, 2024 18:27
@anantjain45823 anantjain45823 force-pushed the feat.onboard.bingads.offline.conversions branch from 4062615 to 462ceef Compare May 15, 2024 05:16
@@ -1,4 +1,4 @@
package bingads
package bingads_audience
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
package bingads_audience
package audience

Per convention is ok to name this just audience, name conflicts can be solved on the package that imports it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Comment on lines 55 to 56
fmt.Println("Error during unmarshalling event:", err)
return payload, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Println("Error during unmarshalling event:", err)
return payload, err
return payload, fmt.Errorf("unmarshalling event %w:", err)

It is usually redundant to log the error and return it as well. It is better to be logged once with as much context as possible. Logging twice makes sense if it is impossible to transfer all the context.

Also, fmt.Println should not be used in production. logger should be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Comment on lines 60 to 61
fmt.Println("Error during unmarshalling event.fields:", err)
return payload, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Println("Error during unmarshalling event.fields:", err)
return payload, err
return payload, fmt.Errorf("unmarshalling event.fields: %w", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Comment on lines +71 to +84
if event.Action != "insert" {
// validate for adjusted time
err := validateField(fields, "conversionAdjustedTime")
if err != nil {
return payload, err
}
if event.Action == "update" {
// validate for Adjustment Value
err := validateField(fields, "conversionValue")
if err != nil {
return payload, err
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if event.Action != "insert" {
// validate for adjusted time
err := validateField(fields, "conversionAdjustedTime")
if err != nil {
return payload, err
}
if event.Action == "update" {
// validate for Adjustment Value
err := validateField(fields, "conversionValue")
if err != nil {
return payload, err
}
}
}
if event.Action != "insert" {
// validate for adjusted time
err := validateField(fields, "conversionAdjustedTime")
if err != nil {
return payload, err
}
}
if event.Action == "update" {
// validate for Adjustment Value
err := validateField(fields, "conversionValue")
if err != nil {
return payload, err
}
}

[minor] reducing nesting to improve reliability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incorporated

Comment on lines 85 to 92
data := map[string]interface{}{
"message": map[string]interface{}{
"fields": event.Fields,
"Action": event.Action,
},
"metadata": map[string]interface{}{
"jobId": job.JobID,
},
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a struct instead? Improve readability and better performance.

Suggested change
data := map[string]interface{}{
"message": map[string]interface{}{
"fields": event.Fields,
"Action": event.Action,
},
"metadata": map[string]interface{}{
"jobId": job.JobID,
},
data := MappedData{
MappedDataMessage{
Fields: event.Fields,
Action: event.Action,
....

Note: more appropriate naming can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using struct now

importIds = append(importIds, uploadBulkFileResp.RequestId)
failedJobs = append(failedJobs, actionFile.FailedJobIDs...)
successJobs = append(successJobs, actionFile.SuccessfulJobIDs...)
// requestIdToJobIdMap[uploadBulkFileResp.RequestId] = successJobs
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// requestIdToJobIdMap[uploadBulkFileResp.RequestId] = successJobs

Is this needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

if err != nil {
b.logger.Error("Errored in Marshalling parameters" + err.Error())
}
allErrors := router_utils.EnhanceJSON([]byte(`{}`), "error", strings.Join(errors, commaSeparator))
Copy link
Member

Choose a reason for hiding this comment

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

why not use proper JSON marshalling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it to use proper JSON marshalling

Comment on lines +176 to +181
for _, actionFile := range actionFiles {
err = os.Remove(actionFile.ZipFilePath)
if err != nil {
b.logger.Error("Error in removing zip file: %v", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this can be moved in defer function, earlier in the code. In case we need to return earlier without deleting the files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are temporary files and needs to be deleted every time upload is finished.
If we have any error while creating the zip files we return else once created we return only after deleting the files

Comment on lines 96 to 99
if err != nil {
fmt.Printf("Failed to create temporary directory: %v\n", err)
return
}
Copy link
Member

Choose a reason for hiding this comment

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

If any of the if err != nil fails it would be hard to debug, since you print and just return, the test suite would not register any failure and silently return. Without verbose mode, logs are not going be shown as well.

Since you are using gomega, the correct way to handle errors is:

Suggested change
if err != nil {
fmt.Printf("Failed to create temporary directory: %v\n", err)
return
}
Exepect(err).ShouldNot(HaveOccurred(), "creating temporary directory")

https://onsi.github.io/gomega/#haveoccurred

Similar of all the if err != nil in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed all err handling in test cases with expect(err).ShouldNot(HaveOccurred(),'some_text')

@anantjain45823 anantjain45823 merged commit c3563af into master May 23, 2024
52 checks passed
@anantjain45823 anantjain45823 deleted the feat.onboard.bingads.offline.conversions branch May 23, 2024 11:06
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.

None yet

4 participants