Skip to content

Introduce LS_JAVA_HOME environment variable#13204

Merged
andsel merged 5 commits into
elastic:masterfrom
andsel:feature/add_ls_java_home
Sep 6, 2021
Merged

Introduce LS_JAVA_HOME environment variable#13204
andsel merged 5 commits into
elastic:masterfrom
andsel:feature/add_ls_java_home

Conversation

@andsel
Copy link
Copy Markdown
Member

@andsel andsel commented Sep 2, 2021

Release notes

Logstash's launch script support LS_JAVA_HOME as an override of environment variable over JAVA_HOME.
It's the path to an installed JDK to be used to launch Logstash's service and support tools.
JAVA_HOME is going to be removed, however if LS_JAVA_HOME is not specified then Logstash still looks for JAVA_HOME.

What does this PR do?

This PR modifies the launch scripts to take care of the LS_JAVA_HOME giving precedence over the JAVA_HOME, which is still used it the first is not found.

Why is it important/What is the impact to the user?

The existing JAVA_HOME is an environment variable globally used by all JVM applications present on a host.
With the introduction of LS_JAVA_HOME the user is able to customize the JDK used by Logstash without changing the global JAVA_HOME. It introduces a layer of separation, permitting a more fine grained control of the JDK customization for Logstash.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • verify it works setting LS_JAVA_HOME on Windows and Linux

How to test this PR locally

  • checkout this branch on your machine
  • on bash set the LS_JAVA_HOME export LS_JAVA_HOME=/path/to/jdk and run `bin/logstash -e "input{stdin{}} output {stdout{codec => rubydebug}}"
  • on Windows cmd set LS_JAVA_HOME="C:\path\to\JDK" and run `bin\logstash -e "input{stdin{}} output {stdout{codec => rubydebug}}"

In both cases it prints the the JDK used and must correspond to what was selected, verify also with rest API curl -XGET 'localhost:9600/_node/jvm?pretty'

Related issues

Use cases

Screenshots

Logs

@andsel andsel marked this pull request as ready for review September 3, 2021 12:39
@andsel andsel requested review from karenzone and removed request for karenzone September 3, 2021 12:40
Copy link
Copy Markdown
Contributor

@roaksoax roaksoax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual changes look good to me. I'll approve on that basis, however, could you please make sure all the comments about messages are addressed before landing?

Comment thread bin/logstash.lib.sh Outdated
if [ -x "$LS_JAVA_HOME/bin/java" ]; then
JAVACMD="$LS_JAVA_HOME/bin/java"
if [ -d "${LOGSTASH_HOME}/${BUNDLED_JDK_PART}" -a -x "${LOGSTASH_HOME}/${BUNDLED_JDK_PART}/bin/java" ]; then
echo "WARNING, using LS_JAVA_HOME while Logstash distribution comes with a bundled JDK"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the format for warnings is "WARNING: ". You are using a ',' instead. So should be:

WARNING: Using LS_JAVA_HOME env variable while Logstash distribution comes with a bundled JDK ()"

I made a couple of minor adjustments. Would be nice to specify which version of the JDK is bundled (the full version). Lets use end of sentence punctuation here as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to print the full version of the bundled JDK could be to execute the "${LOGSTASH_HOME}/${BUNDLED_JDK_PART}/bin/java -version" . But this produces 3 lines of output after the "WARNING:" line, it's not inlined.

Comment thread bin/logstash.lib.sh Outdated

if [ ! -x "$JAVACMD" ]; then
echo "could not find java; set JAVA_HOME or ensure java is in PATH"
echo "could not find java; set LS_JAVA_HOME or ensure java is in PATH"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the first letter be upper cased? (It is a new sentence(. Also, I believe we should use proper punctuation, so should likely need a '.' at the end of all sentences.

Comment thread bin/logstash.lib.sh Outdated
echo "WARNING, using LS_JAVA_HOME while Logstash distribution comes with a bundled JDK"
fi
else
echo "Invalid LS_JAVA_HOME, doesn't contain bin/java executable"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing end of sentence punctuation.

Comment thread bin/setup.bat Outdated
set JAVA="%LS_JAVA_HOME%\bin\java.exe"
echo Using LS_JAVA_HOME defined java: %LS_JAVA_HOME%
if exist "%LS_HOME%\jdk" (
echo WARNING, using LS_JAVA_HOME while Logstash distribution comes with a bundled JDK
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect format, plus missing punctuation.

Comment thread bin/logstash.lib.sh Outdated
JAVACMD_TEST=`command -v java`
if [ -n "$JAVA_HOME" ]; then
if [ -n "$LS_JAVA_HOME" ]; then
echo "Using LS_JAVA_HOME defined java: ${LS_JAVA_HOME}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, punctuation?

Copy link
Copy Markdown
Contributor

@karenzone karenzone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these doc updates, @andsel I left some comments inline for your consideration.

Comment thread docs/static/jvm.asciidoc Outdated
Comment on lines +55 to +56
If {ls} doesn't find `LS_JAVA_HOME` it tries to fall back on `JAVA_HOME` but this behaviour
could be subject to be removed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If {ls} doesn't find `LS_JAVA_HOME` it tries to fall back on `JAVA_HOME` but this behaviour
could be subject to be removed.
If {ls} doesn't find `LS_JAVA_HOME`, it tries to fall back to `JAVA_HOME`. Note that this behavior is experimental and could be subject to removal in later releases.

Comment thread docs/static/jvm.asciidoc
On some Linux systems, you may need to have the `JAVA_HOME` environment
If {ls} doesn't find `LS_JAVA_HOME` it tries to fall back on `JAVA_HOME` but this behaviour
could be subject to be removed.
On some Linux systems, you may need to have the `LS_JAVA_HOME` environment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
On some Linux systems, you may need to have the `LS_JAVA_HOME` environment
On some Linux systems, you may need to have the `LS_JAVA_HOME` environment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest return to break up text block for easier parsing.

@andsel
Copy link
Copy Markdown
Member Author

andsel commented Sep 3, 2021

@karenzone may I ask you a quick eye on the docs part of this PR, located in file docs/static/jvm.asciidoc.
This PR changes the Logstash's launch scripts to that a user can specify the customization of the JDK he wants to use also with LS_JAVA_HOME. This approach has the advantage to don't force the user to change the globally used JAVA_HOME and interfere with other JVM application he could run on the host.

Logstash leverage JAVA_HOME environment variable to give the user the ability to explicitly select a JDK he woudl use.
JAVA_HOME is a variable shared by all applccation that use a JDK, so to avoid conflicts with other services and let
the user to select a specific JDK only for Logstash execution, this commit introduce the LS_JAVA_HOME that takes
precedence over the standard variable.
@andsel andsel force-pushed the feature/add_ls_java_home branch from 128bd61 to d9beb59 Compare September 6, 2021 07:48
@andsel andsel merged commit 979ea21 into elastic:master Sep 6, 2021
andsel added a commit to andsel/logstash that referenced this pull request Sep 8, 2021
This commit modifies the launch scripts to take care of the LS_JAVA_HOME giving precedence over the JAVA_HOME, which is still used it the first is not found.
andsel added a commit that referenced this pull request Sep 8, 2021
Backport of #13204 #13207 to 7.x branch, introduces the LS_JAVA_HOME as preferred environment variable over JAVA_HOME which is deprecated.
@andsel andsel added the v7.16.0 label Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants