Skip to content

Commit

Permalink
chore(release): pull hotfix-release/v1.48.0 into main (#2791)
Browse files Browse the repository at this point in the history
  • Loading branch information
chandumlg authored Nov 3, 2023
2 parents c147906 + 3e1fb26 commit 289ffdc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.48.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.47.0...v1.48.0) (2023-11-02)


### Features

* add support to add custom network policies for specific workspaces in faas pods ([bc1a760](https://github.com/rudderlabs/rudder-transformer/commit/bc1a76066c0aeb43776ded0b266ec48f5e69aa16))

## [1.47.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.46.5...v1.47.0) (2023-10-30)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.47.0",
"version": "1.48.0",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
16 changes: 12 additions & 4 deletions src/util/customTransformer-faas.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { v4: uuidv4 } = require('uuid');
const crypto = require('crypto');
const NodeCache = require('node-cache');
const { getMetadata } = require('../v0/util');
const { getMetadata, getTransformationMetadata } = require('../v0/util');
const stats = require('./stats');
const {
setupFaasFunction,
Expand Down Expand Up @@ -82,10 +82,10 @@ async function setOpenFaasUserTransform(
libraryVersionIds,
pregeneratedFnName,
testMode = false,
trMetadata = {},
) {
const tags = {
transformerVersionId: userTransformation.versionId,
language: userTransformation.language,
identifier: 'openfaas',
testMode,
};
Expand All @@ -106,6 +106,7 @@ async function setOpenFaasUserTransform(
testMode,
),
testMode,
trMetadata,
);

stats.timing('creation_time', setupTime, tags);
Expand All @@ -129,16 +130,22 @@ async function runOpenFaasUserTransform(
const metaTags = events[0].metadata ? getMetadata(events[0].metadata) : {};
const tags = {
transformerVersionId: userTransformation.versionId,
language: userTransformation.language,
identifier: 'openfaas',
testMode,
...metaTags,
};
const trMetadata = events[0].metadata ? getTransformationMetadata(events[0].metadata) : {};

// check and deploy faas function if not exists
const functionName = generateFunctionName(userTransformation, libraryVersionIds, testMode);
if (testMode) {
await setOpenFaasUserTransform(userTransformation, libraryVersionIds, functionName, testMode);
await setOpenFaasUserTransform(
userTransformation,
libraryVersionIds,
functionName,
testMode,
trMetadata,
);
}

const invokeTime = new Date();
Expand All @@ -156,6 +163,7 @@ async function runOpenFaasUserTransform(
testMode,
),
testMode,
trMetadata,
);
stats.timing('run_time', invokeTime, tags);
return result;
Expand Down
62 changes: 52 additions & 10 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const CONFIG_BACKEND_URL = process.env.CONFIG_BACKEND_URL || 'https://api.rudder
const GEOLOCATION_URL = process.env.GEOLOCATION_URL || '';
const FAAS_AST_VID = 'ast';
const FAAS_AST_FN_NAME = 'fn-ast';
const CUSTOM_NETWORK_POLICY_WORKSPACE_IDS = process.env.CUSTOM_NETWORK_POLICY_WORKSPACE_IDS || '';
const customNetworkPolicyWorkspaceIds = CUSTOM_NETWORK_POLICY_WORKSPACE_IDS.split(',');

// Initialise node cache
const functionListCache = new NodeCache();
Expand Down Expand Up @@ -111,7 +113,14 @@ const invalidateFnCache = () => {
functionListCache.set(FUNC_LIST_KEY, []);
};

const deployFaasFunction = async (functionName, code, versionId, libraryVersionIDs, testMode) => {
const deployFaasFunction = async (
functionName,
code,
versionId,
libraryVersionIDs,
testMode,
trMetadata = {},

Check warning on line 122 in src/util/openfaas/index.js

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L122

Added line #L122 was not covered by tests
) => {
try {
logger.debug('[Faas] Deploying a faas function');
let envProcess = 'python index.py';
Expand All @@ -132,19 +141,30 @@ const deployFaasFunction = async (functionName, code, versionId, libraryVersionI
if (GEOLOCATION_URL) {
envVars.geolocation_url = GEOLOCATION_URL;
}
// labels
const labels = {
'openfaas-fn': 'true',
'parent-component': 'openfaas',
'com.openfaas.scale.max': FAAS_MAX_PODS_IN_TEXT,
'com.openfaas.scale.min': FAAS_MIN_PODS_IN_TEXT,
transformationId: trMetadata.transformationId,
workspaceId: trMetadata.workspaceId,
};
if (
trMetadata.workspaceId &&
customNetworkPolicyWorkspaceIds.includes(trMetadata.workspaceId)

Check warning on line 155 in src/util/openfaas/index.js

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L155

Added line #L155 was not covered by tests
) {
labels['custom-network-policy'] = 'true';

Check warning on line 157 in src/util/openfaas/index.js

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L157

Added line #L157 was not covered by tests
}

// TODO: investigate and add more required labels and annotations
const payload = {
service: functionName,
name: functionName,
image: FAAS_BASE_IMG,
envProcess,
envVars,
labels: {
'openfaas-fn': 'true',
'parent-component': 'openfaas',
'com.openfaas.scale.max': FAAS_MAX_PODS_IN_TEXT,
'com.openfaas.scale.min': FAAS_MIN_PODS_IN_TEXT,
},
labels,
annotations: {
'prometheus.io.scrape': 'true',
},
Expand Down Expand Up @@ -175,14 +195,28 @@ const deployFaasFunction = async (functionName, code, versionId, libraryVersionI
}
};

async function setupFaasFunction(functionName, code, versionId, libraryVersionIDs, testMode) {
async function setupFaasFunction(
functionName,
code,
versionId,
libraryVersionIDs,
testMode,
trMetadata = {},

Check warning on line 204 in src/util/openfaas/index.js

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L204

Added line #L204 was not covered by tests
) {
try {
if (!testMode && isFunctionDeployed(functionName)) {
logger.debug(`[Faas] Function ${functionName} already deployed`);
return;
}
// deploy faas function
await deployFaasFunction(functionName, code, versionId, libraryVersionIDs, testMode);
await deployFaasFunction(
functionName,
code,
versionId,
libraryVersionIDs,
testMode,
trMetadata,
);

// This api call is only used to check if function is spinned correctly
await awaitFunctionReadiness(functionName);
Expand All @@ -201,6 +235,7 @@ const executeFaasFunction = async (
versionId,
libraryVersionIDs,
testMode,
trMetadata = {},

Check warning on line 238 in src/util/openfaas/index.js

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L238

Added line #L238 was not covered by tests
) => {
try {
logger.debug('[Faas] Invoking faas function');
Expand All @@ -217,7 +252,14 @@ const executeFaasFunction = async (
error.message.includes(`error finding function ${functionName}`)
) {
removeFunctionFromCache(functionName);
await setupFaasFunction(functionName, null, versionId, libraryVersionIDs, testMode);
await setupFaasFunction(
functionName,
null,
versionId,
libraryVersionIDs,
testMode,
trMetadata,
);
throw new RetryRequestError(`${functionName} not found`);
}

Expand Down
7 changes: 7 additions & 0 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,12 @@ const getMetadata = (metadata) => ({
destinationType: metadata.destinationType,
k8_namespace: metadata.namespace,
});

const getTransformationMetadata = (metadata) => ({
transformationId: metadata.transformationId,
workspaceId: metadata.workspaceId,
});

// checks if array 2 is a subset of array 1
function checkSubsetOfArray(array1, array2) {
const result = array2.every((val) => array1.includes(val));
Expand Down Expand Up @@ -2113,6 +2119,7 @@ module.exports = {
getIntegrationsObj,
getMappingConfig,
getMetadata,
getTransformationMetadata,
getParsedIP,
getStringValueOfJSON,
getSuccessRespEvents,
Expand Down

0 comments on commit 289ffdc

Please sign in to comment.