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

Respect environment variables in jvm.options #16834

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kaisecheng
Copy link
Contributor

@kaisecheng kaisecheng commented Dec 24, 2024

Release notes

Add support for ${VAR:default} syntax in jvm.options file

What does this PR do?

JvmOptionsParser adds support for ${VAR:default} syntax when parsing jvm.options

  • allow dynamic resolution of environment variables in the jvm.options file
  • enables fallback to default value when the environment variable is not set

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

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I 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

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@kaisecheng kaisecheng marked this pull request as ready for review December 27, 2024 15:17
Copy link
Member

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

I like that we skip this if we have a commented or empty line. Doing the regex on every "valid" line in config is probably low overhead in practice. Overall I think this will work for the majority of cases but it does have some requirements and edges that may be worth documenting.

  1. Spell out the highlights from the regexes \$\{ [A-Z_][A-Z0-9_]* (mainly that the substitution must be in form ${FOO} not $FOO, the name must be all caps and not start with an underscore etc ${FOO} not ${foo} and the default syntax).
  2. Nested substitution wont work ${ROOT:${LEAF}}
  3. Default values cannot have colons or dollar signs (i think this is relevant because we have an example of such in
    #-Djava.io.tmpdir=$HOME
    )
  4. There is no escape characters (relates to 3)

Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@kaisecheng
Copy link
Contributor Author

@donoghuc thanks for the edge case checking! I overlooked that we support lowercase variable and the $HOME in jvm.options.

Logstash has documented about the dollar sign variable. $VAR is not the pattern Logstash support. Honestly the variables in jvm.options were interpreted in bash script which has different syntax to logstash env variable. Given that no reported issue on resolving the env var in jvm.options and it has been failing to resolve since 8.0, in this PR, I make it align to Logstash syntax. I noticed that we have different convention in log4j. I will raise the question in weekly sync.

I updated the pattern to align to the current ruby substitution. We do not support nested variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment variables in jvm.options are not replaced by the JvmOptionsParser
3 participants