-
Notifications
You must be signed in to change notification settings - Fork 10.1k
fix(admin,api): honor STORAGE_IMPL when surfacing file_store backend (closes #17294) #17441
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
Open
Harsh23Kashyap
wants to merge
3
commits into
infiniflow:main
Choose a base branch
from
Harsh23Kashyap:fix/admin-storage-status-honors-impl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3ddd65c
fix(admin,api): honor STORAGE_IMPL when surfacing file_store backend …
Harsh23Kashyap 913a7e6
test(admin,api): cover S3 file_store config, STORAGE_IMPL filter, and…
Harsh23Kashyap 4600dd8
fix(admin): handle malformed S3 endpoint_url without aborting config …
Harsh23Kashyap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.