Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Jun 19, 2024
2 parents 20fb5de + 20020af commit 1014c1d
Show file tree
Hide file tree
Showing 20 changed files with 1,752 additions and 548 deletions.
21 changes: 14 additions & 7 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"@pyroscope/nodejs": "^0.2.9",
"@rudderstack/integrations-lib": "^0.2.11",
"@rudderstack/integrations-store": "^1.0.0",
"@rudderstack/json-template-engine": "^0.13.2",
"@rudderstack/workflow-engine": "^0.8.2",
"@rudderstack/json-template-engine": "^0.13.8",
"@rudderstack/workflow-engine": "^0.8.6",
"@shopify/jest-koa-mocks": "^5.1.1",
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
Expand Down
25 changes: 0 additions & 25 deletions src/controllers/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import logger from '../logger';

export class DestinationController {
public static async destinationTransformAtProcessor(ctx: Context) {
const startTime = new Date();
logger.debug('Native(Process-Transform):: Requst to transformer::', ctx.request.body);
let resplist: ProcessorTransformationResponse[];
const requestMetadata = MiscService.getRequestMetadata(ctx);
Expand Down Expand Up @@ -71,22 +70,10 @@ export class DestinationController {
version,
...metaTags,
});
stats.timing('dest_transform_request_latency', startTime, {
destination,
feature: tags.FEATURES.PROCESSOR,
version,
...metaTags,
});
stats.increment('dest_transform_requests', {
destination,
version,
...metaTags,
});
return ctx;
}

public static async destinationTransformAtRouter(ctx: Context) {
const startTime = new Date();
logger.debug('Native(Router-Transform):: Requst to transformer::', ctx.request.body);
const requestMetadata = MiscService.getRequestMetadata(ctx);
const routerRequest = ctx.request.body as RouterTransformationRequest;
Expand Down Expand Up @@ -145,18 +132,11 @@ export class DestinationController {
version: 'v0',
...metaTags,
});
stats.timing('dest_transform_request_latency', startTime, {
destination,
version: 'v0',
feature: tags.FEATURES.ROUTER,
...metaTags,
});
return ctx;
}

public static batchProcess(ctx: Context) {
logger.debug('Native(Process-Transform-Batch):: Requst to transformer::', ctx.request.body);
const startTime = new Date();
const requestMetadata = MiscService.getRequestMetadata(ctx);
const routerRequest = ctx.request.body as RouterTransformationRequest;
const destination = routerRequest.destType;
Expand Down Expand Up @@ -187,11 +167,6 @@ export class DestinationController {
ctx.body = [errResp];
}
ControllerUtility.postProcess(ctx);
stats.timing('dest_transform_request_latency', startTime, {
destination,
feature: tags.FEATURES.BATCH,
version: 'v0',
});
return ctx;
}
}
6 changes: 0 additions & 6 deletions src/controllers/regulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Context } from 'koa';
import { ServiceSelector } from '../helpers/serviceSelector';
import { DestinationPostTransformationService } from '../services/destination/postTransformation';
import { UserDeletionRequest, UserDeletionResponse } from '../types';
import stats from '../util/stats';
import tags from '../v0/util/tags';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { CatchErr } from '../util/types';
Expand All @@ -11,7 +10,6 @@ import logger from '../logger';
export class RegulationController {
public static async deleteUsers(ctx: Context) {
logger.debug('Native(Process-Transform):: Requst to transformer::', ctx.request.body);
const startTime = new Date();
let rudderDestInfo: any;
try {
const rudderDestInfoHeader = ctx.get('x-rudder-dest-info');
Expand Down Expand Up @@ -47,10 +45,6 @@ export class RegulationController {
ctx.body = [{ error, statusCode: 500 }] as UserDeletionResponse[]; // TODO: responses array length is always 1. Is that okay?
ctx.status = 500;
}
stats.timing('dest_transform_request_latency', startTime, {
feature: tags.FEATURES.USER_DELETION,
version: 'v0',
});
return ctx;
}
}
19 changes: 6 additions & 13 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ class Prometheus {
type: 'counter',
labelNames: ['destination_id'],
},
{
name: 'braze_alias_missconfigured_count',
help: 'braze_alias_missconfigured_count',
type: 'counter',
labelNames: ['destination_id'],
},
{
name: 'mixpanel_batch_engage_pack_size',
help: 'mixpanel_batch_engage_pack_size',
Expand Down Expand Up @@ -715,19 +721,6 @@ class Prometheus {
type: 'histogram',
labelNames: ['feature', 'implementation', 'destType'],
},
{
name: 'dest_transform_request_latency',
help: 'dest_transform_request_latency',
type: 'histogram',
labelNames: [
'destination',
'version',
'sourceType',
'destinationType',
'k8_namespace',
'feature',
],
},
{
name: 'user_transform_request_latency',
help: 'user_transform_request_latency',
Expand Down
119 changes: 118 additions & 1 deletion src/v0/destinations/braze/braze.util.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');
const { handleHttpRequest } = require('../../../adapters/network');
const { BrazeDedupUtility, addAppId, getPurchaseObjs } = require('./util');
const { BrazeDedupUtility, addAppId, getPurchaseObjs, setAliasObject } = require('./util');
const { processBatch } = require('./util');
const {
removeUndefinedAndNullValues,
Expand Down Expand Up @@ -1421,3 +1421,120 @@ describe('getPurchaseObjs', () => {
]);
});
});

describe('setAliasObject function', () => {
// Test when integrationsObj has both alias_name and alias_label
test('should set user_alias from integrationsObj if alias_name and alias_label are defined', () => {
const payload = {};
const result = setAliasObject(payload, {
anonymousId: '12345',
integrations: {
BRAZE: {
alias: {
alias_name: 'user123',
alias_label: 'customer_id',
},
},
},
});

expect(result).toEqual({
user_alias: {
alias_name: 'user123',
alias_label: 'customer_id',
},
});
});

// Test when integrationsObj is missing alias_name or alias_label
test('should set user_alias with anonymousId as alias_name and "rudder_id" as alias_label if integrationsObj does not have alias_name or alias_label', () => {
const message = {
anonymousId: '12345',
};
const payload = {};
const result = setAliasObject(payload, message);

expect(result).toEqual({
user_alias: {
alias_name: '12345',
alias_label: 'rudder_id',
},
});
});

// Test when message has no anonymousId and integrationsObj is missing
test('should return payload unchanged if message has no anonymousId and integrationsObj is missing', () => {
const message = {};
const payload = {};
const result = setAliasObject(payload, message);

expect(result).toEqual(payload);
});

test('should set user_alias from integrationsObj if alias_name and alias_label are defined', () => {
const payload = {};
const result = setAliasObject(payload, {
anonymousId: '12345',
integrations: {
BRAZE: {
alias: {
alias_name: 'user123',
alias_label: 'customer_id',
},
},
},
});

expect(result).toEqual({
user_alias: {
alias_name: 'user123',
alias_label: 'customer_id',
},
});
});

test('should set user_alias from integrationsObj if alias_name and alias_label either is not defined', () => {
const payload = {};
const result = setAliasObject(payload, {
anonymousId: '12345',
integrations: {
BRAZE: {
alias: {
alias_name: null,
alias_label: 'customer_id',
},
},
},
});

expect(result).toEqual({
user_alias: {
alias_name: '12345',
alias_label: 'rudder_id',
},
});
});

test('should set user_alias from integrationsObj if alias_name and alias_label either is not defined', () => {
const payload = {};
const result = setAliasObject(payload, {
anonymousId: '12345',
userID: 'user123',
integrations: {
BRAZE: {
alias: {
alias_name: 'rudder_id-123',
alias_label: 'customer_id',
},
},
},
});

expect(result).toEqual({
user_alias: {
alias_name: 'rudder_id-123',
alias_label: 'customer_id',
},
});
});
});
26 changes: 16 additions & 10 deletions src/v0/destinations/braze/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const {
setExternalIdOrAliasObject,
getPurchaseObjs,
setExternalId,
setAliasObjectWithAnonId,
setAliasObject,
collectStatsForAliasFailure,
collectStatsForAliasMissConfigurations,
} = require('./util');
const tags = require('../../util/tags');
const { EventType, MappedToDestinationKey } = require('../../../constants');
Expand All @@ -27,6 +28,7 @@ const {
simpleProcessRouterDestSync,
simpleProcessRouterDest,
isNewStatusCodesAccepted,
getDestinationExternalID,
} = require('../../util');
const {
ConfigCategory,
Expand Down Expand Up @@ -82,7 +84,7 @@ function buildResponse(message, destination, properties, endpoint) {

function getIdentifyPayload(message) {
let payload = {};
payload = setAliasObjectWithAnonId(payload, message);
payload = setAliasObject(payload, message);
payload = setExternalId(payload, message);
return { aliases_to_identify: [payload], merge_behavior: 'merge' };
}
Expand Down Expand Up @@ -202,12 +204,6 @@ function getUserAttributesObject(message, mappingJson, destination) {
* @param {*} destination
*/
async function processIdentify(message, destination) {
// override userId with externalId in context(if present) and event is mapped to destination
const mappedToDestination = get(message, MappedToDestinationKey);
if (mappedToDestination) {
adduserIdFromExternalId(message);
}

const identifyPayload = getIdentifyPayload(message);
const identifyEndpoint = getIdentifyEndpoint(getEndpointFromConfig(destination));
const { processedResponse: brazeIdentifyResp } = await handleHttpRequest(
Expand Down Expand Up @@ -511,10 +507,19 @@ async function process(event, processParams = { userStore: new Map() }, reqMetad
processParams,
);
break;
case EventType.IDENTIFY:
case EventType.IDENTIFY: {
category = ConfigCategory.IDENTIFY;
if (message.anonymousId) {
// override userId with externalId in context(if present) and event is mapped to destination
const mappedToDestination = get(message, MappedToDestinationKey);
if (mappedToDestination) {
adduserIdFromExternalId(message);
}
const brazeExternalID =
getDestinationExternalID(message, 'brazeExternalId') || message.userId;
if (message.anonymousId && brazeExternalID) {
await processIdentify(message, destination);
} else {
collectStatsForAliasMissConfigurations(destination.ID);
}
response = processTrackWithUserAttributes(
message,
Expand All @@ -524,6 +529,7 @@ async function process(event, processParams = { userStore: new Map() }, reqMetad
reqMetadata,
);
break;
}
case EventType.GROUP:
response = processGroup(message, destination);
break;
Expand Down
Loading

0 comments on commit 1014c1d

Please sign in to comment.