Skip to content

Commit

Permalink
Merge branch 'develop' into feat.consentMode.GAOC
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 authored Mar 11, 2024
2 parents af7a820 + 01d460c commit 2be5001
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ class Prometheus {
name: 'get_libraries_code_time',
help: 'get_libraries_code_time',
type: 'histogram',
labelNames: ['libraryVersionId', 'versionId', 'type'],
labelNames: ['libraryVersionId', 'versionId', 'type', 'version'],
},
{
name: 'isolate_cpu_time',
Expand Down
2 changes: 1 addition & 1 deletion src/util/redis/redisConnector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe(`Redis Class Get Tests`, () => {
data.forEach((dataPoint, index) => {
it(`${index}. Redis Get- ${dataPoint.description}`, async () => {
try {
const output = await RedisDB.getVal(dataPoint.input.value, (isObjExpected = false));
const output = await RedisDB.getVal(dataPoint.input.value, false);
expect(output).toEqual(dataPoint.output);
} catch (error) {
expect(error.message).toEqual(dataPoint.output.error);
Expand Down
15 changes: 10 additions & 5 deletions src/util/redis/testData/shopify_source.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"user_id": "rudder01",
"id": "shopify_test_get_items_fail",
"query_parameters": {
"topic": ["carts_update"]
"topic": ["carts_update"],
"writeKey": ["wr"]
},
"token": "shopify_test_get_items_fail",
"email": "[email protected]",
Expand Down Expand Up @@ -115,7 +116,8 @@
"input": {
"cart_token": "shopifyGetAnonymousId",
"query_parameters": {
"topic": ["checkouts_delete"]
"topic": ["checkouts_delete"],
"writeKey": ["wr"]
},
"line_items": [],
"note": null,
Expand Down Expand Up @@ -154,7 +156,8 @@
"input": {
"id": "shopify_test3",
"query_parameters": {
"topic": ["carts_update"]
"topic": ["carts_update"],
"writeKey": ["wr"]
},
"token": "shopify_test3",
"line_items": [],
Expand Down Expand Up @@ -252,7 +255,8 @@
"user_id": "rudder01",
"id": "shopify_test_cart",
"query_parameters": {
"topic": ["carts_update"]
"topic": ["carts_update"],
"writeKey": ["wr"]
},
"token": "shopify_test_cart",
"email": "[email protected]",
Expand Down Expand Up @@ -1256,7 +1260,8 @@
"input": {
"id": "shopify_test4",
"query_parameters": {
"topic": ["carts_update"]
"topic": ["carts_update"],
"writeKey": ["wr"]
},
"token": "shopify_test4",
"line_items": [],
Expand Down
14 changes: 9 additions & 5 deletions src/v0/sources/shopify/shopify_redis.util.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { getAnonymousIdAndSessionId, checkAndUpdateCartItems } = require('./util');
jest.mock('ioredis', () => require('../../../../test/__mocks__/redis'));
const metricMetadata = {
writeKey: 'dummyKey',
source: 'src',
};
describe('Shopify Utils Test', () => {
describe('Check for valid cart update event test cases', () => {
it('Event containing token and nothing is retreived from redis and less than req. time difference between created_at and uadated_at', async () => {
Expand All @@ -14,7 +18,7 @@ describe('Shopify Utils Test', () => {
created_at: '2023-02-10T12:05:04.402Z',
};
const expectedOutput = false;
const output = await checkAndUpdateCartItems(input);
const output = await checkAndUpdateCartItems(input, null, metricMetadata);
expect(output).toEqual(expectedOutput);
});
it('Event containing token and nothing is retreived from redis', async () => {
Expand All @@ -28,7 +32,7 @@ describe('Shopify Utils Test', () => {
],
};
const expectedOutput = true;
const output = await checkAndUpdateCartItems(input);
const output = await checkAndUpdateCartItems(input, null, metricMetadata);
expect(output).toEqual(expectedOutput);
});

Expand All @@ -44,7 +48,7 @@ describe('Shopify Utils Test', () => {
};

const expectedOutput = true;
const output = await checkAndUpdateCartItems(input);
const output = await checkAndUpdateCartItems(input, null, metricMetadata);
expect(output).toEqual(expectedOutput);
});

Expand All @@ -60,7 +64,7 @@ describe('Shopify Utils Test', () => {
};

const expectedOutput = false;
const output = await checkAndUpdateCartItems(input);
const output = await checkAndUpdateCartItems(input, null, metricMetadata);
expect(output).toEqual(expectedOutput);
});

Expand All @@ -76,7 +80,7 @@ describe('Shopify Utils Test', () => {
};

const expectedOutput = true;
const output = await checkAndUpdateCartItems(input);
const output = await checkAndUpdateCartItems(input, null, metricMetadata);
expect(output).toEqual(expectedOutput);
});
});
Expand Down
14 changes: 9 additions & 5 deletions src/v0/sources/shopify/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const processEvent = async (inputEvent, metricMetadata) => {
break;
case 'carts_update':
if (useRedisDatabase) {
redisData = await getDataFromRedis(event.id || event.token);
redisData = await getDataFromRedis(event.id || event.token, metricMetadata);
const isValidEvent = await checkAndUpdateCartItems(inputEvent, redisData, metricMetadata);
if (!isValidEvent) {
return NO_OPERATION_SUCCESS;
Expand All @@ -155,7 +155,8 @@ const processEvent = async (inputEvent, metricMetadata) => {
if (!SUPPORTED_TRACK_EVENTS.includes(shopifyTopic)) {
stats.increment('invalid_shopify_event', {
event: shopifyTopic,
...metricMetadata,
source: metricMetadata.source,
shopifyTopic: metricMetadata.shopifyTopic,
});
return NO_OPERATION_SUCCESS;
}
Expand Down Expand Up @@ -215,7 +216,8 @@ const processIdentifierEvent = async (event, metricMetadata) => {
stats.increment('shopify_redis_calls', {
type: 'set',
field: 'itemsHash',
...metricMetadata,
source: metricMetadata.source,
writeKey: metricMetadata.writeKey,
});
/* cart_token: {
anonymousId: 'anon_id1',
Expand All @@ -236,14 +238,16 @@ const processIdentifierEvent = async (event, metricMetadata) => {
stats.increment('shopify_redis_calls', {
type: 'set',
field,
...metricMetadata,
source: metricMetadata.source,
writeKey: metricMetadata.writeKey,
});
await RedisDB.setVal(`${event.cartToken}`, value);
} catch (e) {
logger.debug(`{{SHOPIFY::}} cartToken map set call Failed due redis error ${e}`);
stats.increment('shopify_redis_failures', {
type: 'set',
...metricMetadata,
source: metricMetadata.source,
writeKey: metricMetadata.writeKey,
});
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/v0/sources/shopify/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ const getDataFromRedis = async (key, metricMetadata) => {
stats.increment('shopify_redis_calls', {
type: 'get',
field: 'all',
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
});
const redisData = await RedisDB.getVal(key);
if (
redisData === null ||
(typeof redisData === 'object' && Object.keys(redisData).length === 0)
) {
stats.increment('shopify_redis_no_val', {
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
});
}
return redisData;
} catch (e) {
logger.debug(`{{SHOPIFY::}} Get call Failed due redis error ${e}`);
stats.increment('shopify_redis_failures', {
type: 'get',
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
});
}
return null;
Expand Down Expand Up @@ -166,7 +169,9 @@ const getAnonymousIdAndSessionId = async (message, metricMetadata, redisData = n
if (isDefinedAndNotNull(anonymousId) && isDefinedAndNotNull(sessionId)) {
stats.increment('shopify_anon_id_resolve', {
method: 'note_attributes',
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
shopifyTopic: metricMetadata.shopifyTopic,
});
return { anonymousId, sessionId };
}
Expand Down Expand Up @@ -198,7 +203,9 @@ const getAnonymousIdAndSessionId = async (message, metricMetadata, redisData = n
// and for how many
stats.increment('shopify_anon_id_resolve', {
method: 'database',
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
shopifyTopic: metricMetadata.shopifyTopic,
});
}
return { anonymousId, sessionId };
Expand All @@ -215,14 +222,16 @@ const updateCartItemsInRedis = async (cartToken, newCartItemsHash, metricMetadat
stats.increment('shopify_redis_calls', {
type: 'set',
field: 'itemsHash',
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
});
await RedisDB.setVal(`${cartToken}`, value);
} catch (e) {
logger.debug(`{{SHOPIFY::}} itemsHash set call Failed due redis error ${e}`);
stats.increment('shopify_redis_failures', {
type: 'set',
...metricMetadata,
writeKey: metricMetadata.writeKey,
source: metricMetadata.source,
});
}
};
Expand Down

0 comments on commit 2be5001

Please sign in to comment.