Skip to content

Commit

Permalink
updated the tags to be similar on both the ivm and openfaas
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimanyubabbar committed Nov 2, 2023
1 parent 86bd66e commit 94b25f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 12 additions & 10 deletions src/util/customTransformer-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ async function userTransformHandlerV1(
return { transformedEvents : events };
}

const metaTags = events.length && events[0].metadata ? getMetadata(events[0].metadata) : {};
const tags = {
transformerVersionId: userTransformation.versionId,
identifier: 'v1',
language: 'javascript',
...metaTags,
};

const isolatevmFactory = await getFactory(
userTransformation.code,
libraryVersionIds,
Expand All @@ -77,21 +69,31 @@ async function userTransformHandlerV1(
logger.debug(`Creating IsolateVM`);
const isolatevm = await isolatevmFactory.create();

stats.counter('batch_user_transform_events', events.length, tags);
const invokeTime = new Date();
let transformedEvents;
let logs;
let transformationError;

try {
transformedEvents = await transform(isolatevm, events);
} catch (err) {
logger.error(`Error encountered while executing transformation: ${err.message}`);
transformationError = err;
throw err;
} finally {
logger.debug(`Destroying IsolateVM`);
logs = isolatevm.logs;
isolatevmFactory.destroy(isolatevm);
stats.timing('batch_user_transform_request_latency', invokeTime, tags);
// send the observability stats
const tags = {
transformerVersionId: userTransformation.versionId,
identifier: 'v1',
language: 'javascript',
...events.length && events[0].metadata ? getMetadata(events[0].metadata) : {},
errored: transformationError ? true : false
}
stats.counter('batch_user_transform_events', events.length, tags);
stats.timing('batch_user_transform_latency', invokeTime, tags);
}

return { transformedEvents, logs };
Expand Down
8 changes: 5 additions & 3 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const logger = require('../../logger');
const { RetryRequestError, RespStatusError } = require('../utils');
const stats = require('../stats');
const { getMetadata } = require('../../v0/util');
const { HTTP_STATUS_CODES } = require('../../v0/util/constant');


const FAAS_BASE_IMG = process.env.FAAS_BASE_IMG || 'rudderlabs/openfaas-flask:main';
Expand Down Expand Up @@ -249,11 +250,12 @@ const executeFaasFunction = async (
// setup the tags for observability and then fire the stats
const tags = {
transformerVersionId: versionId,
language: "python",
identifier: "openfaas",
language: "python",
testMode: testMode,
statusCode: errorRaised ? errorRaised.statusCode : 200, // default statuscode is 200
...events[0].metadata ? getMetadata(events[0].metadata): {},
errored: errorRaised ? true : false,
statusCode: errorRaised ? errorRaised.statusCode : HTTP_STATUS_CODES.OK, // default statuscode is 200OK
...events.length && events[0].metadata ? getMetadata(events[0].metadata): {},
}

stats.counter('batch_user_transform_events', events.length, tags)
Expand Down

0 comments on commit 94b25f3

Please sign in to comment.