Skip to content

Commit

Permalink
fix: 全量日志全文检索修复
Browse files Browse the repository at this point in the history
  • Loading branch information
KT-core committed Oct 16, 2024
1 parent bf19613 commit 362bc90
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const getLogOtherTableListApi = (params) => {
}
//获取外部日志表信息
export const getLogOtherTableInfoApi = (params) => {
return post(`/api/log/other/table`, params)
return get(`/api/log/other/table`, params)
}
//新增外部日志表信息
export const addLogOtherTableApi = (params) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
.validateFields({})
.then(() => {
const formState = form.getFieldsValue(true)
// console.log(formState)
const logRuleParams = {
...formState,
}
Expand Down Expand Up @@ -133,7 +132,14 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
let result = form.getFieldValue('routeRule') || []

Object.entries(res?.routeRule)?.forEach(([key, value]) => {
if (result)
// 检查当前 result 中是否已经存在该 key
const existingIndex = result.findIndex((item) => item?.key?.key === key)

if (existingIndex > -1) {
// 如果已存在,替换对应的 value
result[existingIndex].value = value
} else {
// 如果不存在,则新增项
result.push({
key: {
key: key,
Expand All @@ -142,8 +148,13 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
},
value: value,
})
}
})

// 过滤掉无效项
result = result.filter((item) => item?.key && item.value)

// 更新表单值
form.setFieldValue('routeRule', result)
})
}
Expand Down Expand Up @@ -194,6 +205,7 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
<Select
options={serviceList}
placeholder="请选择执行规则的应用"
mode="multiple"
onChange={(value) => getServiceRouteRule(value)}
></Select>
</Form.Item>
Expand All @@ -204,7 +216,7 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
<div className="flex items-center">
解析规则 <AiOutlineInfoCircle size={16} className="ml-1" />
<span className="text-xs text-gray-400">
用于将日志文本解析为独立的字段,加快检索速度。请使用
点击规则查询对应服务的日志。请使用
<a href="https://playground.vrl.dev/" className="underline" target="_blank">
VRL
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Button, Col, Form, Input, Popover, Row } from 'antd'
import React, { useEffect, useState } from 'react'
import { useLogsContext } from 'src/contexts/LogsContext'

const FullTextSearch = () => {
const { query, updateQuery } = useLogsContext()
const FullTextSearch = ({ searchValue, setSearchValue }) => {
const [form] = Form.useForm()
const [open, setOpen] = useState(false)

Expand All @@ -18,12 +16,12 @@ const FullTextSearch = () => {
const clickSubmit = () => {
form.validateFields().then(() => {
const formState = form.getFieldsValue(true)
let newQuery = query
let newQuery = searchValue
if (newQuery.length > 0) {
newQuery += ' AND '
}
newQuery += '`' + formState.key + '` like ' + `'` + formState.value + `'`
updateQuery(newQuery)
newQuery += '`' + formState.key + '` LIKE ' + `'%` + formState.value + `%'`
setSearchValue(newQuery)
hide()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { useLogsContext } from 'src/contexts/LogsContext'
import { ISOToTimestamp } from 'src/utils/time'
import { useSearchParams } from 'react-router-dom'
import FullTextSearch from './FullTextSearch'
import { LuRefreshCw } from 'react-icons/lu'
const RawLogQuery = () => {
const { query, updateQuery, fetchData } = useLogsContext()
const { query, updateQuery, getLogTableInfo } = useLogsContext()
// 分析字段的代码提示
const [analysisFieldTips, setAnalysisFieldTips] = useState([])
// 输入框自动填充历史记录
Expand All @@ -30,10 +31,15 @@ const RawLogQuery = () => {
setSearchValue(query)
}, [query])

const clickFullTextSearch = (value) => {
setSearchValue(value)
updateQuery(value)
}

return (
<>
<div className="searchBarMain">
<FullTextSearch />
<FullTextSearch searchValue={searchValue} setSearchValue={clickFullTextSearch} />
<div className="inputBox" style={{ overflowX: isMultipleLines ? 'visible' : 'hidden' }}>
<CodeMirrorSearch
title="logInput"
Expand All @@ -57,6 +63,12 @@ const RawLogQuery = () => {
icon={<IoSearch />}
onClick={() => updateQuery(queryKeyword)}
></Button>
{/* <Button
type="primary"
icon={<LuRefreshCw />}
className="ml-2"
onClick={() => getLogTableInfo()}
></Button> */}
</div>
</>
)
Expand Down

0 comments on commit 362bc90

Please sign in to comment.