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

chore: add requestMethod and module latency labels #3085

Merged
merged 7 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ 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 : '';
stats.timing('outgoing_request_latency', startTime, {
feature,
destType,
endpointPath,
requestMethod,
module
});
stats.counter('outgoing_request_count', 1, {
feature,
destType,
endpointPath,
success: clientResponse.success,
statusCode,
requestMethod,
module
});
};

Expand Down
38 changes: 28 additions & 10 deletions src/cdk/v2/destinations/intercom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,20 @@ const searchContact = async (message, destination) => {
const headers = getHeaders(destination);
const baseEndPoint = getBaseEndpoint(destination);
const endpoint = `${baseEndPoint}/${SEARCH_CONTACT_ENDPOINT}`;
const response = await httpPOST(endpoint, data, {
headers,
destType: 'intercom',
feature: 'transformation',
});
const response = await httpPOST(
endpoint,
data,
{
headers,
},
{
destType: 'intercom',
feature: 'transformation',
endpointPath: '/contacts/search',
requestMethod: 'POST',
module: 'router',
},
);
const processedUserResponse = processAxiosResponse(response);
if (isHttpStatusSuccess(processedUserResponse.status)) {
return processedUserResponse.response?.data.length > 0
Expand Down Expand Up @@ -280,11 +289,20 @@ const createOrUpdateCompany = async (payload, destination) => {
const finalPayload = JSON.stringify(removeUndefinedAndNullValues(payload));
const baseEndPoint = getBaseEndpoint(destination);
const endpoint = `${baseEndPoint}/${CREATE_OR_UPDATE_COMPANY_ENDPOINT}`;
const response = await httpPOST(endpoint, finalPayload, {
headers,
destType: 'intercom',
feature: 'transformation',
});
const response = await httpPOST(
endpoint,
finalPayload,
{
headers,
},
{
destType: 'intercom',
feature: 'transformation',
endpointPath: '/companies',
requestMethod: 'POST',
module: 'router',
},
);

const processedResponse = processAxiosResponse(response);
if (isHttpStatusSuccess(processedResponse.status)) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class Prometheus {
name: 'outgoing_request_count',
help: 'Outgoing HTTP requests count',
type: 'counter',
labelNames: ['feature', 'destType', 'endpointPath', 'success', 'statusCode'],
labelNames: ['feature', 'destType', 'endpointPath', 'success', 'statusCode', 'requestMethod' , 'module'],
},

// Gauges
Expand Down Expand Up @@ -573,7 +573,7 @@ class Prometheus {
name: 'outgoing_request_latency',
help: 'Outgoing HTTP requests duration in seconds',
type: 'histogram',
labelNames: ['feature', 'destType', 'endpointPath'],
labelNames: ['feature', 'destType', 'endpointPath', 'requestMethod', 'module'],
},
{
name: 'http_request_duration',
Expand Down
12 changes: 12 additions & 0 deletions src/v0/destinations/active_campaign/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const syncContact = async (contactPayload, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: endPoint,
requestMethod: 'POST',
module: 'router',
});
if (res.success === false) {
errorHandler(res, 'Failed to create new contact');
Expand Down Expand Up @@ -129,6 +131,8 @@ const customTagProcessor = async (message, category, destination, contactId) =>
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/tags`,
requestMethod: 'GET',
module: 'router',
});
promises.push(resp);
}
Expand Down Expand Up @@ -253,6 +257,8 @@ const customFieldProcessor = async (message, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/fields`,
requestMethod: 'GET',
module: 'router',
});
promises.push(resp);
}
Expand Down Expand Up @@ -351,6 +357,8 @@ const customListProcessor = async (message, category, destination, contactId) =>
destType: 'active_campaign',
feature: 'transformation',
endpointPath: mergeListWithContactUrl,
requestMethod: 'POST',
module: 'router',
});
promises.push(res);
}
Expand Down Expand Up @@ -409,6 +417,8 @@ const screenRequestHandler = async (message, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/eventTrackingEvents`,
requestMethod: 'GET',
module: 'router',
});
if (res.success === false) {
errorHandler(res, 'Failed to retrieve events');
Expand Down Expand Up @@ -473,6 +483,8 @@ const trackRequestHandler = async (message, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/eventTrackingEvents`,
requestMethod: 'GET',
module: 'router',
});

if (res.success === false) {
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/af/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const deleteUser = async (config, endpoint, body, identityType, identityValue) =
destType: 'af',
feature: 'deleteUsers',
endpointPath: `appsflyer.com/api/gdpr/v1/opendsr_requests`,
requestMethod: 'POST',
module: 'deletion',
},
);
const handledDelResponse = processAxiosResponse(response);
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/am/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const userDeletionHandler = async (userAttributes, config) => {
destType: 'am',
feature: 'deleteUsers',
endpointPath,
requestMethod: 'POST',
module: 'deletion',
});
const handledDelResponse = processAxiosResponse(resp);
if (!isHttpStatusSuccess(handledDelResponse.status)) {
Expand Down
9 changes: 8 additions & 1 deletion src/v0/destinations/braze/braze.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ describe('dedup utility tests', () => {
},
timeout: 10000,
},
{ destType: 'braze', feature: 'transformation' },
{
destType: 'braze',
feature: 'transformation',
endpointPath: '/users/export/ids',
feature: 'transformation',
module: 'router',
requestMethod: 'POST',
},
);
});

Expand Down
4 changes: 3 additions & 1 deletion src/v0/destinations/braze/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const userDeletionHandler = async (userAttributes, config) => {
// Endpoints different for different data centers.
// DOC: https://www.braze.com/docs/user_guide/administrative/access_braze/braze_instances/
let endPoint;
const endpointPath = '/users/delete'; // TODO: to handle for destinations dynamically by extracting from endpoint
const endpointPath = '/users/delete';
const dataCenterArr = dataCenter.trim().split('-');
if (dataCenterArr[0].toLowerCase() === 'eu') {
endPoint = 'https://rest.fra-01.braze.eu/users/delete';
Expand All @@ -46,6 +46,8 @@ const userDeletionHandler = async (userAttributes, config) => {
destType: 'braze',
feature: 'deleteUsers',
endpointPath,
requestMethod: 'POST',
module: 'deletion',
});
const handledDelResponse = processAxiosResponse(resp);
if (!isHttpStatusSuccess(handledDelResponse.status) && handledDelResponse.status !== 404) {
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/braze/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ async function processIdentify(message, destination) {
{
destType: 'braze',
feature: 'transformation',
requestMethod: 'POST',
module: 'router',
endpointPath: '/users/identify',
},
);
if (!isHttpStatusSuccess(brazeIdentifyResp.status)) {
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ const BrazeDedupUtility = {
{
destType: 'braze',
feature: 'transformation',
requestMethod: 'POST',
module: 'router',
endpointPath: '/users/export/ids',
},
);
stats.counter('braze_lookup_failure_count', 1, {
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/canny/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const retrieveUserId = async (apiKey, message) => {
destType: 'canny',
feature: 'transformation',
endpointPath: `/v1/users/retrieve`,
requestMethod: 'POST',
module: 'processor',
},
);
logger.debug(response);
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/clevertap/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const userDeletionHandler = async (userAttributes, config) => {
destType: 'clevertap',
feature: 'deleteUsers',
endpointPath,
requestMethod: 'POST',
module: 'deletion',
},
);
const handledDelResponse = processAxiosResponse(deletionResponse);
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/clickup/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ const retrieveCustomFields = async (listId, apiToken) => {
const customFieldsResponse = await httpGET(endpoint, requestOptions, {
destType: 'clickup',
feature: 'transformation',
endpointPath: '/list/listId/field',
requestMethod: 'GET',
module: 'router',
});
const processedCustomFieldsResponse = processAxiosResponse(customFieldsResponse);

Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/custify/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const userDeletionHandler = async (userAttributes, config) => {
const deletionResponse = await httpDELETE(requestUrl, requestOptions, {
destType: 'custify',
feature: 'deleteUsers',
requestMethod: 'DELETE',
endpointPath: '/people',
module: 'deletion',
});
const processedDeletionRequest = processAxiosResponse(deletionResponse);
if (processedDeletionRequest.status !== 200 && processedDeletionRequest.status !== 404) {
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/custify/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const createUpdateCompany = async (companyPayload, Config) => {
destType: 'custify',
feature: 'transformation',
endpointPath: `/company`,
requestMethod: 'POST',
module: 'router',
},
);
const processedCompanyResponse = processAxiosResponse(companyResponse);
Expand Down
8 changes: 7 additions & 1 deletion src/v0/destinations/delighted/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ const userValidity = async (channel, Config, userId) => {
},
params: paramsdata,
},
{ destType: 'delighted', feature: 'transformation' },
{
destType: 'delighted',
feature: 'transformation',
requestMethod: 'GET',
endpointPath: '/people.json',
module: 'router',
},
);
if (response && response.data && response.status === 200 && Array.isArray(response.data)) {
return response.data.length > 0;
Expand Down
16 changes: 14 additions & 2 deletions src/v0/destinations/drip/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const userExists = async (Config, id) => {
'Content-Type': JSON_MIME_TYPE,
},
},
{ destType: 'drip', feature: 'transformation' },
{
destType: 'drip',
feature: 'transformation',
requestMethod: 'GET',
endpointPath: '/subscribers/id',
module: 'router',
},
);
if (response && response.status) {
return response.status === 200;
Expand Down Expand Up @@ -70,7 +76,13 @@ const createUpdateUser = async (finalpayload, Config, basicAuth) => {
'Content-Type': JSON_MIME_TYPE,
},
},
{ destType: 'drip', feature: 'transformation' },
{
destType: 'drip',
feature: 'transformation',
requestMethod: 'POST',
endpointPath: '/subscribers',
module: 'router',
},
);
if (response) {
return response.status === 200 || response.status === 201;
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/engage/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const userDeletionHandler = async (userAttributes, config) => {
{
destType: 'engage',
feature: 'deleteUsers',
requestMethod: 'DELETE',
endpointPath: '/users/userId',
module: 'deletion',
},
);
const handledDelResponse = processAxiosResponse(response);
Expand Down
14 changes: 14 additions & 0 deletions src/v0/destinations/freshmarketer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const createUpdateAccount = async (payload, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `/crm/sales/api/sales_accounts/upsert`,
requestMethod: 'POST',
module: 'router',
});
accountResponse = processAxiosResponse(accountResponse);
if (accountResponse.status !== 200 && accountResponse.status !== 201) {
Expand Down Expand Up @@ -95,6 +97,8 @@ const getUserAccountDetails = async (payload, userEmail, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `crm/sales/api/contacts/upsert?include=sales_accounts`,
requestMethod: 'POST',
module: 'router',
});
userSalesAccountResponse = processAxiosResponse(userSalesAccountResponse);
if (userSalesAccountResponse.status !== 200 && userSalesAccountResponse.status !== 201) {
Expand Down Expand Up @@ -145,6 +149,8 @@ const createOrUpdateListDetails = async (listName, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `/crm/sales/api/lists`,
requestMethod: 'GET',
module: 'router',
});
listResponse = processAxiosResponse(listResponse);
if (listResponse.status !== 200) {
Expand All @@ -165,6 +171,8 @@ const createOrUpdateListDetails = async (listName, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `/crm/sales/api/lists`,
requestMethod: 'POST',
module: 'router',
});
listResponse = processAxiosResponse(listResponse);
if (listResponse.status !== 200) {
Expand Down Expand Up @@ -240,6 +248,8 @@ const getContactsDetails = async (userEmail, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `/crm/sales/api/contacts/upsert`,
requestMethod: 'POST',
module: 'router',
});
userResponse = processAxiosResponse(userResponse);
if (userResponse.status !== 200 && userResponse.status !== 201) {
Expand Down Expand Up @@ -314,6 +324,8 @@ const UpdateContactWithLifeCycleStage = async (message, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `/crm/sales/api/selector/lifecycle_stages`,
requestMethod: 'GET',
module: 'router',
});
lifeCycleStagesResponse = processAxiosResponse(lifeCycleStagesResponse);
if (lifeCycleStagesResponse.status !== 200) {
Expand Down Expand Up @@ -400,6 +412,8 @@ const UpdateContactWithSalesActivity = async (payload, message, Config) => {
destType: 'freshmarketer',
feature: 'transformation',
endpointPath: `/crm/sales/api/selector/sales_activity_types`,
requestMethod: 'GET',
module: 'router',
});
salesActivityResponse = processAxiosResponse(salesActivityResponse);
if (salesActivityResponse.status !== 200) {
Expand Down
Loading
Loading