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

chore: added env values for gunicorn workers and threads in openfaas #3150

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
40 changes: 18 additions & 22 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
const { getMetadata, getTransformationMetadata } = require('../../v0/util');
const { HTTP_STATUS_CODES } = require('../../v0/util/constant');

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';
Expand Down Expand Up @@ -135,7 +137,11 @@
envProcess = `${envProcess} --code "${code}" --config-backend-url ${CONFIG_BACKEND_URL} --lvids "${lvidsString}"`;
}

const envVars = {};
const envVars = {

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

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L140

Added line #L140 was not covered by tests
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;
envVars.exec_timeout = FAAS_EXEC_TIMEOUT;
Expand Down Expand Up @@ -247,24 +253,13 @@
try {
if (testMode) await awaitFunctionReadiness(name);
return await invokeFunction(name, events);

} catch (error) {
logger.error(`Error while invoking ${name}: ${error.message}`);
errorRaised = error;

if (
error.statusCode === 404 &&
error.message.includes(`error finding function ${name}`)
) {
if (error.statusCode === 404 && error.message.includes(`error finding function ${name}`)) {
removeFunctionFromCache(name);
await setupFaasFunction(
name,
null,
versionId,
libraryVersionIDs,
testMode,
trMetadata,
);
await setupFaasFunction(name, null, versionId, libraryVersionIDs, testMode, trMetadata);

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

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L262

Added line #L262 was not covered by tests
throw new RetryRequestError(`${name} not found`);
}

Expand All @@ -284,22 +279,23 @@
} finally {
// delete the function created, if it's called as part of testMode
if (testMode) {
deleteFunction(name).catch((err) =>
logger.error(`[Faas] Error while deleting ${name}: ${err.message}`))
deleteFunction(name).catch((err) =>
logger.error(`[Faas] Error while deleting ${name}: ${err.message}`),

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

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L282-L283

Added lines #L282 - L283 were not covered by tests
);
}

// setup the tags for observability and then fire the stats
const tags = {
identifier: "openfaas",
identifier: 'openfaas',
testMode: testMode,
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) : {},
...events.length && events[0].metadata ? getTransformationMetadata(events[0].metadata) : {},
}
...(events.length && events[0].metadata ? getMetadata(events[0].metadata) : {}),
...(events.length && events[0].metadata ? getTransformationMetadata(events[0].metadata) : {}),

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

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L293-L294

Added lines #L293 - L294 were not covered by tests
};

stats.counter('user_transform_function_input_events', events.length, tags)
stats.timing('user_transform_function_latency', startTime, tags)
stats.counter('user_transform_function_input_events', events.length, tags);
stats.timing('user_transform_function_latency', startTime, tags);

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

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L297-L298

Added lines #L297 - L298 were not covered by tests
}
};

Expand Down
Loading