-
Notifications
You must be signed in to change notification settings - Fork 313
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
Remove os environment variables from env prep #978
Conversation
The launcher pulls in local environment variables from the OS prior to launching elasticsearch. This can be problematic if the JAVA_HOME variable is locally set, but explicitly not set by the rally launcher. For the case of the bundled JDK, a variable java_home is explicitly unset, which should be reconciled with the local env by also unsetting JAVA_HOME if it exists before launching. This commit ensures that if java_home is unset in the code, that the local env's JAVA_HOME variable is also unset. Closes elastic#976
@dliappis this commit does not remove any of the JAVAXX_HOME's, but I did not see the usefulness of that inside how we operate w/ rally today. I can do it, but I think that this PR fixes the bug that was present when we moved to the bundled jdk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I left two comments.
esrally/mechanic/launcher.py
Outdated
@@ -175,6 +175,9 @@ def _prepare_env(self, car_env, node_name, java_home, t): | |||
self._set_env(env, "PATH", os.path.join(java_home, "bin"), separator=os.pathsep, prepend=True) | |||
# Don't merge here! | |||
env["JAVA_HOME"] = java_home | |||
elif env.get("JAVA_HOME"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we take a cleaner (and bolder) approach and not inherit anything from the env apart from PATH?
Practically speaking I thought about replacing lines 172 and 172 with something like:
env={k:v for k, v in os.environ.items() if k == "PATH"}
TBH I can't think of what we need from the shell PATH to launch ES, we might just as well be ok with removing line 172 altogether, but typically all launched Elasticsearches (even in Docker) will have something in PATH so this sounds ok to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that approach as it is much cleaner. I can think of situations when we want to set other environment variables like LD_LIBRARY_PATH
in order set a custom allocator like jemalloc to use it for analyzing native memory leaks.
I suggest that we leverage our config object here to only pass PATH
by default but allow to override it with a config property. We should avoid using the config object everywhere and instead derive a property in the constructor of ProcessLauncher
as follows:
from esrally.utils import opts
#...
self.pass_env_vars = opts.csv_to_list(self.cfg.opts("system", "passenv", mandatory=False, default_value="PATH"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to overwriting ES_JAVA_OPTS
? Or append the ExitOnOOM to it? Ill leave it currently as overwriting, unless we want to change the behaviour here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After chatting w @dliappis, we will honor the user's ES_JAVA_OPTS
if provided in the rally.ini, otherwise we will add the flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to always glean the PATH
even if it is not specified in the config? As is if the user adds variables, they might forget the path and then 💥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend not to apply any special logic for PATH
and would favor if the user would clearly see what environment variables are passed. I also expect that the default will only be overridden in very special circumstances (like the example I've provided above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will remove the PATH special case!
esrally/mechanic/launcher.py
Outdated
@@ -175,6 +175,9 @@ def _prepare_env(self, car_env, node_name, java_home, t): | |||
self._set_env(env, "PATH", os.path.join(java_home, "bin"), separator=os.pathsep, prepend=True) | |||
# Don't merge here! | |||
env["JAVA_HOME"] = java_home | |||
elif env.get("JAVA_HOME"): | |||
# Assume that since java_home was not passed in, it should be unset in the environment if it exists | |||
del env["JAVA_HOME"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we adjust the test in launcher_test#test_bundled_jdk_not_in_path() to fail with our current code, i.e. actually check that the JAVA_HOME env var remains unset even if set in os.environ?
I want to ensure yall are ok w/ the functionality here. I added a check to keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
However we have a number of reference to JAVA_HOME
in our docs:
- https://esrally.readthedocs.io/en/latest/quickstart.html?highlight=JAVA_HOME#install
https://esrally.readthedocs.io/en/stable/command_line_reference.html?highlight=JAVA_HOME#runtime-jdk
At least in the latter we should clearly explain what happens when bundled is in use and JAVA_HOME
is set.
Possibly we should also document the change in behavior in the migration guide (for Rally 2.0.0) to avoid people wondering with existing JAVA_HOME isn't honored any more in https://esrally.readthedocs.io/en/stable/migrate.html?
Good call on the JAVA_HOME comments. Would you like this done as part of this PR or a followup? |
Regarding
|
Running with
And what is interesting, running with |
As per @rjernst , the fallback from finding java on the path (which is why Our code, however, allows for a Should we change this so the code in 7.0 and above just uses the bundled JDK if the JAVA_HOME variables are not set? edit: I have found out how the car definitions ensure that one of the environment variables for a given runtime jdk are ensured. I wonder still if we should be erroring out if bundled is not set explicitly, or should be falling back to using the bundled JDK. |
I have added a note about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
docs/migrate.rst
Outdated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Rally can optionally use the bundled runtime JDK by setting ``--runtime-jdk="bundled"``. This setting will use the JDK that is bundled with | ||
elasticsearch and not honor any ``JAVA_HOME`` settings you may have set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: capitalization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will curse me till the day I die I think.
This commit removes an explicit add of the JAVA_HOME environment variable from the _prepare_env method, which will, if the bundled JDK is selected, ensure that Elasticsearch will not use a JAVA_HOME environment variable instead of the bundled JDK. This commit does not remove the use of the JAVA_HOME environment variables in the event that the bundled JDK is not chosen, which is resolved in a different place. Closes elastic#976
The launcher pulls in local environment variables from the OS prior to
launching Elasticsearch. This can be problematic if the $JAVA_HOME
variable is locally set, but explicitly not set by the Rally
launcher. For the case of the bundled JDK, a variable java_home is
explicitly unset, which should be reconciled with the local env by also
unsetting $JAVA_HOME if it exists before launching. This commit ensures
that if java_home is unset in the code, that the local env's $JAVA_HOME
variable is also unset.
Closes #976