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

refactor: deprecate mixpanel /track endpoint #2833

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 0 additions & 6 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,6 @@ class Prometheus {
type: 'gauge',
labelNames: ['destination_id'],
},
{
name: 'mixpanel_batch_track_pack_size',
help: 'mixpanel_batch_track_pack_size',
type: 'gauge',
labelNames: ['destination_id'],
},
{
name: 'mixpanel_batch_import_pack_size',
help: 'mixpanel_batch_import_pack_size',
Expand Down
2 changes: 0 additions & 2 deletions src/v0/destinations/mp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const MP_IDENTIFY_EXCLUSION_LIST = [
];

const GEO_SOURCE_ALLOWED_VALUES = [null, 'reverse_geocoding'];
const TRACK_MAX_BATCH_SIZE = 50;
const IMPORT_MAX_BATCH_SIZE = 2000;
const ENGAGE_MAX_BATCH_SIZE = 2000;
const GROUPS_MAX_BATCH_SIZE = 200;
Expand All @@ -68,7 +67,6 @@ module.exports = {
MP_IDENTIFY_EXCLUSION_LIST,
getCreateDeletionTaskEndpoint,
DISTINCT_ID_MAX_BATCH_SIZE,
TRACK_MAX_BATCH_SIZE,
IMPORT_MAX_BATCH_SIZE,
ENGAGE_MAX_BATCH_SIZE,
GROUPS_MAX_BATCH_SIZE,
Expand Down
65 changes: 22 additions & 43 deletions src/v0/destinations/mp/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
BASE_ENDPOINT,
BASE_ENDPOINT_EU,
IMPORT_MAX_BATCH_SIZE,
TRACK_MAX_BATCH_SIZE,
ENGAGE_MAX_BATCH_SIZE,
GROUPS_MAX_BATCH_SIZE,
} = require('./config');
Expand All @@ -47,21 +46,19 @@
const setImportCredentials = (destConfig) => {
const endpoint =
destConfig.dataResidency === 'eu' ? `${BASE_ENDPOINT_EU}/import/` : `${BASE_ENDPOINT}/import/`;
const headers = { 'Content-Type': 'application/json' };
const params = { strict: destConfig.strictMode ? 1 : 0 };
const { apiSecret, serviceAccountUserName, serviceAccountSecret, projectId } = destConfig;
if (apiSecret) {
headers.Authorization = `Basic ${base64Convertor(`${apiSecret}:`)}`;
const { serviceAccountUserName, serviceAccountSecret, projectId, token } = destConfig;
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
let credentials;
if (token) {
credentials = `${token}:`;
} else if (serviceAccountUserName && serviceAccountSecret && projectId) {
headers.Authorization = `Basic ${base64Convertor(
`${serviceAccountUserName}:${serviceAccountSecret}`,
)}`;
credentials = `${serviceAccountUserName}:${serviceAccountSecret}`;

Check warning on line 55 in src/v0/destinations/mp/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/mp/transform.js#L55

Added line #L55 was not covered by tests
params.projectId = projectId;
} else {
throw new InstrumentationError(
'Event timestamp is older than 5 days and no API secret or service account credentials (i.e. username, secret and projectId) are provided in destination configuration',
);
}
const headers = {
'Content-Type': 'application/json',
Authorization: `Basic ${base64Convertor(credentials)}`,
};
return { endpoint, headers, params };
};

Expand All @@ -70,35 +67,25 @@
response.method = defaultPostRequestConfig.requestMethod;
response.userId = message.userId || message.anonymousId;
response.body.JSON_ARRAY = { batch: JSON.stringify([removeUndefinedValues(payload)]) };
const { apiSecret, serviceAccountUserName, serviceAccountSecret, projectId, dataResidency } =
destConfig;
const { dataResidency } = destConfig;
const duration = getTimeDifference(message.timestamp);
switch (eventType) {
case EventType.ALIAS:
case EventType.TRACK:
case EventType.SCREEN:
case EventType.PAGE:
if (
!apiSecret &&
!(serviceAccountUserName && serviceAccountSecret && projectId) &&
duration.days <= 5
) {
response.endpoint =
dataResidency === 'eu' ? `${BASE_ENDPOINT_EU}/track/` : `${BASE_ENDPOINT}/track/`;
response.headers = {};
} else if (duration.years > 5) {
case EventType.PAGE: {
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
if (duration.years > 5) {
throw new InstrumentationError('Event timestamp should be within last 5 years');
} else {
const credentials = setImportCredentials(destConfig);
response.endpoint = credentials.endpoint;
response.headers = credentials.headers;
response.params = {
project_id: credentials.params?.projectId,
strict: credentials.params.strict,
};
break;
}
const credentials = setImportCredentials(destConfig);
response.endpoint = credentials.endpoint;
response.headers = credentials.headers;
response.params = {
project_id: credentials.params?.projectId,
strict: credentials.params.strict,
};
break;
}
case 'merge':
// eslint-disable-next-line no-case-declarations
const credentials = setImportCredentials(destConfig);
Expand Down Expand Up @@ -483,7 +470,6 @@
const batchSize = {
engage: 0,
groups: 0,
track: 0,
import: 0,
};

Expand Down Expand Up @@ -515,23 +501,16 @@
);

transformedPayloads = lodash.flatMap(transformedPayloads);
const { engageEvents, groupsEvents, trackEvents, importEvents, batchErrorRespList } =
const { engageEvents, groupsEvents, importEvents, batchErrorRespList } =
groupEventsByEndpoint(transformedPayloads);

const engageRespList = batchEvents(engageEvents, ENGAGE_MAX_BATCH_SIZE, reqMetadata);
const groupsRespList = batchEvents(groupsEvents, GROUPS_MAX_BATCH_SIZE, reqMetadata);
const trackRespList = batchEvents(trackEvents, TRACK_MAX_BATCH_SIZE, reqMetadata);
const importRespList = batchEvents(importEvents, IMPORT_MAX_BATCH_SIZE, reqMetadata);
const batchSuccessRespList = [
...engageRespList,
...groupsRespList,
...trackRespList,
...importRespList,
];
const batchSuccessRespList = [...engageRespList, ...groupsRespList, ...importRespList];

batchSize.engage += engageRespList.length;
batchSize.groups += groupsRespList.length;
batchSize.track += trackRespList.length;
batchSize.import += importRespList.length;

return [...batchSuccessRespList, ...batchErrorRespList];
Expand Down
8 changes: 1 addition & 7 deletions src/v0/destinations/mp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const createIdentifyResponse = (message, type, destination, responseBuilderSimpl
* @returns
*/
const isImportAuthCredentialsAvailable = (destination) =>
destination.Config.apiSecret ||
destination.Config.token ||
(destination.Config.serviceAccountSecret &&
destination.Config.serviceAccountUserName &&
destination.Config.projectId);
Expand Down Expand Up @@ -179,7 +179,6 @@ const groupEventsByEndpoint = (events) => {
const eventMap = {
engage: [],
groups: [],
track: [],
import: [],
};
const batchErrorRespList = [];
Expand All @@ -204,7 +203,6 @@ const groupEventsByEndpoint = (events) => {
return {
engageEvents: eventMap.engage,
groupsEvents: eventMap.groups,
trackEvents: eventMap.track,
importEvents: eventMap.import,
batchErrorRespList,
};
Expand Down Expand Up @@ -349,7 +347,6 @@ const generatePageOrScreenCustomEventName = (message, userDefinedEventTemplate)
* @param {Object} batchSize - The object containing the batch size for different endpoints.
* @param {number} batchSize.engage - The batch size for engage endpoint.
* @param {number} batchSize.groups - The batch size for group endpoint.
* @param {number} batchSize.track - The batch size for track endpoint.
* @param {number} batchSize.import - The batch size for import endpoint.
* @param {string} destinationId - The ID of the destination.
* @returns {void}
Expand All @@ -361,9 +358,6 @@ const recordBatchSizeMetrics = (batchSize, destinationId) => {
stats.gauge('mixpanel_batch_group_pack_size', batchSize.groups, {
destination_id: destinationId,
});
stats.gauge('mixpanel_batch_track_pack_size', batchSize.track, {
destination_id: destinationId,
});
stats.gauge('mixpanel_batch_import_pack_size', batchSize.import, {
destination_id: destinationId,
});
Expand Down
14 changes: 0 additions & 14 deletions src/v0/destinations/mp/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('Unit test cases for groupEventsByEndpoint', () => {
expect(result).toEqual({
engageEvents: [],
groupsEvents: [],
trackEvents: [],
importEvents: [],
batchErrorRespList: [],
});
Expand Down Expand Up @@ -122,19 +121,6 @@ describe('Unit test cases for groupEventsByEndpoint', () => {
},
},
],
trackEvents: [
{
message: {
endpoint: '/track',
body: {
JSON_ARRAY: {
batch: '[{prop:4}]',
},
},
userId: 'user1',
},
},
],
importEvents: [
{
message: {
Expand Down
2 changes: 1 addition & 1 deletion test/integrations/destinations/mp/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const defaultMockFns = () => {
const sampleDestination: Destination = {
Config: {
apiKey: 'dummyApiKey',
token: 'dummyApiKey',
token: 'test_api_token',
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
prefixProperties: true,
useNativeSDK: false,
},
Expand Down
Loading
Loading