Closed omrishtam closed 5 years ago
Hi if you are changing the fprocess then you must have your own template.
Why don't you create an entrypoint.sh bash script that runs node with all the various options you care about? An alternative is to look at which of these variables are available as environmental variables and to set them that way.
I do this for debugging Node.js
Hope these two solutions are useful for you.
Alex
Who is @omerzamir? Here are two viable solutions within 30 minutes of the issue being created.
@omrishtam I've taken a look at the code and written some unit tests to cover the scenario you raised.
I'll be pushing a fix to address the parsing of the arguments array from fprocess
, but using the environmental variable is what I would recommend for you so that you don't have to hack on or fork the templates and then maintain them out of tree from upstream.
You can add NODE_OPTIONS
easily without changing any templates by adding it in the environment
section of your YAML file or by adding an external environment_file
- this currently has to be a local file, but I would accept a PR to allow this to be a HTTP/s URL if that made things easier for you.
Thanks for your thorough suggestions on a fix - I think in this case the benchmarks won't be as relevant since the code only runs once per of-watchdog start.
If you and @omerzamir would like to contribute please join Slack and check out the contributors' getting started guide -> https://docs.openfaas.com/contributing/get-started/
Alex
Hi 😄, Thanks for the quick response, I'll be using the environment section in my YAML file for now, until a fix is released.
Omri
I've published a new release as: https://github.com/openfaas-incubator/of-watchdog/releases/tag/0.4.6
Alex
We welcome contributions to the project, an initial contribution could be to update the of-watchdog version in some of all of the incubator templates listed in the template store?
https://github.com/openfaas/store/blob/master/templates.json
Would either of you like this or should I find someone else? (please note you have to type in git commit -s
rather than git commit
or editing in the UI for changes to be accepted by the Developer-Certificate of Origin that OpenFaaS uses.
Regards,
Alex
Sure! How do you want us to do this? Should we clone each repo and branch from master and make the change for the Dockerfiles and open a PR for the commit?
Omri
That's basically the pattern right now. We could do with thinking about whether it can be automated in the future.
Setting a command to fprocess which is containing a '=' character is being cut out after the '=' character.
Expected Behaviour
When setting
fprocess="node --max_old_space_size=4096 index.js"
it should execute the index.js script with the given--max_old_space_size
option set to whatever value is given to it (4096 in this example).Current Behaviour
When setting
fprocess="node --max_old_space_size=4096 index.js"
it fails to execute the command and gives the following output when sending a request to the function:Cause of the issue
The issue is caused by the mapEnv function in config.go which is called with a slice of strings of the environment variables in
key=value
form. It splits the fprocess environmemnt variable with a '=' sign separator to map fprocess as a key to the command as a value. When the command is containing a '=' sign it splits the string to unknown number of substrings, but the mapped value (the command which is ran by of-watchdog) is only based on the first substring. This results tofprocess=node --max_old_space_size=4096 index.js
being mapped asmapped["fprocess"]="node --max_old_space_size"
which causes the error.Possible Solution
Possible fixes for the mapEnv function in https://github.com/openfaas-incubator/of-watchdog/blob/85505a7210cf413e455f8a03d74ba94d9a9fcd30/config/config.go#L89-L101
1. strings.Join in line 97:
mapped[parts[0]] = strings.Join(parts[1:], "=")
2. strings.SplitN in line 93:
parts := strings.SplitN(val, "=", 2)
Both would result to the mapping correctly as
mapped["fprocess"]="node --max_old_space_size=4096 index.js"
.3. setting an environment variable for the function (temporal fix):
It's possible to set environment variables in the function's YAML file as described here: https://github.com/openfaas-incubator/node10-express-template For example node can set
NODE_OPTIONS="--max-old-space-size=4096"
to use the option, though this may not be suitable for all use cases.Benchmarks
Benchmark for solution 1 (strings.Join):
Result:
Benchmark for solution 2 (strings.SplitN):
Result:
Overall the use of strings.SplitN (solution 2) to solve this issue seems better.
Steps to Reproduce (for bugs)
git clone https://github.com/openfaas-incubator/of-watchdog.git
go get -u github.com/openfaas-incubator/of-watchdog/config
go get -u github.com/openfaas-incubator/of-watchdog/executor
go build
fprocess="node --max_old_space_size=4096 index.js" ./of-watchdog
Context
I've deployed a nodeJS function based on https://github.com/openfaas-incubator/node10-express-template which required an increase of the maximum memory allocation for the function to run correctly. I encountered this issue and its temporal fix (solution 3) by setting the
--max_old_space_size=4096
option which caused the issue and forced me to set it as an environment variable for the function in the YAML file.Your Environment
docker version 18.06
I'm using
Docker Swarm
(FaaS-netes)Operating System and version (e.g. Linux, Windows, MacOS):
Ubuntu 16.04, Windows 10 Build 17134