Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
24 changes: 24 additions & 0 deletions admin/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,30 @@ def load_configurations(config_path: str) -> list[BaseConfig]:
config = MinioConfig(id=id_count, name=name, host=host, port=port, user=user, password=password, service_type="file_store", store_type="minio", detail_func_name="check_minio_alive")
configurations.append(config)
id_count += 1
case "s3":
# AWS S3 (or any S3-compatible service: MinIO, R2, ...).
# The config block uses `endpoint_url` instead of `host:port`,
# so parse the URL to derive host/port for the status page.
name: str = "s3"
endpoint_url = v.get("endpoint_url") or ""
if endpoint_url:
parsed = urlparse(endpoint_url)
host: str = parsed.hostname or endpoint_url
port: int = parsed.port or (443 if parsed.scheme == "https" else 80)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
else:
host: str = "s3.amazonaws.com"
port: int = 443
config = FileStoreConfig(
id=id_count,
name=name,
host=host,
port=port,
service_type="file_store",
store_type="s3",
detail_func_name="check_s3_alive",
)
configurations.append(config)
id_count += 1
case "redis":
name: str = "redis"
url = v["host"]
Expand Down
11 changes: 11 additions & 0 deletions admin/server/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,24 @@ class ServiceMgr:
@staticmethod
def get_all_services():
doc_engine = os.getenv("DOC_ENGINE", "elasticsearch")
# Map STORAGE_IMPL (e.g. "AWS_S3", "MINIO", "OSS") to the lowercase
# `store_type` we use in FileStoreConfig.store_type. The "AWS_"
# prefix is stripped so AWS_S3 matches store_type "s3".
storage_impl = os.getenv("STORAGE_IMPL", "MINIO")
active_store_type = storage_impl.lower().removeprefix("aws_")
result = []
configs = SERVICE_CONFIGS.configs
for service_id, config in enumerate(configs):
config_dict = config.to_dict()
if config_dict["service_type"] == "retrieval":
if config_dict["extra"]["retrieval_type"] != doc_engine:
continue
if config_dict["service_type"] == "file_store":
# Only show the file-store backend that's actually active.
# Without this filter, a stale minio entry from service_conf.yaml
# is returned even when STORAGE_IMPL=AWS_S3 (see #17294).
if config_dict.get("extra", {}).get("store_type") != active_store_type:
continue
try:
service_detail = ServiceMgr.get_service_details(service_id)
if "status" in service_detail:
Expand Down
13 changes: 13 additions & 0 deletions api/utils/health_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ def check_minio_alive():
}


def check_s3_alive():
"""
Check AWS S3 (or any S3-compatible) liveness via the active
storage backend's `.health()` method. Delegates to the generic
``check_storage`` so the same check works for AWS S3, MinIO,
R2, and any other S3-compatible endpoint. See #17294.
"""
ok, payload = check_storage()
if ok:
return {"status": "alive", "message": f"Confirm elapsed: {payload.get('elapsed', '?')} ms."}
return {"status": "timeout", "message": f"error: {payload.get('error', 'unknown')}"}
Comment thread
coderabbitai[bot] marked this conversation as resolved.


def get_redis_info():
try:
return {"status": "alive", "message": REDIS_CONN.info()}
Expand Down
38 changes: 38 additions & 0 deletions test/unit_test/admin/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Conftest for admin unit tests.

The admin package is invoked as a script (`python admin/server/admin_server.py`)
and its internal modules use top-level imports like `from config import
SERVICE_CONFIGS`. To make those modules importable from pytest, we prepend
``admin/server`` to ``sys.path`` for the duration of the test session.
"""

import os
import sys

_ADMIN_SERVER = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"..",
"..",
"..",
"admin",
"server",
)
_ADMIN_SERVER = os.path.normpath(_ADMIN_SERVER)
if _ADMIN_SERVER not in sys.path:
sys.path.insert(0, _ADMIN_SERVER)
241 changes: 241 additions & 0 deletions test/unit_test/admin/test_get_all_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
#
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Unit tests for ``ServiceMgr.get_all_services`` in
``admin/server/services.py``.

Specifically covers the new ``STORAGE_IMPL`` filter that hides
inactive file_store backends. See #17294 (Admin Service status still
reports MinIO when object storage is configured as AWS S3).
"""

from unittest.mock import patch

import pytest

from config import (
ElasticsearchConfig,
FileStoreConfig,
MinioConfig,
SERVICE_CONFIGS,
)


def _minio_config():
return MinioConfig(
id=0,
name="minio",
host="minio",
port=9000,
user="u",
password="p",
service_type="file_store",
store_type="minio",
detail_func_name="check_minio_alive",
)


def _s3_config():
return FileStoreConfig(
id=1,
name="s3",
host="s3.us-east-1.amazonaws.com",
port=443,
service_type="file_store",
store_type="s3",
detail_func_name="check_s3_alive",
)


def _es_config(retrieval_type="elasticsearch"):
return ElasticsearchConfig(
id=2,
name="elasticsearch",
host="es",
port=9200,
service_type="retrieval",
retrieval_type=retrieval_type,
username="",
password="",
detail_func_name="get_es_cluster_stats",
)


@pytest.fixture
def install_configs():
"""Install a clean ``SERVICE_CONFIGS.configs`` for each test, then
restore the previous value. Required because the admin module uses
``SERVICE_CONFIGS`` as a mutable namespace, not an instance."""
previous = list(getattr(SERVICE_CONFIGS, "configs", []))
yield
SERVICE_CONFIGS.configs = previous


class TestFileStoreFilter:
"""The new filter: only the active file_store backend is returned."""

def test_minio_shown_when_storage_impl_is_minio(self, install_configs, monkeypatch):
monkeypatch.setenv("STORAGE_IMPL", "MINIO")
SERVICE_CONFIGS.configs = [_minio_config(), _s3_config()]

with patch("services.ServiceMgr.get_service_details", return_value={"status": "alive"}):
from services import ServiceMgr

result = ServiceMgr.get_all_services()

stores = [s for s in result if s["service_type"] == "file_store"]
assert len(stores) == 1
assert stores[0]["name"] == "minio"

def test_s3_shown_when_storage_impl_is_aws_s3(self, install_configs, monkeypatch):
monkeypatch.setenv("STORAGE_IMPL", "AWS_S3")
SERVICE_CONFIGS.configs = [_minio_config(), _s3_config()]

with patch("services.ServiceMgr.get_service_details", return_value={"status": "alive"}):
from services import ServiceMgr

result = ServiceMgr.get_all_services()

stores = [s for s in result if s["service_type"] == "file_store"]
assert len(stores) == 1
assert stores[0]["name"] == "s3"

def test_no_file_store_shown_when_active_backend_not_configured(self, install_configs, monkeypatch):
"""If the active backend has no corresponding config block,
nothing is shown for file_store. We never fall back to a
stale minio entry."""
monkeypatch.setenv("STORAGE_IMPL", "AWS_S3")
# Only the minio block is present.
SERVICE_CONFIGS.configs = [_minio_config()]

with patch("services.ServiceMgr.get_service_details", return_value={"status": "alive"}):
from services import ServiceMgr

result = ServiceMgr.get_all_services()

stores = [s for s in result if s["service_type"] == "file_store"]
assert stores == []


class TestRetrivalFilterStillWorks:
"""Regression guard: the existing DOC_ENGINE filter for retrieval
must keep working — the new file_store filter is additive."""

def test_elasticsearch_shown_when_doc_engine_is_elasticsearch(self, install_configs, monkeypatch):
monkeypatch.setenv("DOC_ENGINE", "elasticsearch")
monkeypatch.setenv("STORAGE_IMPL", "MINIO")
from config import InfinityConfig

SERVICE_CONFIGS.configs = [
_es_config(retrieval_type="elasticsearch"),
InfinityConfig(
id=3,
name="infinity",
host="inf",
port=23800,
service_type="retrieval",
retrieval_type="infinity",
db_name="default_db",
detail_func_name="get_infinity_status",
),
_minio_config(),
]

with patch("services.ServiceMgr.get_service_details", return_value={"status": "alive"}):
from services import ServiceMgr

result = ServiceMgr.get_all_services()

retrievals = [s for s in result if s["service_type"] == "retrieval"]
assert len(retrievals) == 1
assert retrievals[0]["name"] == "elasticsearch"

def test_infinity_filtered_when_doc_engine_is_elasticsearch(self, install_configs, monkeypatch):
"""When DOC_ENGINE=elasticsearch, an infinity retrieval config
must be filtered out."""
monkeypatch.setenv("DOC_ENGINE", "elasticsearch")
monkeypatch.setenv("STORAGE_IMPL", "MINIO")
from config import InfinityConfig

SERVICE_CONFIGS.configs = [
_es_config(retrieval_type="elasticsearch"),
InfinityConfig(
id=3,
name="infinity",
host="inf",
port=23800,
service_type="retrieval",
retrieval_type="infinity",
db_name="default_db",
detail_func_name="get_infinity_status",
),
]

with patch("services.ServiceMgr.get_service_details", return_value={"status": "alive"}):
from services import ServiceMgr

result = ServiceMgr.get_all_services()

names = [s["name"] for s in result if s["service_type"] == "retrieval"]
assert "infinity" not in names
assert "elasticsearch" in names


class TestStorageImplNameMapping:
"""The STORAGE_IMPL env var uses upper-case + underscores (e.g.
``AWS_S3``). The ``store_type`` we record is lower-case (``s3``).
The filter must translate correctly so ``AWS_S3`` matches
``s3``, not ``aws_s3``."""

@pytest.mark.parametrize(
"storage_impl,expected_store",
[
("MINIO", "minio"),
("AWS_S3", "s3"),
("OSS", "oss"),
("GCS", "gcs"),
],
)
def test_env_var_maps_to_store_type(self, install_configs, monkeypatch, storage_impl, expected_store):
monkeypatch.setenv("STORAGE_IMPL", storage_impl)
active = FileStoreConfig(
id=0,
name=expected_store,
host="x",
port=443,
service_type="file_store",
store_type=expected_store,
detail_func_name="check_storage",
)
inactive = FileStoreConfig(
id=1,
name="other",
host="x",
port=443,
service_type="file_store",
store_type="other",
detail_func_name="check_storage",
)
SERVICE_CONFIGS.configs = [active, inactive]

with patch("services.ServiceMgr.get_service_details", return_value={"status": "alive"}):
from services import ServiceMgr

result = ServiceMgr.get_all_services()

stores = [s for s in result if s["service_type"] == "file_store"]
assert len(stores) == 1
assert stores[0]["name"] == expected_store
Loading