Skip to content

Commit c1449e0

Browse files
feat: support cloud OpenSearch via environment variables (opensearch-project#89)
* feat: support cloud OpenSearch via environment variables - Make OpenSearch Dashboards URL configurable (host, port, protocol) - Move opensearch and opensearch-dashboards to docker-compose.local-opensearch.yml, included by default; comment out INCLUDE_COMPOSE_LOCAL_OPENSEARCH in .env to switch to a cloud cluster - Make data-prepper pipelines use OPENSEARCH_HOST/PORT placeholders instead of hardcoded opensearch:9200 - Move opensearch-dashboards-init to main compose file so it works with both local and cloud deployments Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: fudongying <fudongying@bytedance.com> * feat: kylehounslow's comment Signed-off-by: fudongying <fudongying@bytedance.com> * fix: harden install.sh and document TLS skip-verify behavior - Extract read_env_var() helper in install.sh to safely read .env values without crashing on missing keys (grep non-zero exit + set -e/pipefail) - Add -k flag to OSD health check curl so HTTPS cloud Dashboards do not hang - Document in README that all HTTPS connections skip certificate verification (Data Prepper, OSD config, init script, install.sh health checks) and list where to enable verification for production environments Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: fudongying <fudongying@bytedance.com> * chore: delete auth info in document Signed-off-by: fudongying <fudongying@bytedance.com> --------- Signed-off-by: fudongying <fudongying@bytedance.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c18245f commit c1449e0

9 files changed

Lines changed: 277 additions & 125 deletions

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# Include additional compose files (comment out to disable)
88
INCLUDE_COMPOSE_EXAMPLES=docker-compose.examples.yml
99
# INCLUDE_COMPOSE_OTEL_DEMO=docker-compose.otel-demo.yml
10+
INCLUDE_COMPOSE_LOCAL_OPENSEARCH=docker-compose.local-opensearch.yml
11+
INCLUDE_COMPOSE_LOCAL_OPENSEARCH_DASHBOARDS=docker-compose.local-opensearch-dashboards.yml
1012

1113
# OPENSEARCH_DOCKER_REPO=opensearchproject
1214
OPENSEARCH_DOCKER_REPO=opensearchstaging
@@ -18,11 +20,14 @@ OPENSEARCH_USER=admin
1820
OPENSEARCH_PASSWORD='My_password_123!@#'
1921
OPENSEARCH_HOST=opensearch
2022
OPENSEARCH_PORT=9200
23+
OPENSEARCH_PROTOCOL=https
2124
OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
2225

2326
# OpenSearch Dashboards Configuration
2427
OPENSEARCH_DASHBOARDS_VERSION=3.6.0
28+
OPENSEARCH_DASHBOARDS_HOST=opensearch-dashboards
2529
OPENSEARCH_DASHBOARDS_PORT=5601
30+
OPENSEARCH_DASHBOARDS_PROTOCOL=http
2631

2732
# OpenTelemetry Collector Configuration
2833
OTEL_COLLECTOR_VERSION=0.146.1
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Local OpenSearch Dashboards - include this file when running OpenSearch Dashboards locally
2+
# Included by default via INCLUDE_COMPOSE_LOCAL_OPENSEARCH_DASHBOARDS in .env
3+
# To use a cloud OpenSearch Dashboards instance, comment out INCLUDE_COMPOSE_LOCAL_OPENSEARCH_DASHBOARDS in .env
4+
5+
x-default-logging: &logging
6+
driver: "json-file"
7+
options:
8+
max-size: "5m"
9+
max-file: "2"
10+
tag: "{{.Name}}"
11+
12+
services:
13+
# OpenSearch Dashboards - Web UI for visualizing logs and traces
14+
opensearch-dashboards:
15+
image: ${OPENSEARCH_DOCKER_REPO}/opensearch-dashboards:${OPENSEARCH_DASHBOARDS_VERSION}
16+
container_name: opensearch-dashboards
17+
pull_policy: always
18+
command: >
19+
/bin/bash -c "
20+
cp /tmp/opensearch_dashboards.template.yml /tmp/opensearch_dashboards.yml &&
21+
sed -i 's|OPENSEARCH_HOSTS|${OPENSEARCH_PROTOCOL}://${OPENSEARCH_HOST}:${OPENSEARCH_PORT}|g' /tmp/opensearch_dashboards.yml &&
22+
sed -i 's|OPENSEARCH_USER|${OPENSEARCH_USER}|g' /tmp/opensearch_dashboards.yml &&
23+
sed -i 's|OPENSEARCH_PASSWORD|${OPENSEARCH_PASSWORD}|g' /tmp/opensearch_dashboards.yml &&
24+
cp /tmp/opensearch_dashboards.yml /usr/share/opensearch-dashboards/config/opensearch_dashboards.yml &&
25+
cd /usr/share/opensearch-dashboards &&
26+
exec ./opensearch-dashboards-docker-entrypoint.sh opensearch-dashboards"
27+
environment:
28+
- OPENSEARCH_DASHBOARD_PORT=${OPENSEARCH_DASHBOARDS_PORT}
29+
volumes:
30+
- ./docker-compose/opensearch-dashboards/opensearch_dashboards.template.yml:/tmp/opensearch_dashboards.template.yml
31+
ports:
32+
# Web UI endpoint
33+
- "${OPENSEARCH_DASHBOARDS_PORT}:5601"
34+
networks:
35+
- observability-stack-network
36+
restart: unless-stopped
37+
deploy:
38+
resources:
39+
limits:
40+
memory: ${DASHBOARDS_MEMORY_LIMIT}
41+
healthcheck:
42+
test: curl -f -u '${OPENSEARCH_USER}':'${OPENSEARCH_PASSWORD}' http://localhost:5601/api/status || exit 1
43+
start_period: 60s
44+
interval: 10s
45+
timeout: 5s
46+
retries: 12
47+
logging: *logging
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Local OpenSearch - include this file when running OpenSearch locally instead of cloud
2+
# Included by default via INCLUDE_COMPOSE_LOCAL_OPENSEARCH in .env
3+
# To use a cloud OpenSearch instance, comment out INCLUDE_COMPOSE_LOCAL_OPENSEARCH in .env
4+
5+
x-default-logging: &logging
6+
driver: "json-file"
7+
options:
8+
max-size: "5m"
9+
max-file: "2"
10+
tag: "{{.Name}}"
11+
12+
volumes:
13+
opensearch-data:
14+
driver: local
15+
16+
services:
17+
# OpenSearch - Stores and indexes logs and traces for search and analysis
18+
opensearch:
19+
image: ${OPENSEARCH_DOCKER_REPO}/opensearch:${OPENSEARCH_VERSION}
20+
container_name: opensearch
21+
pull_policy: always
22+
environment:
23+
# Single-node cluster for development
24+
- cluster.name=observability-stack-cluster
25+
- node.name=observability-stack-node
26+
- discovery.type=single-node
27+
- bootstrap.memory_lock=true
28+
# Set heap size (adjust based on available memory)
29+
- OPENSEARCH_JAVA_OPTS=${OPENSEARCH_JAVA_OPTS}
30+
# Initial admin password (required for OpenSearch 2.12+)
31+
- "OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD}"
32+
- plugins.query.datasources.encryption.masterkey=BTqK4Ytdz67La1kShIKV3Pu9
33+
volumes:
34+
# Persist data across container restarts
35+
- opensearch-data:/usr/share/opensearch/data
36+
ports:
37+
# REST API endpoint
38+
- "${OPENSEARCH_PORT}:9200"
39+
# Performance analyzer
40+
- "9600:9600"
41+
networks:
42+
- observability-stack-network
43+
restart: unless-stopped
44+
deploy:
45+
resources:
46+
limits:
47+
memory: ${OPENSEARCH_MEMORY_LIMIT}
48+
ulimits:
49+
memlock:
50+
soft: -1
51+
hard: -1
52+
nofile:
53+
soft: 65536
54+
hard: 65536
55+
healthcheck:
56+
test: curl -s -k -u '${OPENSEARCH_USER}':'${OPENSEARCH_PASSWORD}' ${OPENSEARCH_PROTOCOL}://localhost:9200/_cluster/health | grep -E '"status":"(green|yellow)"'
57+
start_period: 120s
58+
interval: 5s
59+
timeout: 10s
60+
retries: 30
61+
logging: *logging
62+
63+
# Add depends_on opensearch to services that need it for local startup ordering
64+
otel-collector:
65+
depends_on:
66+
opensearch:
67+
condition: service_healthy
68+
69+
data-prepper:
70+
depends_on:
71+
opensearch:
72+
condition: service_healthy

docker-compose.yml

Lines changed: 14 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
include:
66
- path: ${INCLUDE_COMPOSE_EXAMPLES:-docker-compose/util/docker-compose.empty.yml}
77
- path: ${INCLUDE_COMPOSE_OTEL_DEMO:-docker-compose/util/docker-compose.empty.yml}
8+
- path: ${INCLUDE_COMPOSE_LOCAL_OPENSEARCH:-docker-compose/util/docker-compose.empty.yml}
9+
- path: ${INCLUDE_COMPOSE_LOCAL_OPENSEARCH_DASHBOARDS:-docker-compose/util/docker-compose.empty.yml}
810

911
x-default-logging: &logging
1012
driver: "json-file"
@@ -19,8 +21,6 @@ networks:
1921
driver: bridge
2022

2123
volumes:
22-
opensearch-data:
23-
driver: local
2424
prometheus-data:
2525
driver: local
2626

@@ -54,9 +54,6 @@ services:
5454
- OPENSEARCH_HOST=${OPENSEARCH_HOST}
5555
- OPENSEARCH_PORT=${OPENSEARCH_PORT}
5656
- GOMEMLIMIT=160MiB
57-
depends_on:
58-
opensearch:
59-
condition: service_healthy
6057
logging: *logging
6158

6259
# Data Prepper - Transforms and enriches logs/traces before OpenSearch ingestion
@@ -71,6 +68,9 @@ services:
7168
chmod +w /tmp/pipelines.yaml &&
7269
sed -i 's|OPENSEARCH_USER|${OPENSEARCH_USER}|g' /tmp/pipelines.yaml &&
7370
sed -i 's|OPENSEARCH_PASSWORD|${OPENSEARCH_PASSWORD}|g' /tmp/pipelines.yaml &&
71+
sed -i 's|OPENSEARCH_PROTOCOL|${OPENSEARCH_PROTOCOL}|g' /tmp/pipelines.yaml &&
72+
sed -i 's|OPENSEARCH_HOST|${OPENSEARCH_HOST}|g' /tmp/pipelines.yaml &&
73+
sed -i 's|OPENSEARCH_PORT|${OPENSEARCH_PORT}|g' /tmp/pipelines.yaml &&
7474
mv /tmp/pipelines.yaml /usr/share/data-prepper/pipelines/pipelines.yaml &&
7575
exec /usr/share/data-prepper/bin/data-prepper"
7676
volumes:
@@ -86,9 +86,6 @@ services:
8686
- OPENSEARCH_PORT=${OPENSEARCH_PORT}
8787
- OPENSEARCH_USER=${OPENSEARCH_USER}
8888
- OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD}
89-
depends_on:
90-
opensearch:
91-
condition: service_healthy
9289
networks:
9390
- observability-stack-network
9491
restart: unless-stopped
@@ -98,52 +95,6 @@ services:
9895
memory: ${DATA_PREPPER_MEMORY_LIMIT}
9996
logging: *logging
10097

101-
# OpenSearch - Stores and indexes logs and traces for search and analysis
102-
opensearch:
103-
image: ${OPENSEARCH_DOCKER_REPO}/opensearch:${OPENSEARCH_VERSION}
104-
container_name: opensearch
105-
pull_policy: always
106-
environment:
107-
# Single-node cluster for development
108-
- cluster.name=observability-stack-cluster
109-
- node.name=observability-stack-node
110-
- discovery.type=single-node
111-
- bootstrap.memory_lock=true
112-
# Set heap size (adjust based on available memory)
113-
- OPENSEARCH_JAVA_OPTS=${OPENSEARCH_JAVA_OPTS}
114-
# Initial admin password (required for OpenSearch 2.12+)
115-
- "OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD}"
116-
- plugins.query.datasources.encryption.masterkey=BTqK4Ytdz67La1kShIKV3Pu9
117-
volumes:
118-
# Persist data across container restarts
119-
- opensearch-data:/usr/share/opensearch/data
120-
ports:
121-
# REST API endpoint
122-
- "${OPENSEARCH_PORT}:9200"
123-
# Performance analyzer
124-
- "9600:9600"
125-
networks:
126-
- observability-stack-network
127-
restart: unless-stopped
128-
deploy:
129-
resources:
130-
limits:
131-
memory: ${OPENSEARCH_MEMORY_LIMIT}
132-
ulimits:
133-
memlock:
134-
soft: -1
135-
hard: -1
136-
nofile:
137-
soft: 65536
138-
hard: 65536
139-
healthcheck:
140-
test: curl -s -k -u '${OPENSEARCH_USER}':'${OPENSEARCH_PASSWORD}' https://localhost:9200/_cluster/health | grep -E '"status":"(green|yellow)"'
141-
start_period: 120s
142-
interval: 5s
143-
timeout: 10s
144-
retries: 30
145-
logging: *logging
146-
14798
# Prometheus - Time-series database for metrics storage
14899
prometheus:
149100
image: prom/prometheus:${PROMETHEUS_VERSION}
@@ -178,49 +129,20 @@ services:
178129
memory: ${PROMETHEUS_MEMORY_LIMIT}
179130
logging: *logging
180131

181-
# OpenSearch Dashboards - Web UI for visualizing logs and traces
182-
opensearch-dashboards:
183-
image: ${OPENSEARCH_DOCKER_REPO}/opensearch-dashboards:${OPENSEARCH_DASHBOARDS_VERSION}
184-
container_name: opensearch-dashboards
185-
pull_policy: always
186-
environment:
187-
- OPENSEARCH_HOSTS=["https://${OPENSEARCH_HOST}:${OPENSEARCH_PORT}"]
188-
- OPENSEARCH_DASHBOARD_PORT=${OPENSEARCH_DASHBOARDS_PORT}
189-
- OPENSEARCH_USER=${OPENSEARCH_USER}
190-
- OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD}
191-
volumes:
192-
- ./docker-compose/opensearch-dashboards/opensearch_dashboards.yml:/usr/share/opensearch-dashboards/config/opensearch_dashboards.yml
193-
ports:
194-
# Web UI endpoint
195-
- "${OPENSEARCH_DASHBOARDS_PORT}:5601"
196-
depends_on:
197-
opensearch:
198-
condition: service_healthy
199-
networks:
200-
- observability-stack-network
201-
restart: unless-stopped
202-
deploy:
203-
resources:
204-
limits:
205-
memory: ${DASHBOARDS_MEMORY_LIMIT}
206-
healthcheck:
207-
test: curl -f -u '${OPENSEARCH_USER}':'${OPENSEARCH_PASSWORD}' http://localhost:5601/api/status || exit 1
208-
start_period: 60s
209-
interval: 10s
210-
timeout: 5s
211-
retries: 12
212-
logging: *logging
213-
214-
# OpenSearch Dashboards Initialization - Creates workspace and index patterns
132+
# OpenSearch Dashboards Initialization - Creates workspace, index patterns, and saved queries
215133
opensearch-dashboards-init:
216134
image: python:3.11-alpine
217135
container_name: opensearch-dashboards-init
218136
command: sh -c "pip install requests pyyaml && python /init.py"
219-
depends_on:
220-
opensearch-dashboards:
221-
condition: service_healthy
222137
environment:
138+
- OPENSEARCH_USER=${OPENSEARCH_USER}
223139
- OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD}
140+
- OPENSEARCH_HOST=${OPENSEARCH_HOST}
141+
- OPENSEARCH_PORT=${OPENSEARCH_PORT}
142+
- OPENSEARCH_PROTOCOL=${OPENSEARCH_PROTOCOL}
143+
- OPENSEARCH_DASHBOARDS_HOST=${OPENSEARCH_DASHBOARDS_HOST}
144+
- OPENSEARCH_DASHBOARDS_PORT=${OPENSEARCH_DASHBOARDS_PORT}
145+
- OPENSEARCH_DASHBOARDS_PROTOCOL=${OPENSEARCH_DASHBOARDS_PROTOCOL}
224146
- PROMETHEUS_HOST=${PROMETHEUS_HOST}
225147
- PROMETHEUS_PORT=${PROMETHEUS_PORT}
226148
volumes:
@@ -232,3 +154,4 @@ services:
232154
- observability-stack-network
233155
restart: "no"
234156
logging: *logging
157+

0 commit comments

Comments
 (0)