Skip to content

Commit

Permalink
feat: 全量日志全文检索
Browse files Browse the repository at this point in the history
  • Loading branch information
KT-core committed Oct 16, 2024
1 parent 626fccc commit 6a52f7e
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 25 deletions.
4 changes: 2 additions & 2 deletions frontend/src/api/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getLogIndexApi = (params) => {

//获取日志表信息
export const getLogTableInfoAPi = (params) => {
return post(`/api/log/table`, params)
return get(`/api/log/table`, params)
}

// ————全量日志->日志规则
Expand All @@ -52,7 +52,7 @@ export const deleteLogRuleApi = (params) => {
//——————全量日志->接入外部表
// 获取所有外部表
export const getLogOtherTableListApi = (params) => {
return post(`/api/log/other`, params)
return get(`/api/log/other`, params)
}
//获取外部日志表信息
export const getLogOtherTableInfoApi = (params) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ export default function LogRouteRuleFormList() {
name={[field.name, 'key']}
required
rules={[
{ required: true, message: '请选择匹配规则Key' },
{
validator: async (_, value) => {
// 获取当前表单中所有的routeRule项
const routeRule = form.getFieldValue('routeRule') || []
// 检查是否有重复的key
if (!value) {
return Promise.reject('匹配规则key不可为空')
}
const duplicate = routeRule.filter(
(item, i) => item.key.key === value.key && i !== index,
(item, i) => item?.key?.key === value.key && i !== index,
)
if (duplicate.length) {
return Promise.reject('已存在相同的Key')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
function addLogRule(logRuleParams) {
addLogRuleApi(logRuleParams).then((res) => {
showToast({
title: '日志规则配置成功',
title: '日志解析规则配置成功',
color: 'success',
})
})
Expand All @@ -81,7 +81,7 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
tableName: logRuleInfo.tableName,
}).then((res) => {
showToast({
title: '日志规则配置成功',
title: '日志解析规则配置成功',
color: 'success',
})

Expand Down Expand Up @@ -123,7 +123,7 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
}
return (
<Modal
title={'日志规则配置'}
title={'日志解析规则配置'}
open={modalVisible}
onCancel={closeModal}
destroyOnClose
Expand Down Expand Up @@ -161,17 +161,7 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
disabled={logRuleInfo?.parseName}
/>
</Form.Item>
<Form.Item
label="规则描述"
name="parseInfo"
required
rules={[
{
required: true,
message: '请输入规则描述',
},
]}
>
<Form.Item label="规则描述" name="parseInfo">
<Input placeholder="规则描述" />
</Form.Item>
<Form.Item label="执行应用" name="serviceName">
Expand All @@ -190,31 +180,43 @@ const ConfigLogRuleModal = ({ modalVisible, closeModal, logRuleInfo }) => {
</a>
语言,查看
<Tooltip
title={`.msg, err = parse_regex(.content, r' \[(?P<level>.*?)\] \[(?P<thread>.*?)\] \[(?P<method>.*?)\(.*?\)\] - (?P<msg>.*)')
title={
<div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
{`.msg, err = parse_regex(.content, r' \\[(?P<level>.*?)\\] \\[(?P<thread>.*?)\\] \\[(?P<method>.*?)\\(.*?\\)\\] - (?P<msg>.*)')
if err == null {
.content = encode_json(.msg)
.content = encode_json(.msg)
}
del(.msg)`}
</div>
}
>
<span className="px-1 underline cursor-pointer">JAVA</span>
</Tooltip>
<Tooltip
title={`.msg, err = parse_regex(.content, r' \[(?P<level>.*?)\] \[(?P<thread>.*?)\] \[(?P<method>.*?)\(.*?\)\] - (?P<msg>.*)')
title={
<div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
{`.msg, err = parse_regex(.content, r' \\[(?P<level>.*?)\\] \\[(?P<thread>.*?)\\] \\[(?P<method>.*?)\\(.*?\\)\\] - (?P<msg>.*)')
if err == null {
.content = encode_json(.msg)
.content = encode_json(.msg)
}
del(.msg)`}
</div>
}
>
<span className="px-1 underline cursor-pointer">Go</span>
</Tooltip>
<Tooltip
title={`.msg, err = parse_regex(.content, r' \[(?P<level>.*?)\] \[(?P<thread>.*?)\] \[(?P<method>.*?)\(.*?\)\] - (?P<msg>.*)')
title={
<div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
{`.msg, err = parse_regex(.content, r' \\[(?P<level>.*?)\\] \\[(?P<thread>.*?)\\] \\[(?P<method>.*?)\\(.*?\\)\\] - (?P<msg>.*)')
if err == null {
.content = encode_json(.msg)
.content = encode_json(.msg)
}
del(.msg)`}
</div>
}
>
<span className="px-1 underline cursor-pointer">Nginx</span>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 [form] = Form.useForm()
const [open, setOpen] = useState(false)

const hide = () => {
setOpen(false)
}

const handleOpenChange = (newOpen) => {
setOpen(newOpen)
}

const clickSubmit = () => {
form.validateFields().then(() => {
const formState = form.getFieldsValue(true)
let newQuery = query
if (newQuery.length > 0) {
newQuery += ' AND '
}
newQuery += '`' + formState.key + '` like ' + `'` + formState.value + `'`
updateQuery(newQuery)
hide()
})
}
useEffect(() => {
form.resetFields()
}, [open])
return (
<Popover
destroyTooltipOnHide
content={
<div>
<Form layout="vertical" className="px-2" form={form} initialValues={{ key: 'content' }}>
<Row gutter={10}>
<Col span={7}>
<Form.Item
label="全文检索字段"
name="key"
rules={[
{
required: true,
message: '请输入全文检索字段',
},
]}
>
<Input placeholder="请输入全文检索字段" />
</Form.Item>
</Col>
<Col span={13}>
<Form.Item
label="全文检索内容"
name="value"
rules={[
{
required: true,
message: '请输入全文检索内容',
},
]}
>
<Input placeholder="请输入全文检索内容" />
</Form.Item>
</Col>
<Col>
<Form.Item label=" ">
<Button type="primary" htmlType="submit" onClick={clickSubmit}>
确认
</Button>
</Form.Item>
</Col>
</Row>
</Form>
</div>
}
title="全文检索"
trigger="click"
open={open}
onOpenChange={handleOpenChange}
>
<Button type="primary">全文检索</Button>
</Popover>
)
}
export default FullTextSearch
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IoSearch } from 'react-icons/io5'
import { useLogsContext } from 'src/contexts/LogsContext'
import { ISOToTimestamp } from 'src/utils/time'
import { useSearchParams } from 'react-router-dom'
import FullTextSearch from './FullTextSearch'
const RawLogQuery = () => {
const { query, updateQuery, fetchData } = useLogsContext()
// 分析字段的代码提示
Expand All @@ -32,6 +33,7 @@ const RawLogQuery = () => {
return (
<>
<div className="searchBarMain">
<FullTextSearch />
<div className="inputBox" style={{ overflowX: isMultipleLines ? 'visible' : 'hidden' }}>
<CodeMirrorSearch
title="logInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const LogRuleList = () => {
return (
<Card
className="overflow-y-auto h-1/2 w-full overflow-x-hidden"
title="日志规则列表"
title="日志解析规则"
classNames={{
body: 'p-0 pr-2',
}}
Expand Down

0 comments on commit 6a52f7e

Please sign in to comment.