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

feat: add stats for bad events in fb_custom_audience #2192

Merged
merged 14 commits into from
Jun 1, 2023
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
12 changes: 12 additions & 0 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,18 @@ class Prometheus {
500, 600, 700, 800, 900, 1000,
],
},
{
name: 'fb_custom_audience_event_having_all_null_field_values_for_a_user',
help: 'fbcustomaudience event having all null field values for a user',
type: 'counter',
labelNames: ['destinationId'],
},
{
name: 'fb_custom_audience_event_having_all_null_field_values_for_all_users',
help: 'fbcustomaudience event having all null field values for all users',
type: 'counter',
labelNames: ['destinationId'],
},
{
name: 'http_request_size',
help: 'http_request_size',
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/fb_custom_audience/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const preparePayload = (
paramsPayload,
isHashRequired,
disableFormat,
destinationId,
) => {
const prepareFinalPayload = _.cloneDeep(paramsPayload);
if (Array.isArray(userSchema)) {
Expand All @@ -73,6 +74,7 @@ const preparePayload = (
userUpdateList,
isHashRequired,
disableFormat,
destinationId,
);
return batchingWithPayloadSize(prepareFinalPayload);
};
Expand Down Expand Up @@ -125,6 +127,7 @@ const prepareResponse = (
paramsPayload,
isHashRequired,
disableFormat,
destination.ID,
);
// paramsPayload.schema = userSchema;
const respList = [];
Expand Down
28 changes: 26 additions & 2 deletions src/v0/destinations/fb_custom_audience/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const _ = require('lodash');
const sha256 = require('sha256');
const get = require('get-value');
const jsonSize = require('json-size');
const stats = require('../../../util/stats');

const { isDefinedAndNotNull } = require('../../util');
const { maxPayloadSize } = require('./config');
Expand Down Expand Up @@ -128,11 +129,19 @@ const ensureApplicableFormat = (userProperty, userInformation) => {

// Function responsible for making the data field without payload object
// Based on the "isHashRequired" value hashing is explicitly enabled or disabled
const prepareDataField = (userSchema, userUpdateList, isHashRequired, disableFormat) => {
const prepareDataField = (
userSchema,
userUpdateList,
isHashRequired,
disableFormat,
destinationId,
) => {
const data = [];
let updatedProperty;
let dataElement;
let nullEvent = true; // flag to check for bad events (all user properties are null)
userUpdateList.forEach((eachUser) => {
let nullUserData = true; // flag to check for bad event (all properties are null for a user)
dataElement = [];
userSchema.forEach((eachProperty) => {
const userProperty = eachUser[eachProperty];
Expand Down Expand Up @@ -160,9 +169,24 @@ const prepareDataField = (userSchema, userUpdateList, isHashRequired, disableFor
dataElement.push(updatedProperty);
}
});
dataElement.forEach((property) => {
if (property) {
nullUserData = false;
nullEvent = false;
}
});
if (nullUserData) {
stats.increment('fb_custom_audience_event_having_all_null_field_values_for_a_user', {
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
destinationId,
});
}
data.push(dataElement);
});

if (nullEvent) {
stats.increment('fb_custom_audience_event_having_all_null_field_values_for_all_users', {
destinationId,
});
}
return data;
};
module.exports = { prepareDataField, getSchemaForEventMappedToDest, batchingWithPayloadSize };