opensearch-build icon indicating copy to clipboard operation
opensearch-build copied to clipboard

[Bug]: Snake case environment variables for settings do not work #20

Open gowrizrh opened this issue 6 months ago • 8 comments

Describe the bug

We are migrating from Elasticsearch to Opensearch. We mostly use bitbucket pipelines to run functional or integration api testing where Elasticsearch is required as a service.

Currently, configuration of Opensearch via Docker variables is possible. -e discovery.type=single-node

However, Bitbucket pipelines does not allow dots in variable definition for services.

See https://jira.atlassian.com/browse/BCLOUD-18007

As a very quick example, running echo $DOT.VARIABLE in Shell or Bash would evaluate $DOT as a variable and then append .VARIABLE verbatim, rather than evaluate $DOT.VARIABLE as a whole. Though there are some scenarios where this does work as expected, such as how Elasticsearch reads the variables.

As far as I can tell from this ticket, this feature was needed primarily for the Elasticsearch Docker image. And Elasticsearch has offered a workaround for this problem:

See Elasticsearch's workaround https://github.com/elastic/elasticsearch/issues/74036

For example discovery.type would become ES_SETTING_DISCOVERY_TYPE. This type of environment variable no longer works in Opensearch and it fails to boot up because of the bootstrap checks.

To reproduce

Start a simple container passing in a snake cased variant of the configuration option.

docker run --rm -it -e "ES_SETTING_DISCOVERY_TYPE=single-node" opensearchproject/opensearch:latest

Results in the following logs

[2023-03-16T23:39:08,792][INFO ][o.o.b.BootstrapChecks    ] [fcd52ae49431] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_cluster_manager_nodes / cluster.initial_master_nodes] must be configured
ERROR: OpenSearch did not exit normally - check the logs at /usr/share/opensearch/logs/docker-cluster.log

Expected behavior

A workaround or an alternative syntax to pass in variables without the dot format like Elasticsearch.

For example the docker environment variable ES_SETTING_DISCOVERY_TYPE is the same as discovery.type

Screenshots

No response

Host / Environment

Docker version 23.0.1, build a5ee5b1

Additional context

This is a copy of https://github.com/opensearch-project/docker-images/issues/20

Relevant log output

No response

gowrizrh avatar Feb 14 '24 01:02 gowrizrh

Thanks for creating this issue. While we work on providing you a work around, is it possible for you mount opensearch.yml from your local to the container to overcome this issue? Tagging @peterzhuamazon for any other work around that he may know of.

Also, https://github.com/opensearch-project/docker-images is on deprecation path, if you want to create OpenSearch docker images form source please follow https://github.com/opensearch-project/opensearch-build/blob/main/docker/release/README.md.

rishabh6788 avatar Feb 15 '24 02:02 rishabh6788

@rishabh6788 No, not at least for us. This is in a throw away CI environment. There is no way to mount files in Bitbucket's pipeline runners

https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/

Our current workaround is using Elasticsearch.

gowrizrh avatar Feb 15 '24 03:02 gowrizrh

Hi @gowrizrh are you able to run docker with this command? Basically wrapping the env var with double quotes such as this: https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/#configure-opensearch

docker run -it -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:latest

peterzhuamazon avatar Feb 19 '24 19:02 peterzhuamazon

Hi @andrross @mch2 seems like we do not see similar env var for discovery.type in core. Could you help checking this up so @gowrizrh can use a env var that without . to specify discovery.type during docker deployment?

Thanks.

peterzhuamazon avatar Feb 19 '24 19:02 peterzhuamazon

Hello @andrross @mch2 Can you please provide your inputs?

bbarani avatar Mar 18 '24 17:03 bbarani

@peterzhuamazon Does the double quote approach work? If not, we could add snake case environment variables in core if that make things easier.

andrross avatar Mar 18 '24 17:03 andrross

Screenshot 2024-03-27 at 3 03 17 PM Screenshot 2024-03-27 at 3 03 35 PM

This is what happens when attempting to use a list, or a map with dot notation in Bitbucket Pipelines.

I've attempted the following formats for environment (taken from the sample yml):

 environment:
        - cluster.name=opensearch-cluster
        - node.name=opensearch
        - discovery.seed_hosts=opensearch
        - cluster.initial_cluster_manager_nodes=opensearch
        - bootstrap.memory_lock=true
        - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
        - "DISABLE_INSTALL_DEMO_CONFIG=true"
        - "DISABLE_SECURITY_PLUGIN=true"

environment:
        cluster.name: opensearch-cluster
        node.name: opensearch
        discovery.seed_hosts: opensearch
        cluster.initial_cluster_manager_nodes: opensearch
        bootstrap.memory_lock: "true"
        OPENSEARCH_JAVA_OPTS: "-Xms512m -Xmx512m"
        DISABLE_INSTALL_DEMO_CONFIG: "true"
        DISABLE_SECURITY_PLUGIN: "true"

What Bitbucket Pipelines would require:

environment:
        CUSTER_NAME: opensearch-cluster
        NODE_NAME: opensearch
        DISCOVERY_SEED_HOSTS: opensearch
        CLUSTER_INITIAL_CLUSTER_MANAGER_NODES: opensearch
        BOOTSTRAP_MEMORY_LOCK: "true"
        OPENSEARCH_JAVA_OPTS: "-Xms512m -Xmx512m"
        DISABLE_INSTALL_DEMO_CONFIG: "true"
        DISABLE_SECURITY_PLUGIN: "true"

jhauserdev avatar Mar 27 '24 19:03 jhauserdev