Skip to content

Commit

Permalink
Merge branch 'develop' into chore.bugsbag-braze
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepdsvs authored Jun 24, 2024
2 parents 60f4a7b + a0f5c2f commit 057d9a7
Show file tree
Hide file tree
Showing 101 changed files with 5,935 additions and 1,666 deletions.
18 changes: 9 additions & 9 deletions benchmark/metaLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

const logger = require('../src/logger');

logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');

const debug = (...args) => {
logger.setLogLevel(logger.levelDebug);
logger.setLogLevel('debug');
logger.debug(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

const info = (...args) => {
logger.setLogLevel(logger.levelInfo);
logger.setLogLevel('info');
logger.info(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

const warn = (...args) => {
logger.setLogLevel(logger.levelWarn);
logger.setLogLevel('warn');
logger.warn(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

const error = (...args) => {
logger.setLogLevel(logger.levelError);
logger.setLogLevel('error');
logger.error(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

module.exports = {
Expand Down
69 changes: 56 additions & 13 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
Expand Up @@ -64,9 +64,9 @@
"@koa/router": "^12.0.0",
"@ndhoule/extend": "^2.0.0",
"@pyroscope/nodejs": "^0.2.9",
"@rudderstack/integrations-lib": "^0.2.8",
"@rudderstack/json-template-engine": "^0.13.2",
"@rudderstack/workflow-engine": "^0.8.2",
"@rudderstack/integrations-lib": "^0.2.10",
"@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
102 changes: 76 additions & 26 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,28 @@ const networkClientConfigs = {
httpsAgent: new https.Agent({ keepAlive: true }),
};

const fireHTTPStats = (clientResponse, startTime, statTags) => {
const destType = statTags.destType ? statTags.destType : '';
const feature = statTags.feature ? statTags.feature : '';
const endpointPath = statTags.endpointPath ? statTags.endpointPath : '';
const requestMethod = statTags.requestMethod ? statTags.requestMethod : '';
const module = statTags.module ? statTags.module : '';
const statusCode = clientResponse.success ? clientResponse.response.status : '';
const fireOutgoingReqStats = ({
destType,
feature,
endpointPath,
requestMethod,
module,
metadata = {},
startTime,
statusCode,
clientResponse,
}) => {
const logMetaInfo = log.getLogMetadata(metadata);
stats.timing('outgoing_request_latency', startTime, {
...logMetaInfo,
feature,
destType,
endpointPath,
requestMethod,
module,
});
stats.counter('outgoing_request_count', 1, {
...logMetaInfo,
feature,
destType,
endpointPath,
Expand All @@ -70,6 +77,36 @@ const fireHTTPStats = (clientResponse, startTime, statTags) => {
});
};

const fireHTTPStats = (clientResponse, startTime, statTags) => {
const destType = statTags.destType ? statTags.destType : '';
const feature = statTags.feature ? statTags.feature : '';
const endpointPath = statTags.endpointPath ? statTags.endpointPath : '';
const requestMethod = statTags.requestMethod ? statTags.requestMethod : '';
const module = statTags.module ? statTags.module : '';
const statusCode = clientResponse.success ? clientResponse.response.status : '';
const defArgs = {
destType,
endpointPath,
feature,
module,
requestMethod,
statusCode,
startTime,
clientResponse,
};
if (statTags?.metadata) {
const metadata = !Array.isArray(statTags?.metadata) ? [statTags.metadata] : statTags.metadata;
metadata?.forEach((m) => {
fireOutgoingReqStats({
...defArgs,
metadata: m,
});
});
return;
}
fireOutgoingReqStats(defArgs);
};

const enhanceRequestOptions = (options) => {
const requestOptions = {
...networkClientConfigs,
Expand Down Expand Up @@ -322,25 +359,6 @@ const prepareProxyRequest = (request) => {
return removeUndefinedValues({ endpoint, data, params, headers, method, config });
};

/**
* depricating: handles proxying requests to destinations from server, expects requsts in "defaultRequestConfig"
* note: needed for test api
* @param {*} request
* @returns
*/
const proxyRequest = async (request, destType) => {
const { endpoint, data, method, params, headers } = prepareProxyRequest(request);
const requestOptions = {
url: endpoint,
data,
params,
headers,
method,
};
const response = await httpSend(requestOptions, { feature: 'proxy', destType });
return response;
};

/**
* handles http request and sends the response in a simple format that is followed in transformer
*
Expand Down Expand Up @@ -392,6 +410,38 @@ const handleHttpRequest = async (requestType = 'post', ...httpArgs) => {
return { httpResponse, processedResponse };
};

/**
* depricating: handles proxying requests to destinations from server, expects requsts in "defaultRequestConfig"
* note: needed for test api
* @param {*} request
* @returns
*/
const proxyRequest = async (request, destType) => {
const { metadata } = request;
const { endpoint, data, method, params, headers } = prepareProxyRequest(request);
const requestOptions = {
url: endpoint,
data,
params,
headers,
method,
};
log.requestLog(`[${destType.toUpperCase()}] delivering data`, {
metadata,
requestDetails: {
body: data,
url: endpoint,
method,
},
});
const response = await httpSend(requestOptions, {
feature: 'proxy',
destType,
metadata,
});
return response;
};

module.exports = {
httpSend,
httpGET,
Expand Down
6 changes: 4 additions & 2 deletions src/adapters/utils/networkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ const processAxiosResponse = (clientResponse) => {
}
// non 2xx status handling for axios response
if (response) {
const { data, status } = response;
const { data, status, headers } = response;
return {
response: data || '',
status: status || 500,
...(isDefinedAndNotNullAndNotEmpty(headers) ? { headers } : {}),
};
}
// (edge case) response and code is not present
Expand All @@ -157,10 +158,11 @@ const processAxiosResponse = (clientResponse) => {
};
}
// success(2xx) axios response
const { data, status } = clientResponse.response;
const { data, status, headers } = clientResponse.response;
return {
response: data || '',
status: status || 500,
...(isDefinedAndNotNullAndNotEmpty(headers) ? { headers } : {}),
};
};

Expand Down
3 changes: 2 additions & 1 deletion src/cdk/v2/destinations/gladly/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ steps:
headers: $.getHeaders(.destination)
}
const endpoint = $.getEndpoint(.destination) + "?" + $.getQueryParams($.context.payload);
const rawResponse = await $.httpGET(endpoint,requestOptions)
const reqStats = {metadata:.metadata, module: 'router',feature: "transformation", destType:"gladly",requestMethod:"get",endpointPath:"/api/v1/customer-profiles"}
const rawResponse = await $.httpGET(endpoint,requestOptions, reqStats)
const processedResponse = $.processAxiosResponse(rawResponse)
processedResponse
Expand Down
2 changes: 2 additions & 0 deletions src/cdk/v2/destinations/intercom/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const BASE_AU_ENDPOINT = 'https://api.au.intercom.io';

const SEARCH_CONTACT_ENDPOINT = 'contacts/search';
const CREATE_OR_UPDATE_COMPANY_ENDPOINT = 'companies';
const TAGS_ENDPOINT = 'tags';

const ReservedAttributes = {
v1UserAttributes: [
Expand Down Expand Up @@ -78,4 +79,5 @@ module.exports = {
SEARCH_CONTACT_ENDPOINT,
ReservedCompanyProperties,
CREATE_OR_UPDATE_COMPANY_ENDPOINT,
TAGS_ENDPOINT,
};
25 changes: 25 additions & 0 deletions src/cdk/v2/destinations/intercom/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ bindings:
- name: addExternalIdToTraits
path: ../../../../v0/util
- path: ../../bindings/jsontemplate
- name: HTTP_STATUS_CODES
path: ../../../../v0/util/constant

steps:
- name: checkIfProcessed
Expand Down Expand Up @@ -182,10 +184,17 @@ steps:
id: companyId,
};
$.context.endpoint = $.getBaseEndpoint(.destination) + "/" + "contacts" + "/" + contactId + "/" + "companies";
const payload = $.context.payload;
const endpoint = $.context.endpoint;
await $.attachContactToCompany(payload, endpoint, .destination);
await $.addOrUpdateTagsToCompany(.message, .destination, companyId);
else:
name: whenSearchContactNotFound
template: |
const companyId = await $.createOrUpdateCompany($.context.payload, .destination);
$.assert(companyId, "Unable to create or update company");
$.context.endpoint = $.getBaseEndpoint(.destination) + "/" + "companies";
await $.addOrUpdateTagsToCompany(.message, .destination, companyId);
- name: prepareFinalPayload
template: |
$.context.requestMethod = 'POST';
Expand All @@ -208,9 +217,25 @@ steps:
response.method = "POST";
response.userId = .message.anonymousId;
$.context.response.push(response);
payload = response.body.JSON;
const companyId = await $.createOrUpdateCompany(payload, .destination);
$.assert(companyId, "Unable to create or update company");
const attachUserAndCompanyResponse = $.attachUserAndCompany(.message, .destination.Config);
attachUserAndCompanyResponse ? attachUserAndCompanyResponse.userId = .message.anonymousId;
attachUserAndCompanyResponse ? $.context.response.push(attachUserAndCompanyResponse);
payload = attachUserAndCompanyResponse.body.JSON;
let endpoint = attachUserAndCompanyResponse.endpoint;
attachUserAndCompanyResponse ? await $.attachContactToCompany(payload, endpoint, .destination);
await $.addOrUpdateTagsToCompany(.message, .destination, companyId);
- name: statusCode
condition: $.outputs.messageType === {{$.EventType.GROUP}}
template: |
$.HTTP_STATUS_CODES.SUPPRESS_EVENTS
else:
name: successStatusCode
template: |
$.HTTP_STATUS_CODES.OK
- name: buildResponseForProcessTransformation
description: Build response for multiple transformed event
Expand Down
Loading

0 comments on commit 057d9a7

Please sign in to comment.