fix(log): F6 polish — log datasource create error log + schema patches for auth_type/token/headers + ES default index sync on datasource select
This commit is contained in:
1 parent
6bba6144f3
commit
5fb74a787a
3 files changed
+17
-6
No files matched your search
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -76,6 +77,8 @@ func (h *LogDSHandler) Create(c *gin.Context) {
|
|||||||
IsDefault: req.IsDefault, Status: 1,
|
IsDefault: req.IsDefault, Status: 1,
|
||||||
}
|
}
|
||||||
if err := h.db.Create(&ds).Error; err != nil {
|
if err := h.db.Create(&ds).Error; err != nil {
|
||||||
|
// 记录详细错误,便于排查字段缺失/唯一约束等数据库问题 // Logan.Li
|
||||||
|
log.Printf("[LogDataSource] 创建数据源失败: %v", err)
|
||||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||||
c.JSON(409, model.Response{Code: 409, Message: "数据源名称已存在"})
|
c.JSON(409, model.Response{Code: 409, Message: "数据源名称已存在"})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -192,4 +192,16 @@ func applySchemaPatches(db *gorm.DB) {
|
|||||||
patchUserColumn("ApiAccessKeyDescription", "api_access_key_description")
|
patchUserColumn("ApiAccessKeyDescription", "api_access_key_description")
|
||||||
patchUserColumn("ApiAccessKeyDurationMonths", "api_access_key_duration_months")
|
patchUserColumn("ApiAccessKeyDurationMonths", "api_access_key_duration_months")
|
||||||
patchUserColumn("ApiAccessKeyLastUsedAt", "api_access_key_last_used_at")
|
patchUserColumn("ApiAccessKeyLastUsedAt", "api_access_key_last_used_at")
|
||||||
|
|
||||||
|
// 补全日志数据源表可能缺失的列(旧表仅有基础字段)// Logan.Li
|
||||||
|
patchLogDSColumn := func(field string, col string) {
|
||||||
|
if !m.HasColumn(&model.LogDataSource{}, col) {
|
||||||
|
if err := m.AddColumn(&model.LogDataSource{}, field); err != nil {
|
||||||
|
log.Printf("[DB] 补列 monitor_log_datasources.%s 失败: %v", col, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
patchLogDSColumn("AuthType", "auth_type")
|
||||||
|
patchLogDSColumn("Token", "token")
|
||||||
|
patchLogDSColumn("Headers", "headers")
|
||||||
}
|
}
|
||||||
@@ -176,19 +176,15 @@ export function UnifiedQueryPanel({ engine, onRuleCreated }: Props) {
|
|||||||
const [saveMenuOpen, setSaveMenuOpen] = useState(false);
|
const [saveMenuOpen, setSaveMenuOpen] = useState(false);
|
||||||
const [hasQueried, setHasQueried] = useState(false);
|
const [hasQueried, setHasQueried] = useState(false);
|
||||||
|
|
||||||
// 数据源加载后选中默认或首个(无源时保持空)// Logan.Li
|
// 数据源加载后选中默认或首个(无源时保持空),并同步 ES 默认索引 // Logan.Li
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sources.length > 0) {
|
if (sources.length > 0) {
|
||||||
const def = sources.find(s => s.is_default) || sources[0];
|
const def = sources.find(s => s.is_default) || sources[0];
|
||||||
setDsId(String(def.id));
|
setDsId(String(def.id));
|
||||||
|
setEsIndex(def.default_index || '');
|
||||||
}
|
}
|
||||||
}, [sources]);
|
}, [sources]);
|
||||||
|
|
||||||
// 当前数据源变化时,同步 ES 临时索引框为数据源的默认索引 // Logan.Li
|
|
||||||
useEffect(() => {
|
|
||||||
setEsIndex(currentSource?.default_index || '');
|
|
||||||
}, [currentSource]);
|
|
||||||
|
|
||||||
const currentSource = sources.find(s => String(s.id) === dsId);
|
const currentSource = sources.find(s => String(s.id) === dsId);
|
||||||
|
|
||||||
const fields = useMemo(() => extractFields(entries), [entries]);
|
const fields = useMemo(() => extractFields(entries), [entries]);
|
||||||
|
|||||||
Reference in new issue
Block a user