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

node.name=${HOSTNAME} in the environment variable could not be resolved #93218

Open
maomao905 opened this issue Jan 25, 2023 · 4 comments
Open
Labels
>bug :Core/Infra/Settings Settings infrastructure and APIs :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts Team:Core/Infra Meta label for core/infra team Team:Delivery Meta label for Delivery team

Comments

@maomao905
Copy link

maomao905 commented Jan 25, 2023

Elasticsearch Version

8.6.0

Installed Plugins

no installed plugins

Java Version

19.0.1

OS Version

macOS Monterey 12.3.1

Problem Description

I use the environment variable node.name=$HOSTNAME to dynamically set the node name.
It is fine until Elasticsearch version 7.17.7.
When I upgraded to 8.6.0, Elasticsearch failed to start.
The problem is HOSTNAME in the environment variable could not be resolved when starting up Elasticsearch.
The expected behavior is $HOSTNAME should be replaced by the hostname of the running Elasticsearch machine.

Steps to Reproduce

docker-compose up es will reproduce the problem.

  • docker-compose.yml
    $${HOSTNAME} is escaped and should be interpreted as ${HOSTNAME} in Elasticsearch.
    I checked that there is no problem with version 7.17.7 using the image docker.elastic.co/elasticsearch/elasticsearch:7.17.7.
version: '3'
services:
  es:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.6.0
    ports:
      - "9200:9200"
    environment:
      - discovery.type=single-node
      - node.name=$${HOSTNAME}
      - node.roles=master,data
      - ES_JAVA_OPTS=-Xms425m -Xmx425m

I confirmed that the same problem occurs in AWS ECS.

Logs (if relevant)

Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'HOSTNAME'
	at org.elasticsearch.common.settings.PropertyPlaceholder.parseStringValue(PropertyPlaceholder.java:102)
	at org.elasticsearch.common.settings.PropertyPlaceholder.replacePlaceholders(PropertyPlaceholder.java:57)
	at org.elasticsearch.common.settings.Settings$Builder.replacePropertyPlaceholders(Settings.java:1296)
	at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:56)
	at org.elasticsearch.common.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:110)
	at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
	at org.elasticsearch.cli.Command.main(Command.java:50)
	at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)
@maomao905 maomao905 added >bug needs:triage Requires assignment of a team area label labels Jan 25, 2023
@maomao905
Copy link
Author

By the way,
According to the document, the default node name is the hostname of the machine.

The node name defaults to the hostname of the machine when Elasticsearch starts.

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/important-settings.html#node-name

Therefore, there is no need to set ${HOSTNAME} in the environment variable.

But, I actually set the node.name with the prefix of the node role like data.${HOSTNAME}, client.${HOSTNAME}.
That's why we want to specify it by the environment variable.

Alternatively, node.name could be specified in the elasticsearch.yml. But the environment variable is more flexible and does not need an elasticsearch.yml file for each node role.

@dliappis dliappis added the :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts label Jan 25, 2023
@elasticsearchmachine elasticsearchmachine added Team:Delivery Meta label for Delivery team and removed needs:triage Requires assignment of a team area label labels Jan 25, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

@mark-vieira mark-vieira added the :Core/Infra/Settings Settings infrastructure and APIs label Jan 30, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Jan 30, 2023
@mark-vieira
Copy link
Contributor

This is basically the same problem as reported in #90823. The issue here is that we used to allow variable substitution in environment variables with other environment variables, although this was untested, and undocumented, and now this no longer works.

@rjernst Should we treat this as a regression? The previous issue was closed because the original submitter found a workaround but I don't think that would work for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Settings Settings infrastructure and APIs :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts Team:Core/Infra Meta label for core/infra team Team:Delivery Meta label for Delivery team
Projects
None yet
Development

No branches or pull requests

4 participants