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

chore: set logger level to error to reduce noise from Elasticsearch and OpenSearch client libraries #4979

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions argilla-server/src/argilla_server/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
for app_configure in [
configure_app_logging,
configure_database,
ping_search_engine,
configure_search_engine,
configure_telemetry,
configure_middleware,
configure_app_security,
Expand Down Expand Up @@ -148,18 +148,35 @@
)


def ping_search_engine(app: FastAPI):
def configure_search_engine(app: FastAPI):
@app.on_event("startup")
async def configure_elasticsearch():
if not settings.search_engine_is_elasticsearch:
return

Check warning on line 155 in argilla-server/src/argilla_server/_app.py

View check run for this annotation

Codecov / codecov/patch

argilla-server/src/argilla_server/_app.py#L154-L155

Added lines #L154 - L155 were not covered by tests

logging.getLogger("elasticsearch").setLevel(logging.ERROR)
logging.getLogger("elastic_transport").setLevel(logging.ERROR)

Check warning on line 158 in argilla-server/src/argilla_server/_app.py

View check run for this annotation

Codecov / codecov/patch

argilla-server/src/argilla_server/_app.py#L157-L158

Added lines #L157 - L158 were not covered by tests

@app.on_event("startup")
async def configure_opensearch():
if not settings.search_engine_is_opensearch:
return

Check warning on line 163 in argilla-server/src/argilla_server/_app.py

View check run for this annotation

Codecov / codecov/patch

argilla-server/src/argilla_server/_app.py#L162-L163

Added lines #L162 - L163 were not covered by tests

logging.getLogger("opensearch").setLevel(logging.ERROR)
logging.getLogger("opensearch_transport").setLevel(logging.ERROR)

Check warning on line 166 in argilla-server/src/argilla_server/_app.py

View check run for this annotation

Codecov / codecov/patch

argilla-server/src/argilla_server/_app.py#L165-L166

Added lines #L165 - L166 were not covered by tests

@app.on_event("startup")
@backoff.on_exception(backoff.expo, ConnectionError, max_time=60)
async def _ping_search_engine():
async def ping_search_engine():
async for search_engine in get_search_engine():
if not await search_engine.ping():
raise ConnectionError(
f"Your Elasticsearch endpoint at {settings.obfuscated_elasticsearch()} is not available or not responding.\n"
"Please make sure your Elasticsearch instance is launched and correctly running and\n"
f"Your {settings.search_engine} endpoint at {settings.obfuscated_elasticsearch()} is not available or not responding.\n"
f"Please make sure your {settings.search_engine} instance is launched and correctly running and\n"
"you have the necessary access permissions. Once you have verified this, restart the argilla server.\n"
)


def configure_app_security(app: FastAPI):
auth.configure_app(app)

Expand Down
3 changes: 3 additions & 0 deletions argilla-server/src/argilla_server/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
API_KEY_HEADER_NAME = "X-Argilla-Api-Key"
WORKSPACE_HEADER_NAME = "X-Argilla-Workspace"

SEARCH_ENGINE_ELASTICSEARCH = "elasticsearch"
SEARCH_ENGINE_OPENSEARCH = "opensearch"

DEFAULT_USERNAME = "argilla"
DEFAULT_PASSWORD = "1234"
DEFAULT_API_KEY = "argilla.apikey"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from elasticsearch8 import AsyncElasticsearch, helpers

from argilla_server.constants import SEARCH_ENGINE_ELASTICSEARCH
from argilla_server.models import VectorSettings
from argilla_server.search_engine import SearchEngine
from argilla_server.search_engine.commons import (
Expand All @@ -37,7 +38,7 @@ def _compute_num_candidates_from_k(k: int) -> int:
return 2000


@SearchEngine.register(engine_name="elasticsearch")
@SearchEngine.register(engine_name=SEARCH_ENGINE_ELASTICSEARCH)
@dataclasses.dataclass
class ElasticSearchEngine(BaseElasticAndOpenSearchEngine):
config: Dict[str, Any] = dataclasses.field(default_factory=dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from opensearchpy import AsyncOpenSearch, helpers

from argilla_server.constants import SEARCH_ENGINE_OPENSEARCH
from argilla_server.models import VectorSettings
from argilla_server.search_engine.base import SearchEngine
from argilla_server.search_engine.commons import (
Expand All @@ -29,7 +30,7 @@
from argilla_server.settings import settings


@SearchEngine.register(engine_name="opensearch")
@SearchEngine.register(engine_name=SEARCH_ENGINE_OPENSEARCH)
@dataclasses.dataclass
class OpenSearchEngine(BaseElasticAndOpenSearchEngine):
config: Dict[str, Any] = dataclasses.field(default_factory=dict)
Expand Down
12 changes: 11 additions & 1 deletion argilla-server/src/argilla_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
DEFAULT_MAX_KEYWORD_LENGTH,
DEFAULT_SPAN_OPTIONS_MAX_ITEMS,
DEFAULT_TELEMETRY_KEY,
SEARCH_ENGINE_ELASTICSEARCH,
SEARCH_ENGINE_OPENSEARCH,
)
from argilla_server.pydantic_v1 import BaseSettings, Field, root_validator, validator

Expand Down Expand Up @@ -97,7 +99,7 @@

es_mapping_total_fields_limit: int = 2000

search_engine: str = "elasticsearch"
search_engine: str = SEARCH_ENGINE_ELASTICSEARCH

vectors_fields_limit: int = Field(
default=5,
Expand Down Expand Up @@ -217,6 +219,14 @@
return index_name.replace("<NAMESPACE>", "")
return index_name.replace("<NAMESPACE>", f".{ns}")

@property
def search_engine_is_elasticsearch(self) -> bool:
return self.search_engine == SEARCH_ENGINE_ELASTICSEARCH

Check warning on line 224 in argilla-server/src/argilla_server/settings.py

View check run for this annotation

Codecov / codecov/patch

argilla-server/src/argilla_server/settings.py#L224

Added line #L224 was not covered by tests

@property
def search_engine_is_opensearch(self) -> bool:
return self.search_engine == SEARCH_ENGINE_OPENSEARCH

Check warning on line 228 in argilla-server/src/argilla_server/settings.py

View check run for this annotation

Codecov / codecov/patch

argilla-server/src/argilla_server/settings.py#L228

Added line #L228 was not covered by tests

def obfuscated_elasticsearch(self) -> str:
"""Returns configured elasticsearch url obfuscating the provided password, if any"""
parsed = urlparse(self.elasticsearch)
Expand Down
Loading