From 47fb27cdf1a468d2001fbe46ff93d8e6c5ba111c Mon Sep 17 00:00:00 2001 From: Abhimanyu Babbar Date: Fri, 1 Mar 2024 11:52:43 +0530 Subject: [PATCH 1/4] fix: added env values for gunicorn workers and threads in openfaas --- src/util/openfaas/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/openfaas/index.js b/src/util/openfaas/index.js index 98f3340cad8..88f95fb2215 100644 --- a/src/util/openfaas/index.js +++ b/src/util/openfaas/index.js @@ -20,6 +20,8 @@ const FAAS_SCALE_TARGET = process.env.FAAS_SCALE_TARGET || '4'; const FAAS_SCALE_TARGET_PROPORTION = process.env.FAAS_SCALE_TARGET_PROPORTION || '0.70'; const FAAS_SCALE_ZERO = process.env.FAAS_SCALE_ZERO || 'false'; const FAAS_SCALE_ZERO_DURATION = process.env.FAAS_SCALE_ZERO_DURATION || '15m'; +const FAAS_GUNICORN_WORKERS = process.env.FAAS_GUNICORN_WORKERS || '1'; +const FAAS_GUNICORN_THREADS = process.env.FAAS_GUNICORN_THREADS || '1'; const FAAS_BASE_IMG = process.env.FAAS_BASE_IMG || 'rudderlabs/openfaas-flask:main'; const FAAS_MAX_PODS_IN_TEXT = process.env.FAAS_MAX_PODS_IN_TEXT || '40'; const FAAS_MIN_PODS_IN_TEXT = process.env.FAAS_MIN_PODS_IN_TEXT || '1'; @@ -209,6 +211,7 @@ const updateFaasFunction = async ( await updateFunction(functionName, payload); // wait for function to be ready and then set it in cache await awaitFunctionReadiness(functionName); + // set the function in cache setFunctionInCache(functionName); } catch (error) { // 404 is statuscode returned from openfaas community edition @@ -392,7 +395,6 @@ const executeFaasFunction = async ( if (error.statusCode === 404 && error.message.includes(`error finding function ${name}`)) { removeFunctionFromCache(name); - await setupFaasFunction(name, null, versionId, libraryVersionIDs, testMode, trMetadata); throw new RetryRequestError(`${name} not found`); } From 00067943573e6262587c2295795c829e261aba66 Mon Sep 17 00:00:00 2001 From: Abhimanyu Babbar Date: Wed, 5 Jun 2024 11:28:49 +0530 Subject: [PATCH 2/4] fix: add gunicorn values in env vars --- src/util/openfaas/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/openfaas/index.js b/src/util/openfaas/index.js index 88f95fb2215..4df7a64aa83 100644 --- a/src/util/openfaas/index.js +++ b/src/util/openfaas/index.js @@ -306,7 +306,10 @@ function buildOpenfaasFn(name, code, versionId, libraryVersionIDs, testMode, trM envProcess = `${envProcess} --code "${code}" --config-backend-url ${CONFIG_BACKEND_URL} --lvids "${lvidsString}"`; } - const envVars = {}; + const envVars = { + GUNICORN_WORKER_COUNT: FAAS_GUNICORN_WORKERS, + GUNICORN_THREAD_COUNT: FAAS_GUNICORN_THREADS, + }; if (FAAS_ENABLE_WATCHDOG_ENV_VARS.trim().toLowerCase() === 'true') { envVars.max_inflight = FAAS_MAX_INFLIGHT; From 423c1bba11b6f252fe140f76d779773189db5176 Mon Sep 17 00:00:00 2001 From: Abhimanyu Babbar Date: Mon, 29 Jul 2024 17:29:38 +0530 Subject: [PATCH 3/4] fix: add env dns resolver --- src/util/openfaas/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/openfaas/index.js b/src/util/openfaas/index.js index 4df7a64aa83..4130066deb9 100644 --- a/src/util/openfaas/index.js +++ b/src/util/openfaas/index.js @@ -51,6 +51,7 @@ const CUSTOM_NETWORK_POLICY_WORKSPACE_IDS = process.env.CUSTOM_NETWORK_POLICY_WO const customNetworkPolicyWorkspaceIds = CUSTOM_NETWORK_POLICY_WORKSPACE_IDS.split(','); const CUSTOMER_TIER = process.env.CUSTOMER_TIER || 'shared'; const FAAS_SCALE_DOWN_WINDOW = process.env.FAAS_SCALE_DOWN_WINDOW || ''; // Go time values are supported ( max 5m or 300s ) +const FAAS_DNS_RESOLVER = process.env.FAAS_DNS_RESOLVER || 'false'; // Initialise node cache const functionListCache = new NodeCache(); @@ -309,6 +310,7 @@ function buildOpenfaasFn(name, code, versionId, libraryVersionIDs, testMode, trM const envVars = { GUNICORN_WORKER_COUNT: FAAS_GUNICORN_WORKERS, GUNICORN_THREAD_COUNT: FAAS_GUNICORN_THREADS, + dns_resolver: FAAS_DNS_RESOLVER, }; if (FAAS_ENABLE_WATCHDOG_ENV_VARS.trim().toLowerCase() === 'true') { From d0cb38b29eee19eee7fb405ba7bd0c4d3b238a5c Mon Sep 17 00:00:00 2001 From: Abhimanyu Babbar Date: Mon, 7 Oct 2024 11:47:08 +0530 Subject: [PATCH 4/4] fix: update the package json start script to properly handle termination signals --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c96d436b3d2..36c06fe5cd8 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint:fix:json": "eslint --ext .json --fix .", "lint": "npm run format && npm run lint:fix", "check:merge": "npm run verify || exit 1; codecov", - "start": "cd dist;node ./src/index.js;cd ..", + "start": "cd dist;exec node ./src/index.js;cd ..", "build:start": "npm run build && npm run start", "build:ci": "tsc -p tsconfig.json", "build:swagger": "npm run build && npm run setup:swagger",