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

Web: Display the icon of the currently used storage. #2504

Merged
merged 1 commit into from
Sep 20, 2024
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
11 changes: 6 additions & 5 deletions api/apps/system_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from flask_login import login_required

from api.db.services.knowledgebase_service import KnowledgebaseService
from api.settings import DATABASE_TYPE
from api.utils.api_utils import get_json_result
from api.versions import get_rag_version
from rag.settings import SVR_QUEUE_NAME
from rag.utils.es_conn import ELASTICSEARCH
from rag.utils.storage_factory import STORAGE_IMPL
from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE
from timeit import default_timer as timer

from rag.utils.redis_conn import REDIS_CONN
Expand All @@ -48,16 +49,16 @@ def status():
st = timer()
try:
STORAGE_IMPL.health()
res["minio"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
res["storage"] = {"storage": STORAGE_IMPL_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
except Exception as e:
res["minio"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
res["storage"] = {"storage": STORAGE_IMPL_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}

st = timer()
try:
KnowledgebaseService.get_by_id("x")
res["mysql"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
res["database"] = {"database": DATABASE_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
except Exception as e:
res["mysql"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
res["database"] = {"database": DATABASE_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}

st = timer()
try:
Expand Down
3 changes: 2 additions & 1 deletion rag/utils/storage_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ def create(cls, storage: Storage):
return cls.storage_mapping[storage]()


STORAGE_IMPL = StorageFactory.create(Storage[os.getenv('STORAGE_IMPL', 'MINIO')])
STORAGE_IMPL_TYPE = os.getenv('STORAGE_IMPL', 'MINIO')
STORAGE_IMPL = StorageFactory.create(Storage[STORAGE_IMPL_TYPE])
3 changes: 3 additions & 0 deletions web/src/assets/svg/database.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions web/src/assets/svg/storage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions web/src/interfaces/database/user-setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export type TaskExecutorElapsed = Record<string, number[]>;

export interface ISystemStatus {
es: Es;
minio: Minio;
mysql: Minio;
storage: Storage;
database: Database;
redis: Redis;
task_executor: {
error?: string;
Expand All @@ -41,7 +41,13 @@ interface Redis {
pending: number;
}

export interface Minio {
export interface Storage {
status: string;
elapsed: number;
error: string;
}

export interface Database {
status: string;
elapsed: number;
error: string;
Expand Down
14 changes: 11 additions & 3 deletions web/src/pages/user-setting/setting-system/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SvgIcon from '@/components/svg-icon';
import { useFetchSystemStatus } from '@/hooks/user-setting-hooks';
import { ISystemStatus, Storage } from '@/interfaces/database/userSetting';
import {
ISystemStatus,
TaskExecutorElapsed,
Expand All @@ -24,12 +25,19 @@ enum Status {

const TitleMap = {
es: 'Elasticsearch',
minio: 'MinIO Object Storage',
storage: 'Object Storage',
redis: 'Redis',
mysql: 'Mysql',
database: 'Database',
task_executor: 'Task Executor',
};

const IconMap = {
es: 'es',
storage: 'storage',
redis: 'redis',
database: 'database',
};

const SystemInfo = () => {
const {
systemStatus,
Expand All @@ -56,7 +64,7 @@ const SystemInfo = () => {
{key === 'task_executor' ? (
<img src="/logo.svg" alt="" width={26} />
) : (
<SvgIcon name={key} width={26}></SvgIcon>
<SvgIcon name={IconMap[key as keyof typeof IconMap]} width={26}></SvgIcon>
)}
<span className={styles.title}>
{TitleMap[key as keyof typeof TitleMap]}
Expand Down