Skip to content

Commit f8a2e4c

Browse files
author
Dylan Huang
committed
Refactor Elasticsearch configuration naming for consistency
- Updated all instances of ElasticSearchConfig to ElasticsearchConfig across the codebase to align with official naming conventions. - Ensured that related classes and methods reflect this change, enhancing code clarity and maintainability.
1 parent 5f3f4f9 commit f8a2e4c

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

eval_protocol/logging/elasticsearch_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import requests
1111
from typing import Any, Dict, List, Optional, Union
1212
from urllib.parse import urlparse
13-
from eval_protocol.types.remote_rollout_processor import ElasticSearchConfig
13+
from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig
1414

1515

1616
class ElasticsearchClient:
1717
"""Centralized client for all Elasticsearch operations."""
1818

19-
def __init__(self, config: ElasticSearchConfig):
19+
def __init__(self, config: ElasticsearchConfig):
2020
"""Initialize the Elasticsearch client.
2121
2222
Args:

eval_protocol/logging/elasticsearch_direct_http_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from typing import Optional, Tuple, Any, Dict
88
from datetime import datetime
99

10-
from eval_protocol.types.remote_rollout_processor import ElasticSearchConfig
10+
from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig
1111
from .elasticsearch_client import ElasticsearchClient
1212

1313

1414
class ElasticsearchDirectHttpHandler(logging.Handler):
15-
def __init__(self, elasticsearch_config: ElasticSearchConfig) -> None:
15+
def __init__(self, elasticsearch_config: ElasticsearchConfig) -> None:
1616
super().__init__()
17-
self.config = ElasticSearchConfig(
17+
self.config = ElasticsearchConfig(
1818
url=elasticsearch_config.url,
1919
api_key=elasticsearch_config.api_key,
2020
index_name=elasticsearch_config.index_name,

eval_protocol/logging/elasticsearch_index_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict, Any, Optional
22
from .elasticsearch_client import ElasticsearchClient
3-
from eval_protocol.types.remote_rollout_processor import ElasticSearchConfig
3+
from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig
44

55

66
class ElasticsearchIndexManager:
@@ -14,7 +14,7 @@ def __init__(self, base_url: str, index_name: str, api_key: str) -> None:
1414
index_name: Name of the index to manage
1515
api_key: API key for authentication
1616
"""
17-
self.config = ElasticSearchConfig(url=base_url, api_key=api_key, index_name=index_name)
17+
self.config = ElasticsearchConfig(url=base_url, api_key=api_key, index_name=index_name)
1818
self.client = ElasticsearchClient(self.config)
1919
self._mapping_created: bool = False
2020

eval_protocol/pytest/elasticsearch_setup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from dotenv import load_dotenv
88
from eval_protocol.directory_utils import find_eval_protocol_dir
9-
from eval_protocol.types.remote_rollout_processor import ElasticSearchConfig
9+
from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig
1010
from eval_protocol.logging.elasticsearch_index_manager import ElasticsearchIndexManager
1111

1212
logger = logging.getLogger(__name__)
@@ -24,15 +24,15 @@ class ElasticsearchSetup:
2424
def __init__(self):
2525
self.eval_protocol_dir = find_eval_protocol_dir()
2626

27-
def setup_elasticsearch(self, index_name: str = "default-logs") -> ElasticSearchConfig:
27+
def setup_elasticsearch(self, index_name: str = "default-logs") -> ElasticsearchConfig:
2828
"""
2929
Set up Elasticsearch, handling both local and remote scenarios.
3030
3131
Args:
3232
index_name: Name of the Elasticsearch index to use for logging
3333
3434
Returns:
35-
ElasticSearchConfig for the running instance with the specified index name.
35+
ElasticsearchConfig for the running instance with the specified index name.
3636
"""
3737
elastic_start_local_dir = os.path.join(self.eval_protocol_dir, "elastic-start-local")
3838
env_file_path = os.path.join(elastic_start_local_dir, ".env")
@@ -48,11 +48,11 @@ def setup_elasticsearch(self, index_name: str = "default-logs") -> ElasticSearch
4848
self.create_logging_index(index_name)
4949

5050
# Return config with the specified index name
51-
return ElasticSearchConfig(url=config.url, api_key=config.api_key, index_name=index_name)
51+
return ElasticsearchConfig(url=config.url, api_key=config.api_key, index_name=index_name)
5252

5353
def _setup_existing_docker_elasticsearch(
5454
self, elastic_start_local_dir: str, env_file_path: str
55-
) -> ElasticSearchConfig:
55+
) -> ElasticsearchConfig:
5656
"""Set up Elasticsearch using existing Docker start.sh script."""
5757
from eval_protocol.utils.subprocess_utils import run_script_and_wait
5858

@@ -63,7 +63,7 @@ def _setup_existing_docker_elasticsearch(
6363
)
6464
return self._parse_elastic_env_file(env_file_path)
6565

66-
def _setup_initialized_docker_elasticsearch(self, env_file_path: str) -> ElasticSearchConfig:
66+
def _setup_initialized_docker_elasticsearch(self, env_file_path: str) -> ElasticsearchConfig:
6767
"""Set up Elasticsearch by initializing Docker setup from scratch with retry logic."""
6868
max_retries = 2
6969
for attempt in range(max_retries):
@@ -126,7 +126,7 @@ def _handle_existing_elasticsearch_container(self, output: str) -> bool:
126126
return False
127127
return False
128128

129-
def _parse_elastic_env_file(self, env_file_path: str) -> ElasticSearchConfig:
129+
def _parse_elastic_env_file(self, env_file_path: str) -> ElasticsearchConfig:
130130
"""Parse ES_LOCAL_API_KEY and ES_LOCAL_URL from .env file."""
131131
loaded = load_dotenv(env_file_path)
132132
if not loaded:
@@ -138,7 +138,7 @@ def _parse_elastic_env_file(self, env_file_path: str) -> ElasticSearchConfig:
138138
if not url or not api_key:
139139
raise ElasticsearchSetupError("Failed to parse ES_LOCAL_API_KEY and ES_LOCAL_URL from .env file")
140140

141-
return ElasticSearchConfig(url=url, api_key=api_key, index_name="default-logs")
141+
return ElasticsearchConfig(url=url, api_key=api_key, index_name="default-logs")
142142

143143
def create_logging_index(self, index_name: str) -> bool:
144144
"""Create an Elasticsearch index with proper mapping for logging data.

eval_protocol/pytest/remote_rollout_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from eval_protocol.logging.elasticsearch_client import ElasticsearchClient
88
from eval_protocol.models import EvaluationRow, Status
99
from eval_protocol.data_loader.dynamic_data_loader import DynamicDataLoader
10-
from eval_protocol.types.remote_rollout_processor import ElasticSearchConfig, InitRequest, RolloutMetadata
10+
from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig, InitRequest, RolloutMetadata
1111
from .rollout_processor import RolloutProcessor
1212
from .types import RolloutProcessorConfig
1313
from .elasticsearch_setup import ElasticsearchSetup
@@ -34,7 +34,7 @@ def __init__(
3434
timeout_seconds: float = 120.0,
3535
output_data_loader: Callable[[str], DynamicDataLoader],
3636
disable_elastic_search: bool = False,
37-
elastic_search_config: Optional[ElasticSearchConfig] = None,
37+
elastic_search_config: Optional[ElasticsearchConfig] = None,
3838
):
3939
# Prefer constructor-provided configuration. These can be overridden via
4040
# config.kwargs at call time for backward compatibility.
@@ -56,7 +56,7 @@ def setup(self) -> None:
5656
self._elastic_search_config = self._setup_elastic_search()
5757
logger.info("Elasticsearch setup complete")
5858

59-
def _setup_elastic_search(self) -> ElasticSearchConfig:
59+
def _setup_elastic_search(self) -> ElasticsearchConfig:
6060
"""Set up Elasticsearch using the dedicated setup module."""
6161
setup = ElasticsearchSetup()
6262
return setup.setup_elasticsearch()

eval_protocol/types/remote_rollout_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from eval_protocol.models import Message, Status
99

1010

11-
class ElasticSearchConfig(BaseModel):
11+
class ElasticsearchConfig(BaseModel):
1212
"""
1313
Configuration for Elasticsearch.
1414
"""
@@ -38,7 +38,7 @@ class InitRequest(BaseModel):
3838
"""Request model for POST /init endpoint."""
3939

4040
model: str
41-
elastic_search_config: Optional[ElasticSearchConfig] = None
41+
elastic_search_config: Optional[ElasticsearchConfig] = None
4242
messages: Optional[List[Message]] = None
4343
tools: Optional[List[Dict[str, Any]]] = None
4444

tests/logging/test_elasticsearch_direct_http_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from eval_protocol.logging.elasticsearch_direct_http_handler import ElasticsearchDirectHttpHandler
77
from eval_protocol.logging.elasticsearch_client import ElasticsearchClient
88
from eval_protocol.pytest.elasticsearch_setup import ElasticsearchSetup
9-
from eval_protocol.types.remote_rollout_processor import ElasticSearchConfig
9+
from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig
1010

1111

1212
@pytest.fixture
@@ -39,7 +39,7 @@ def elasticsearch_config():
3939

4040

4141
@pytest.fixture
42-
def elasticsearch_handler(elasticsearch_config: ElasticSearchConfig, rollout_id: str):
42+
def elasticsearch_handler(elasticsearch_config: ElasticsearchConfig, rollout_id: str):
4343
"""Create and configure ElasticsearchDirectHttpHandler."""
4444
# Use a unique test-specific index name with timestamp
4545

@@ -52,7 +52,7 @@ def elasticsearch_handler(elasticsearch_config: ElasticSearchConfig, rollout_id:
5252

5353

5454
@pytest.fixture
55-
def elasticsearch_client(elasticsearch_config: ElasticSearchConfig):
55+
def elasticsearch_client(elasticsearch_config: ElasticsearchConfig):
5656
"""Create an Elasticsearch client for testing."""
5757
# Create a new config instance for the client
5858
return ElasticsearchClient(elasticsearch_config)

0 commit comments

Comments
 (0)