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: add error handling for CDK v1 #1698

Merged
merged 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Utils } = require("rudder-transformer-cdk");
const { InstrumentationError } = require("../../v0/util/errorTypes");
const { InstrumentationError } = require("../../../v0/util/errorTypes");

function identifyPostMapper(event, mappedPayload, rudderContext) {
const { message } = event;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const {
isEmptyObject,
getValueFromPropertiesOrTraits,
getHashFromArray
} = require("../../v0/util");
} = require("../../../v0/util");
const {
GENERIC_TRUE_VALUES,
GENERIC_FALSE_VALUES
} = require("../../constants");
} = require("../../../constants");
const { BASE_URL, BLACKLISTED_CHARACTERS } = require("./config");
const {
ConfigurationError,
InstrumentationError
} = require("../../v0/util/errorTypes");
} = require("../../../v0/util/errorTypes");

// append properties to endpoint
// eg: ${BASE_URL}key1=value1;key2=value2;....
Expand Down
96 changes: 96 additions & 0 deletions src/cdk/v1/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const { ConfigFactory, Executor } = require("rudder-transformer-cdk");
const { CustomError } = require("rudder-transformer-cdk/build/error");
const {
TRANSFORMER_METRIC
} = require("rudder-transformer-cdk/build/constants");
const path = require("path");

const basePath = path.resolve(__dirname);
ConfigFactory.init({ basePath, loggingMode: "production" });

const tags = require("../../v0/util/tags");
const { generateErrorObject } = require("../../v0/util");
const {
TransformationError,
ConfigurationError,
InstrumentationError
} = require("../../v0/util/errorTypes");

const defTags = {
[tags.TAG_NAMES.IMPLEMENTATION]: tags.IMPLEMENTATIONS.CDK_V1
};

/**
* Translates CDK errors into transformer errors
* @param {} err The error object
* @returns An error type which the transformer recognizes
*/
function getErrorInfo(err) {
if (err instanceof CustomError) {
let errInstance = "";
switch (err.statTags?.meta) {
case TRANSFORMER_METRIC.MEASUREMENT_TYPE.CDK.META.BAD_CONFIG:
errInstance = new TransformationError(
`Bad transformer configuration file. Original error: ${err.message}`
);
break;

case TRANSFORMER_METRIC.MEASUREMENT_TYPE.CDK.META.CONFIGURATION:
errInstance = new ConfigurationError(
`Bad configuration. Original error: ${err.message}`
);
break;

case TRANSFORMER_METRIC.MEASUREMENT_TYPE.CDK.META.TF_FUNC:
errInstance = new TransformationError(
`Bad pre/post transformation function. Original error: ${err.message}`
);
break;

case TRANSFORMER_METRIC.MEASUREMENT_TYPE.CDK.META.BAD_EVENT:
case TRANSFORMER_METRIC.MEASUREMENT_TYPE.CDK.META.INSTRUMENTATION:
errInstance = new InstrumentationError(
`Bad event. Original error: ${err.message}`
);
break;

case TRANSFORMER_METRIC.MEASUREMENT_TYPE.CDK.META.EXCEPTION:
errInstance = new TransformationError(
`Unknown error occurred. Original error: ${err.message}`
);
break;
default:
break;
}

switch (err.statTags.scope) {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
case TRANSFORMER_METRIC.MEASUREMENT_TYPE.EXCEPTION.SCOPE:
errInstance = new TransformationError(
`Unknown error occurred. Original error: ${err.message}`
);
break;
default:
break;
}

if (errInstance) {
return generateErrorObject(errInstance, defTags);
}
}

return generateErrorObject(err, defTags);
}

async function processCdkV1(destType, parsedEvent) {
try {
const tfConfig = await ConfigFactory.getConfig(destType);
const respEvents = await Executor.execute(parsedEvent, tfConfig);
return respEvents;
} catch (error) {
throw getErrorInfo(error);
}
}

module.exports = {
processCdkV1
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function processExtraPayloadParams(event, mappedPayload) {
}
}
break;
default:
break;
}

const extraParams = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getHashFromArray } = require("../../v0/util");
const { getHashFromArray } = require("../../../v0/util");

function commonPostMapper(event, mappedPayload, rudderContext) {
const { message, destination } = event;
Expand Down
11 changes: 4 additions & 7 deletions src/versionedRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const Router = require("koa-router");
const _ = require("lodash");
const fs = require("fs");
const path = require("path");
const { ConfigFactory, Executor } = require("rudder-transformer-cdk");
const logger = require("./logger");
const stats = require("./util/stats");
const { SUPPORTED_VERSIONS, API_VERSION } = require("./routes/utils/constants");
Expand Down Expand Up @@ -41,10 +40,9 @@ const {
getCachedWorkflowEngine,
processCdkV2Workflow
} = require("./cdk/v2/handler");
const { processCdkV1 } = require("./cdk/v1/handler");

const CDK_DEST_PATH = "cdk";
const basePath = path.resolve(__dirname, `./${CDK_DEST_PATH}`);
ConfigFactory.init({ basePath, loggingMode: "production" });
const CDK_V1_DEST_PATH = "cdk/v1";

const transformerMode = process.env.TRANSFORMER_MODE;

Expand Down Expand Up @@ -254,8 +252,7 @@ async function handleDest(ctx, version, destination) {
tags.FEATURES.PROCESSOR
);
} else if (isCdkDestination(parsedEvent)) {
const tfConfig = await ConfigFactory.getConfig(destination);
respEvents = await Executor.execute(parsedEvent, tfConfig);
respEvents = await processCdkV1(destination, parsedEvent);
} else {
if (destHandler === null) {
destHandler = getDestHandler(version, destination);
Expand Down Expand Up @@ -558,7 +555,7 @@ if (startDestTransformer) {
path.resolve(__dirname, `./${version}/destinations`)
);
destinations.push(
...getIntegrations(path.resolve(__dirname, `./${CDK_DEST_PATH}`))
...getIntegrations(path.resolve(__dirname, `./${CDK_V1_DEST_PATH}`))
);
destinations.forEach(destination => {
// eg. v0/destinations/ga
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/autopilot.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
trackPostMapper,
identifyPostMapper
} = require("../../../src/cdk/autopilot/transform");
} = require("../../../src/cdk/v1/autopilot/transform");

describe("Unit Test for track postMapper", () => {
it("should update the rudderContext with correct endpoint", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/dcm_floodlight.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { postMapper } = require("../../../src/cdk/dcm_floodlight/transform");
const { postMapper } = require("../../../src/cdk/v1/dcm_floodlight/transform");

describe("Unit Test for postMapper", () => {
it("should update the rudderContext with userAgent and valid endpoint", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/heap.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { commonPostMapper } = require("../../../src/cdk/heap/transform");
const { commonPostMapper } = require("../../../src/cdk/v1/heap/transform");

describe("Unit test cases for heap common post mapper", () => {
let payload, event, rudderContext;
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/kochava.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
processExtraPayloadParams
} = require("../../../src/cdk/kochava/transform");
} = require("../../../src/cdk/v1/kochava/transform");

describe("Unit Test for kochava postMapper", () => {
it("should set all the default values", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/lytics.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { cleanResponse } = require("../../../src/cdk/lytics/transform");
const { cleanResponse } = require("../../../src/cdk/v1/lytics/transform");

describe("Test for Lytics common post mapper", () => {
it("should remove both first name and last name from mappedPayload", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/new_relic.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { even } = require("is");
const { commonPostMapper } = require("../../../src/cdk/new_relic/transform");
const { commonPostMapper } = require("../../../src/cdk/v1/new_relic/transform");

describe("Unit test cases for new_relic common post mapper", () => {
let payload, event, rudderContext, expectedOutput;
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/cdk_postMapper/zapier.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { commonPostMapper } = require("../../../src/cdk/zapier/transform");
const { commonPostMapper } = require("../../../src/cdk/v1/zapier/transform");

describe("Unit test cases for zapier common post mapper", () => {
it("should update the rudderContext with default endpoint", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/utilities/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function executeTransformationTest(dest, transformAt) {
const routerCommonTestParams = routerCommonformTestParams();
const { iscdkDest, expected, input } = testParams;
const { commonInput, commonExpected } = routerCommonTestParams;
const basePath = path.resolve(__dirname, "../../../src/cdk");
const basePath = path.resolve(__dirname, "../../../src/cdk/v1");
ConfigFactory.init({ basePath, loggingMode: "production" });

describe(`${dest} ${transformAt} tests`, () => {
Expand Down