Skip to content

fix: discard duplicate cart event - #2091

Merged
anantjain45823 merged 21 commits into
fix.redis-connectorfrom
fix.shopifyDuplicateEvents
May 5, 2023
Merged

anantjain45823 merged 21 commits into
fix.redis-connectorfrom
fix.shopifyDuplicateEvents

Conversation

@anantjain45823

@anantjain45823 anantjain45823 commented Apr 24, 2023 •

Copy link
Copy Markdown
Contributor

Description of the change

Discard Duplicate Event for cart events that are generated by us
Remove carts_create event support

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Fix #1

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers mentioned in a comment
  • Changes have been reviewed by at least one other engineer
  • Issue from task tracker has a link to this pull request

@codecov

codecov Bot commented Apr 24, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 95.55% and project coverage change: +0.07 🎉

Comparison is base (c2117af) 87.87% compared to head (9a7ac6e) 87.95%.

❗ Current head 9a7ac6e differs from pull request most recent head bd3dc15. Consider uploading reports for the commit bd3dc15 to get more accurate results

Additional details and impacted files
@@                   Coverage Diff                   @@
##           fix.redis-connector    #2091      +/-   ##
=======================================================
+ Coverage                87.87%   87.95%   +0.07%     
=======================================================
  Files                      509      509              
  Lines                    25742    25746       +4     
  Branches                  6368     6352      -16     
=======================================================
+ Hits                     22622    22646      +24     
+ Misses                    2787     2767      -20     
  Partials                   333      333              
Impacted Files Coverage Δ
src/v0/sources/shopify/transform.js 97.67% <95.00%> (+0.23%) ⬆️
src/util/redisConnector.js 94.52% <95.45%> (+0.86%) ⬆️
src/v0/sources/shopify/util.js 97.93% <95.74%> (+17.06%) ⬆️
src/v0/sources/shopify/config.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment thread src/v0/sources/shopify/transform.js Resolved
Comment thread src/v0/sources/shopify/config.js Resolved
"token": "shopify_test3",
"updated_at": "2023-02-10T12:16:07.251Z"
}
"error": "event type carts_create not supported"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we absorb the changes made here in this PR ?
CC @krishna2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am adding some more cases here and there first it is confirm.Then we can see depending on number conflicts
Will that be right approach?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes are simple:
Move redisConnector.js to src/util/redis &
Move redisConnector.test.js to src/util/redis & redis test cases files to src/util/testdata

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@anantjain45823
anantjain45823 requested a review from a team April 27, 2023 05:42
Comment thread src/util/redisConnector.js Resolved
Comment thread src/util/redisConnector.js Resolved
Comment thread src/v0/sources/shopify/util.js Resolved
Comment thread src/util/redisConnector.js Outdated
Comment on lines +34 to +35
errorType: "Redis",
timestamp: Date.now()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is wrong labels, we shouldn't add timestamp as label. Also having a constant value for errorType as label as well doesn't make sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me gather info and see what would be the best param

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

Comment thread src/util/redisConnector.js Outdated
*
*/
async getVal(key, isJsonExpected = true) {
async getVal(key, isObjExpected = true) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please update the JS docs its still showing description for isJsonExpected

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/util/redisConnector.js Outdated
return isJsonExpected ? JSON.parse(value) : value;
const bytes = Buffer.byteLength(JSON.stringify(value), "utf-8");
stats.gauge('redis_get_val_size', bytes, {
timestamp: Date.now()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove timestamp as label from here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in #2107

Comment thread src/util/redisConnector.js Outdated
} catch (e) {
stats.increment('redis_get_val_error', {
error: e,
errorType: "Redis",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same please remove timestamp as label from here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/util/redisConnector.js Outdated

async setVal(key, value, isValJson = true) {
const dataExpiry = 60 * 60; // 1 hour
async setVal(key, value, expiryTime = 60 * 60) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
async setVal(key, value, expiryTime = 60 * 60) {
async setVal(key, value, expiryTimeInSec = 60 * 60) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

} else {
bytes = Buffer.byteLength(value, "utf-8");
await this.client.setex(key, expiryTime, value);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove timestamp as a stats label for all occurrences

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in #2107

Comment thread src/v0/sources/shopify/config.js Resolved
@anantjain45823
anantjain45823 changed the base branch from develop to fix.redis-connector May 3, 2023 11:00
Comment thread src/util/redisConnector.js Outdated
.exec();
} else {
bytes = Buffer.byteLength(value, "utf-8");
await this.client.setex(key, expiryTimeInSec, value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment thread src/util/redisConnector.js Outdated
if (isObjExpected === true) {
value = await this.client.hmget(key);
if (isDefinedAndNotNull(value)) {
Object.keys(value).forEach(Key => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Key -> keep key (lower case)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we already have key as parameter . will change this to objKey

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/util/redisConnector.js Outdated
@@ -122,7 +151,7 @@ const RedisDB = {
});
this.client.quit();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread src/util/redisConnector.js Outdated
}
return element;
})
bytes = Buffer.byteLength(JSON.stringify(value), "utf-8");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not required, aws provides this already

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay will remove this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/util/redisConnector.js Outdated
.expire(key, expiryTimeInSec)
.exec();
} else {
bytes = Buffer.byteLength(value, "utf-8");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not required, aws provides this already

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/v0/sources/shopify/util.js Outdated
}
if (!isDefinedAndNotNull(cartToken)) {
stats.increment('shopify_no_cartToken', {
stats.increment('No_cartToken_in_payload', {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

keep all small no_cart_token_in_payload

what are we planning to do with this metric?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we want to know in how many cases will we wont get any cartToken in payload

Comment thread src/v0/sources/shopify/util.js Outdated
redisVal = await RedisDB.getVal(cartToken);
} catch (e) {
// so if redis is down we will send the event to downstream destinations
console.log("Error: ", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

console.log("Shopify events not stitched:", e);

@sonarqubecloud

sonarqubecloud Bot commented May 4, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 71 Code Smells

86.9% 86.9% Coverage
4.4% 4.4% Duplication

@anantjain45823
anantjain45823 merged commit 5105696 into fix.redis-connector May 5, 2023
anantjain45823 added a commit that referenced this pull request May 17, 2023
* fix: redis connect with promise race

timeoutPromise should be a function so that it returns a new
promise everytime.

* fix: redis connect with promise race

timeoutPromise should be a function so that it returns a new
promise everytime.

Also we should use reject so that it will error if timed out.

* added extra padding for redis failure and passing events if redis error comes up

* refactor: checkAndConnectConnection method

* feat: tested redis

* refactor redis for incorporating end signal

* comments addressed

* test coverage increased

* test coverage increased

* introducing redis_error stat

* introducing redis_latency stat

* comments addressed+1

* stat fix

* chore: comments addressed+2

* fix: discard duplicate cart event (#2091)

* fix: discard duplicate cart event

* Removed cart_create event

* Removed cart_create event

* chore: utils test cases added

* fix: updated design flow for cart duplication

* chore: test cases added

* fix: directory path

* fix: directory path

* feat: added some more redis metric

* Update src/util/redisConnector.js

Co-authored-by: Sudip Paul <[email protected]>

* comments addressed

* chore: conflicts resolved

* chore: comments addressed

* chore: ideas incorporated

* chore: comments addressed

* chore: comments addressed

* fix: redis mock

* fix: redis

---------

Co-authored-by: Sudip Paul <[email protected]>

* chore: update import statement

* chore: comments addressed

* feat: redis return type changes

* chore: add metrics in prometheus.js

* replaced hmget with hget

* added padding

* removed use of isObject

* console removes

* added error logs

* chore: addressed comments

* chore: addressed comments

* solve build issue

* chore: addressed comments

---------

Co-authored-by: Anant Jain <[email protected]>
Co-authored-by: Anant Jain <[email protected]>
Co-authored-by: Sudip Paul <[email protected]>
@devops-github-rudderstack
devops-github-rudderstack deleted the fix.shopifyDuplicateEvents branch August 5, 2023 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants