Skip to content

Commit

Permalink
Merge branch 'develop' into feat.klvaiyo_api_15062024
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 authored Jun 25, 2024
2 parents 0b987b4 + 0379c4d commit 9d973f4
Show file tree
Hide file tree
Showing 41 changed files with 2,455 additions and 477 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.69.1](https://github.com/rudderlabs/rudder-transformer/compare/v1.69.0...v1.69.1) (2024-06-25)


### Bug Fixes

* enhancement: introduce user model for one signal ([#3499](https://github.com/rudderlabs/rudder-transformer/issues/3499)) ([1c8e950](https://github.com/rudderlabs/rudder-transformer/commit/1c8e950f3d8789b33bba69a30c9eb21c40ce3d04))

## [1.69.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.68.2...v1.69.0) (2024-06-10)


Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.69.0",
"version": "1.69.1",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down Expand Up @@ -65,8 +65,8 @@
"@ndhoule/extend": "^2.0.0",
"@pyroscope/nodejs": "^0.2.9",
"@rudderstack/integrations-lib": "^0.2.10",
"@rudderstack/json-template-engine": "^0.14.1",
"@rudderstack/workflow-engine": "^0.8.8",
"@rudderstack/json-template-engine": "^0.15.0",
"@rudderstack/workflow-engine": "^0.8.9",
"@shopify/jest-koa-mocks": "^5.1.1",
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
Expand Down
18 changes: 5 additions & 13 deletions src/legacy/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ if (startDestTransformer) {
(event) => `${event.metadata.destinationId}_${event.metadata.sourceId}`,
);
}
stats.counter('user_transform_function_group_size', Object.entries(groupedEvents).length, {
processSessions,
});
stats.counter('user_transform_function_group_size', Object.entries(groupedEvents).length, {});

let ctxStatusCode = 200;
const transformedEvents = [];
Expand Down Expand Up @@ -646,16 +644,10 @@ if (startDestTransformer) {
ctx.status = ctxStatusCode;
ctx.set('apiVersion', API_VERSION);

stats.timing('user_transform_request_latency', startTime, {
processSessions,
});
stats.timingSummary('user_transform_request_latency_summary', startTime, {
processSessions,
});
stats.increment('user_transform_requests', { processSessions });
stats.histogram('user_transform_output_events', transformedEvents.length, {
processSessions,
});
stats.timing('user_transform_request_latency', startTime, {});
stats.timingSummary('user_transform_request_latency_summary', startTime, {});
stats.increment('user_transform_requests', {});
stats.histogram('user_transform_output_events', transformedEvents.length, {});
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/customTransformer-faas.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function setOpenFaasUserTransform(
trMetadata = {},
) {
const tags = {
transformerVersionId: userTransformation.versionId,
transformationId: userTransformation.id,
identifier: 'openfaas',
testMode,
};
Expand Down
1 change: 0 additions & 1 deletion src/util/customTransformer-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async function userTransformHandlerV1(
const isolatevmFactory = await getFactory(
userTransformation.code,
libraryVersionIds,
userTransformation.versionId,
userTransformation.id,
userTransformation.workspaceId,
credentialsMap,
Expand Down
22 changes: 12 additions & 10 deletions src/util/customTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ async function runUserTransform(
code,
secrets,
eventsMetadata,
versionId,
transformationId,
workspaceId,
testMode = false,
) {
const trTags = { identifier: 'v0', transformationId, workspaceId };
// TODO: Decide on the right value for memory limit
const isolate = new ivm.Isolate({ memoryLimit: ISOLATE_VM_MEMORY });
const context = await isolate.createContext();
Expand All @@ -36,9 +38,9 @@ async function runUserTransform(
new ivm.Reference(async (resolve, ...args) => {
try {
const fetchStartTime = new Date();
const res = await fetchWithDnsWrapper(versionId, ...args);
const res = await fetchWithDnsWrapper(trTags, ...args);
const data = await res.json();
stats.timing('fetch_call_duration', fetchStartTime, { versionId });
stats.timing('fetch_call_duration', fetchStartTime, trTags);
resolve.applyIgnored(undefined, [new ivm.ExternalCopy(data).copyInto()]);
} catch (error) {
resolve.applyIgnored(undefined, [new ivm.ExternalCopy('ERROR').copyInto()]);
Expand All @@ -51,7 +53,7 @@ async function runUserTransform(
new ivm.Reference(async (resolve, reject, ...args) => {
try {
const fetchStartTime = new Date();
const res = await fetchWithDnsWrapper(versionId, ...args);
const res = await fetchWithDnsWrapper(trTags, ...args);
const headersContent = {};
res.headers.forEach((value, header) => {
headersContent[header] = value;
Expand All @@ -67,7 +69,7 @@ async function runUserTransform(
data.body = JSON.parse(data.body);
} catch (e) {}

stats.timing('fetchV2_call_duration', fetchStartTime, { versionId });
stats.timing('fetchV2_call_duration', fetchStartTime, trTags);
resolve.applyIgnored(undefined, [new ivm.ExternalCopy(data).copyInto()]);
} catch (error) {
const err = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
Expand All @@ -93,7 +95,7 @@ async function runUserTransform(
throw new Error(`request to fetch geolocation failed with status code: ${res.status}`);
}
const geoData = await res.json();
stats.timing('geo_call_duration', geoStartTime, { versionId });
stats.timing('geo_call_duration', geoStartTime, trTags);
resolve.applyIgnored(undefined, [new ivm.ExternalCopy(geoData).copyInto()]);
} catch (error) {
const err = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
Expand Down Expand Up @@ -251,10 +253,9 @@ async function runUserTransform(
isolate.dispose();

const tags = {
identifier: 'v0',
errored: transformationError ? true : false,
...(events.length && events[0].metadata ? getMetadata(events[0].metadata) : {}),
...(events.length && events[0].metadata ? getTransformationMetadata(events[0].metadata) : {}),
...(Object.keys(eventsMetadata).length ? getMetadata(Object.values(eventsMetadata)[0]) : {}),
...trTags,
};

stats.counter('user_transform_function_input_events', events.length, tags);
Expand Down Expand Up @@ -316,7 +317,8 @@ async function userTransformHandler(
res.code,
res.secrets || {},
eventsMetadata,
versionId,
res.id,
res.workspaceId,
testMode,
);

Expand Down
37 changes: 6 additions & 31 deletions src/util/customTransforrmationsStore-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,79 +19,54 @@ const getRudderLibrariesUrl = `${CONFIG_BACKEND_URL}/rudderstackTransformationLi
async function getTransformationCodeV1(versionId) {
const transformation = transformationCache[versionId];
if (transformation) return transformation;
const tags = {
versionId,
version: 1,
};
try {
const url = `${getTransformationURL}?versionId=${versionId}`;
const startTime = new Date();
const response = await fetchWithProxy(url);

responseStatusHandler(response.status, 'Transformation', versionId, url);
stats.increment('get_transformation_code', { success: 'true', ...tags });
stats.timing('get_transformation_code_time', startTime, tags);
stats.timingSummary('get_transformation_code_time_summary', startTime, tags);
const myJson = await response.json();
transformationCache[versionId] = myJson;
return myJson;
} catch (error) {
logger.error(error);
stats.increment('get_transformation_code', { success: 'false', ...tags });
logger.error(
`Error fetching transformation V1 code for versionId: ${versionId}`,
error.message,
);
throw error;
}
}

async function getLibraryCodeV1(versionId) {
const library = libraryCache[versionId];
if (library) return library;
const tags = {
libraryVersionId: versionId,
version: 1,
};
try {
const url = `${getLibrariesUrl}?versionId=${versionId}`;
const startTime = new Date();
const response = await fetchWithProxy(url);

responseStatusHandler(response.status, 'Transformation Library', versionId, url);
stats.increment('get_libraries_code', { success: 'true', ...tags });
stats.timing('get_libraries_code_time', startTime, tags);
stats.timingSummary('get_libraries_code_time_summary', startTime, tags);
const myJson = await response.json();
libraryCache[versionId] = myJson;
return myJson;
} catch (error) {
logger.error(error);
stats.increment('get_libraries_code', { success: 'false', ...tags });
logger.error(`Error fetching library code for versionId: ${versionId}`, error.message);
throw error;
}
}

async function getRudderLibByImportName(importName) {
const rudderLibrary = rudderLibraryCache[importName];
if (rudderLibrary) return rudderLibrary;
const tags = {
libraryVersionId: importName,
version: 1,
type: 'rudderlibrary',
};
try {
const [name, version] = importName.split('/').slice(-2);
const url = `${getRudderLibrariesUrl}/${name}?version=${version}`;
const startTime = new Date();
const response = await fetchWithProxy(url);

responseStatusHandler(response.status, 'Rudder Library', importName, url);
stats.increment('get_libraries_code', { success: 'true', ...tags });
stats.timing('get_libraries_code_time', startTime, tags);
stats.timingSummary('get_libraries_code_time_summary', startTime, tags);
const myJson = await response.json();
rudderLibraryCache[importName] = myJson;
return myJson;
} catch (error) {
logger.error(error);
stats.increment('get_libraries_code', { success: 'false', ...tags });
logger.error(`Error fetching rudder library code for importName: ${importName}`, error.message);
throw error;
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/util/customTransforrmationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const NodeCache = require('node-cache');
const { fetchWithProxy } = require('./fetch');
const logger = require('../logger');
const { responseStatusHandler } = require('./utils');
const stats = require('./stats');

const myCache = new NodeCache({ stdTTL: 60 * 60 * 24 * 1 });

Expand All @@ -18,19 +17,14 @@ async function getTransformationCode(versionId) {
if (transformation) return transformation;
try {
const url = `${getTransformationURL}?versionId=${versionId}`;
const startTime = new Date();
const response = await fetchWithProxy(url);

responseStatusHandler(response.status, 'Transformation', versionId, url);
stats.increment('get_transformation_code', { versionId, success: 'true' });
stats.timing('get_transformation_code_time', startTime, { versionId });
stats.timingSummary('get_transformation_code_time_summary', startTime, { versionId });
const myJson = await response.json();
myCache.set(versionId, myJson);
return myJson;
} catch (error) {
logger.error(error);
stats.increment('get_transformation_code', { versionId, success: 'false' });
logger.error(`Error fetching transformation code for versionId: ${versionId}`, error.message);
throw error;
}
}
Expand Down
Loading

0 comments on commit 9d973f4

Please sign in to comment.