Skip to content

Commit 8e5d3a5

Browse files
authored
create_elasticsearch_config_from_env (#271)
1 parent 71ddf9b commit 8e5d3a5

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

eval_protocol/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ def parse_args(args=None):
301301
logs_parser = subparsers.add_parser("logs", help="Serve logs with file watching and real-time updates")
302302
logs_parser.add_argument("--port", type=int, default=8000, help="Port to bind to (default: 8000)")
303303
logs_parser.add_argument("--debug", action="store_true", help="Enable debug mode")
304+
logs_parser.add_argument("--disable-elasticsearch-setup", action="store_true", help="Disable Elasticsearch setup")
305+
logs_parser.add_argument(
306+
"--use-env-elasticsearch-confi",
307+
action="store_true",
308+
help="Use env vars for Elasticsearch config (requires ELASTICSEARCH_URL, ELASTICSEARCH_API_KEY, ELASTICSEARCH_INDEX_NAME)",
309+
)
304310

305311
# Upload command
306312
upload_parser = subparsers.add_parser(

eval_protocol/cli_commands/logs.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,28 @@ def logs_command(args):
2020
print("Press Ctrl+C to stop the server")
2121
print("-" * 50)
2222

23-
# setup Elasticsearch
24-
from eval_protocol.pytest.elasticsearch_setup import ElasticsearchSetup
25-
26-
elasticsearch_config = ElasticsearchSetup().setup_elasticsearch()
23+
# Setup Elasticsearch based on flags
24+
elasticsearch_config = None
25+
try:
26+
if getattr(args, "use_env_elasticsearch_config", False):
27+
# Use environment variables for configuration
28+
print("⚙️ Using environment variables for Elasticsearch config")
29+
from eval_protocol.pytest.remote_rollout_processor import (
30+
create_elasticsearch_config_from_env,
31+
)
32+
33+
elasticsearch_config = create_elasticsearch_config_from_env()
34+
elif not getattr(args, "disable_elasticsearch_setup", False):
35+
# Default behavior: start or connect to local Elasticsearch via Docker helper
36+
from eval_protocol.pytest.elasticsearch_setup import ElasticsearchSetup
37+
38+
print("🧰 Auto-configuring local Elasticsearch (Docker)")
39+
elasticsearch_config = ElasticsearchSetup().setup_elasticsearch()
40+
else:
41+
print("🚫 Elasticsearch setup disabled; running without Elasticsearch integration")
42+
except Exception as e:
43+
print(f"❌ Failed to configure Elasticsearch: {e}")
44+
return 1
2745

2846
try:
2947
serve_logs(port=args.port, elasticsearch_config=elasticsearch_config, debug=args.debug)

eval_protocol/pytest/remote_rollout_processor.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@
2626
logger = logging.getLogger(__name__)
2727

2828

29+
def create_elasticsearch_config_from_env() -> ElasticsearchConfig:
30+
"""Setup Elasticsearch config from environment variables."""
31+
url = os.getenv("ELASTICSEARCH_URL")
32+
api_key = os.getenv("ELASTICSEARCH_API_KEY")
33+
index_name = os.getenv("ELASTICSEARCH_INDEX_NAME")
34+
35+
if url is None:
36+
raise ValueError("ELASTICSEARCH_URL must be set")
37+
if api_key is None:
38+
raise ValueError("ELASTICSEARCH_API_KEY must be set")
39+
if index_name is None:
40+
raise ValueError("ELASTICSEARCH_INDEX_NAME must be set")
41+
return ElasticsearchConfig(
42+
url=url,
43+
api_key=api_key,
44+
index_name=index_name,
45+
)
46+
47+
2948
def _build_fireworks_tracing_url(
3049
base_url: str, metadata: RolloutMetadata, completion_params_base_url: Optional[str] = None
3150
) -> str:

0 commit comments

Comments
 (0)