Skip to content

Commit

Permalink
feat: marketo: migrate config fields and fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Nov 7, 2023
1 parent c38f14f commit ea35d22
Show file tree
Hide file tree
Showing 51 changed files with 4,940 additions and 1,803 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-hotfix-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

# Only allow these users to create new hotfix branch from 'main'
if: github.ref == 'refs/heads/main' && (github.actor == 'ItsSudip' || github.actor == 'krishna2020' || github.actor == 'saikumarrs' || github.actor == 'sandeepdsvs' || github.actor == 'shrouti1507' || github.actor == 'anantjain45823' || github.actor == 'chandumlg' || github.actor == 'mihir-4116') && (github.triggering_actor == 'ItsSudip' || github.triggering_actor == 'krishna2020' || github.triggering_actor == 'saikumarrs' || github.triggering_actor == 'sandeepdsvs' || github.triggering_actor == 'shrouti1507' || github.triggering_actor == 'anantjain45823' || github.triggering_actor == 'chandumlg' || github.triggering_actor == 'mihir-4116')
if: github.ref == 'refs/heads/main' && (github.actor == 'ItsSudip' || github.actor == 'krishna2020' || github.actor == 'saikumarrs' || github.actor == 'sandeepdsvs' || github.actor == 'shrouti1507' || github.actor == 'anantjain45823' || github.actor == 'chandumlg' || github.actor == 'mihir-4116' || github.actor == 'ujjwal-ab') && (github.triggering_actor == 'ItsSudip' || github.triggering_actor == 'krishna2020' || github.triggering_actor == 'saikumarrs' || github.triggering_actor == 'sandeepdsvs' || github.triggering_actor == 'shrouti1507' || github.triggering_actor == 'anantjain45823' || github.triggering_actor == 'chandumlg' || github.triggering_actor == 'mihir-4116' || github.triggering_actor == 'ujjwal-ab)
steps:
- name: Create Branch
uses: peterjgrainger/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft-new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

# Only allow release stakeholders to initiate releases
if: (github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/hotfix/')) && (github.actor == 'ItsSudip' || github.actor == 'krishna2020' || github.actor == 'saikumarrs' || github.actor == 'sandeepdsvs' || github.actor == 'shrouti1507' || github.actor == 'anantjain45823' || github.actor == 'chandumlg' || github.actor == 'mihir-4116' || github.actor == 'yashasvibajpai' || github.actor == 'sanpj2292') && (github.triggering_actor == 'ItsSudip' || github.triggering_actor == 'krishna2020' || github.triggering_actor == 'saikumarrs' || github.triggering_actor == 'sandeepdsvs' || github.triggering_actor == 'shrouti1507' || github.triggering_actor == 'anantjain45823' || github.triggering_actor == 'chandumlg' || github.triggering_actor == 'mihir-4116' || github.triggering_actor == 'yashasvibajpai' || github.triggering_actor == 'sanpj2292')
if: (github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/hotfix/')) && (github.actor == 'ItsSudip' || github.actor == 'krishna2020' || github.actor == 'saikumarrs' || github.actor == 'sandeepdsvs' || github.actor == 'shrouti1507' || github.actor == 'anantjain45823' || github.actor == 'chandumlg' || github.actor == 'mihir-4116' || github.actor == 'yashasvibajpai' || github.actor == 'sanpj2292' || github.actor == 'ujjwal-ab') && (github.triggering_actor == 'ItsSudip' || github.triggering_actor == 'krishna2020' || github.triggering_actor == 'saikumarrs' || github.triggering_actor == 'sandeepdsvs' || github.triggering_actor == 'shrouti1507' || github.triggering_actor == 'anantjain45823' || github.triggering_actor == 'chandumlg' || github.triggering_actor == 'mihir-4116' || github.triggering_actor == 'yashasvibajpai' || github.triggering_actor == 'sanpj2292' || github.triggering_actor == 'ujjwal-ab')
steps:
- name: Checkout
uses: actions/[email protected]
Expand Down
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.48.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.47.0...v1.48.0) (2023-11-02)


### Features

* add support to add custom network policies for specific workspaces in faas pods ([bc1a760](https://github.com/rudderlabs/rudder-transformer/commit/bc1a76066c0aeb43776ded0b266ec48f5e69aa16))

## [1.47.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.46.5...v1.47.0) (2023-10-30)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.47.0",
"version": "1.48.0",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
6 changes: 6 additions & 0 deletions src/cdk/v2/bindings/default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const crypto = require('crypto');
const {
InstrumentationError,
ConfigurationError,
Expand Down Expand Up @@ -47,7 +48,12 @@ function assertHttpResp(processedResponse, message) {
}
}

function MD5(data) {
return crypto.createHash('md5').update(data).digest('hex');
}

module.exports = {
MD5,
isValidEventType,
assert,
assertConfig,
Expand Down
9 changes: 9 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const ACTION_MAP = {
add: 'add',
remove: 'delete',
};
const SHA256_TRAITS = ['IDFA_SHA256', 'AAID_SHA256', 'EMAIL_SHA256', 'PHONE_SHA256'];
module.exports = {
ACTION_MAP,
SHA256_TRAITS,
};
67 changes: 67 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- path: ./config
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- name: defaultRequestConfig
path: ../../../../v0/util

steps:
- name: validateInput
template: |
let messageType = .message.type;
$.assert(.message.type, "message Type is not present. Aborting message.");
$.assert(.message.type.toLowerCase() ==='audiencelist', "Event type " + .message.type.toLowerCase() + " is not supported. Aborting message.");
$.assert(.message.properties, "Message properties is not present. Aborting message.");
$.assert(.message.properties.listData, "listData is not present inside properties. Aborting message.");
$.assert($.containsAll(Object.keys(.message.properties.listData), ["add", "remove"]), "unsupported action type. Aborting message.")
- name: prepareIdentifiersList
description: |
Populate list of identifiers to be updated
template: |
const destinationFields = .message.context.destinationFields.split(", ")
const audienceId = .message.context.externalId[0].type.split("-")[1];
const isHashRequired = .destination.Config.isHashRequired;
const advertiserIds = .metadata.secret.advertiserIds;
const hashTraits = function(traits) {
traits@trait.(destinationFields@destinationField.(
trait[destinationField] ? {
id: isHashRequired ?
destinationField in $.SHA256_TRAITS ?
$.SHA256(trait[destinationField]) : $.MD5(trait[destinationField])
: trait[destinationField],
audience_ids:[audienceId]
} : {}
)[])
};
const listData = .message.properties.listData;
const actions = Object.keys(listData)
actions@action.({
"batch_data": hashTraits(listData[action]),
"id_schema": destinationFields,
"advertiser_ids": advertiserIds,
"action": $.ACTION_MAP[action],
})[]
- name: buildResponseForProcessTransformation
description: build response
template: |
const accessToken = .metadata.secret.accessToken
const anonymousId = .message.anonymousId;
$.outputs.prepareIdentifiersList@body.(
let response = $.defaultRequestConfig();
response.body.JSON = body;
response.userId = anonymousId;
response.endpoint = "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/";
response.headers = {
"Access-Token": accessToken,
"Content-Type": "application/json"
};
response
)
32 changes: 32 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
bindings:
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index

steps:
- name: validateInput
template: |
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array")
- name: transform
externalWorkflow:
path: ./procWorkflow.yaml
loopOverInput: true

- name: successfulEvents
debug: true
template: |
$.outputs.transform#idx{"output" in .}.({
"batchedRequest": .output,
"batched": true,
"destination": ^[idx].destination,
"metadata": ^[idx].metadata[],
"statusCode": 200
})[]
- name: failedEvents
template: |
$.outputs.transform#idx.error.(
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {})
)[]
- name: finalPayload
template: |
[...$.outputs.failedEvents, ...$.outputs.successfulEvents]
4 changes: 3 additions & 1 deletion src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"OPTIMIZELY_FULLSTACK": true,
"TWITTER_ADS": true,
"CLEVERTAP": true,
"ORTTO": true
"ORTTO": true,
"ONE_SIGNAL": true,
"TIKTOK_AUDIENCE": true
}
}
16 changes: 12 additions & 4 deletions src/util/customTransformer-faas.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { v4: uuidv4 } = require('uuid');
const crypto = require('crypto');
const NodeCache = require('node-cache');
const { getMetadata } = require('../v0/util');
const { getMetadata, getTransformationMetadata } = require('../v0/util');
const stats = require('./stats');
const {
setupFaasFunction,
Expand Down Expand Up @@ -82,10 +82,10 @@ async function setOpenFaasUserTransform(
libraryVersionIds,
pregeneratedFnName,
testMode = false,
trMetadata = {},
) {
const tags = {
transformerVersionId: userTransformation.versionId,
language: userTransformation.language,
identifier: 'openfaas',
testMode,
};
Expand All @@ -106,6 +106,7 @@ async function setOpenFaasUserTransform(
testMode,
),
testMode,
trMetadata,
);

stats.timing('creation_time', setupTime, tags);
Expand All @@ -129,16 +130,22 @@ async function runOpenFaasUserTransform(
const metaTags = events[0].metadata ? getMetadata(events[0].metadata) : {};
const tags = {
transformerVersionId: userTransformation.versionId,
language: userTransformation.language,
identifier: 'openfaas',
testMode,
...metaTags,
};
const trMetadata = events[0].metadata ? getTransformationMetadata(events[0].metadata) : {};

// check and deploy faas function if not exists
const functionName = generateFunctionName(userTransformation, libraryVersionIds, testMode);
if (testMode) {
await setOpenFaasUserTransform(userTransformation, libraryVersionIds, functionName, testMode);
await setOpenFaasUserTransform(
userTransformation,
libraryVersionIds,
functionName,
testMode,
trMetadata,
);
}

const invokeTime = new Date();
Expand All @@ -156,6 +163,7 @@ async function runOpenFaasUserTransform(
testMode,
),
testMode,
trMetadata,
);
stats.timing('run_time', invokeTime, tags);
return result;
Expand Down
62 changes: 52 additions & 10 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const CONFIG_BACKEND_URL = process.env.CONFIG_BACKEND_URL || 'https://api.rudder
const GEOLOCATION_URL = process.env.GEOLOCATION_URL || '';
const FAAS_AST_VID = 'ast';
const FAAS_AST_FN_NAME = 'fn-ast';
const CUSTOM_NETWORK_POLICY_WORKSPACE_IDS = process.env.CUSTOM_NETWORK_POLICY_WORKSPACE_IDS || '';
const customNetworkPolicyWorkspaceIds = CUSTOM_NETWORK_POLICY_WORKSPACE_IDS.split(',');

// Initialise node cache
const functionListCache = new NodeCache();
Expand Down Expand Up @@ -111,7 +113,14 @@ const invalidateFnCache = () => {
functionListCache.set(FUNC_LIST_KEY, []);
};

const deployFaasFunction = async (functionName, code, versionId, libraryVersionIDs, testMode) => {
const deployFaasFunction = async (
functionName,
code,
versionId,
libraryVersionIDs,
testMode,
trMetadata = {},
) => {
try {
logger.debug('[Faas] Deploying a faas function');
let envProcess = 'python index.py';
Expand All @@ -132,19 +141,30 @@ const deployFaasFunction = async (functionName, code, versionId, libraryVersionI
if (GEOLOCATION_URL) {
envVars.geolocation_url = GEOLOCATION_URL;
}
// labels
const labels = {
'openfaas-fn': 'true',
'parent-component': 'openfaas',
'com.openfaas.scale.max': FAAS_MAX_PODS_IN_TEXT,
'com.openfaas.scale.min': FAAS_MIN_PODS_IN_TEXT,
transformationId: trMetadata.transformationId,
workspaceId: trMetadata.workspaceId,
};
if (
trMetadata.workspaceId &&
customNetworkPolicyWorkspaceIds.includes(trMetadata.workspaceId)
) {
labels['custom-network-policy'] = 'true';
}

// TODO: investigate and add more required labels and annotations
const payload = {
service: functionName,
name: functionName,
image: FAAS_BASE_IMG,
envProcess,
envVars,
labels: {
'openfaas-fn': 'true',
'parent-component': 'openfaas',
'com.openfaas.scale.max': FAAS_MAX_PODS_IN_TEXT,
'com.openfaas.scale.min': FAAS_MIN_PODS_IN_TEXT,
},
labels,
annotations: {
'prometheus.io.scrape': 'true',
},
Expand Down Expand Up @@ -175,14 +195,28 @@ const deployFaasFunction = async (functionName, code, versionId, libraryVersionI
}
};

async function setupFaasFunction(functionName, code, versionId, libraryVersionIDs, testMode) {
async function setupFaasFunction(
functionName,
code,
versionId,
libraryVersionIDs,
testMode,
trMetadata = {},
) {
try {
if (!testMode && isFunctionDeployed(functionName)) {
logger.debug(`[Faas] Function ${functionName} already deployed`);
return;
}
// deploy faas function
await deployFaasFunction(functionName, code, versionId, libraryVersionIDs, testMode);
await deployFaasFunction(
functionName,
code,
versionId,
libraryVersionIDs,
testMode,
trMetadata,
);

// This api call is only used to check if function is spinned correctly
await awaitFunctionReadiness(functionName);
Expand All @@ -201,6 +235,7 @@ const executeFaasFunction = async (
versionId,
libraryVersionIDs,
testMode,
trMetadata = {},
) => {
try {
logger.debug('[Faas] Invoking faas function');
Expand All @@ -217,7 +252,14 @@ const executeFaasFunction = async (
error.message.includes(`error finding function ${functionName}`)
) {
removeFunctionFromCache(functionName);
await setupFaasFunction(functionName, null, versionId, libraryVersionIDs, testMode);
await setupFaasFunction(
functionName,
null,
versionId,
libraryVersionIDs,
testMode,
trMetadata,
);
throw new RetryRequestError(`${functionName} not found`);
}

Expand Down
3 changes: 2 additions & 1 deletion src/v0/destinations/adobe_analytics/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
isDefinedAndNotNull,
isDefinedAndNotNullAndNotEmpty,
getIntegrationsObj,
removeUndefinedAndNullValues,
simpleProcessRouterDest,
} = require('../../util');
const {
Expand Down Expand Up @@ -394,7 +395,7 @@ const handleTrack = (message, destinationConfig) => {
break;
}

return payload;
return removeUndefinedAndNullValues(payload);
};

const process = async (event) => {
Expand Down
Loading

0 comments on commit ea35d22

Please sign in to comment.