Skip to content

Commit

Permalink
Merge pull request #2604 from emqx/dev/1.9.0
Browse files Browse the repository at this point in the history
Sync code from refs/heads/dev/1.9.0 to enterprise
  • Loading branch information
Kinplemelon authored Apr 28, 2024
2 parents ac5b812 + e70b79e commit aa0b28a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/hooks/Rule/rule/useDebugRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addTrace, deleteTrace, getTraceLog } from '@/api/diagnose'
import { applyRuleTest } from '@/api/ruleengine'
import useSyncPolling from '@/hooks/useSyncPolling'
import { TraceRecord } from '@/types/diagnose'
import { TraceEncodeType } from '@/types/enum'
import { LogTraceFormatter, TraceEncodeType } from '@/types/enum'
import { BasicRule, RuleItem } from '@/types/rule'
import { cloneDeep, debounce, isArray, isEqual, isFunction, mergeWith, startCase } from 'lodash'
import moment from 'moment'
Expand Down Expand Up @@ -48,7 +48,7 @@ export default () => {
payload_encode: TraceEncodeType.Text,
start_at: new Date().toISOString(),
end_at: new Date(oneDayLaterTimestamp).toISOString(),
formatter: 'json',
formatter: LogTraceFormatter.JSON,
}
const { name } = await addTrace(traceData)
emptyLogData()
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/LogTrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@ export default {
zh: `确定跟踪文件中有效负载格式的格式。<br/>\`text\`:基于文本的协议或纯文本协议。建议在有效负载为JSON编码时使用<br/>\`hex\`:二进制十六进制编码。当有效负载是自定义二进制协议时,建议使用此选项<br/>\`hidden\`:有效负载被模糊化为 \`******\``,
en: `Determine the format of the payload format in the trace file.<br/>\`text\`: Text-based protocol or plain text protocol.It is recommended when payload is JSON encoded.<br/>\`hex\`: Binary hexadecimal encode. It is recommended when payload is a custom binary protocol.<br/>\`hidden\`: payload is obfuscated as \`******\``,
},
formatter: {
zh: '格式化',
en: 'Formatter',
},
}
5 changes: 3 additions & 2 deletions src/types/diagnose.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogTraceType, SlowSubType, TraceEncodeType } from './enum'
import { LogTraceFormatter, LogTraceType, SlowSubType, TraceEncodeType } from './enum'

export interface SlowSubConfig {
enable: boolean
Expand Down Expand Up @@ -26,7 +26,7 @@ export type TraceRecord = {
start_at: string
end_at: string
payload_encode: TraceEncodeType
formatter?: 'json' | 'plain'
formatter?: LogTraceFormatter
}

export type TraceFormRecord = {
Expand All @@ -38,6 +38,7 @@ export type TraceFormRecord = {
ruleid: string
startTime: [string, string] | [Date, Date]
payload_encode: TraceEncodeType
formatter?: LogTraceFormatter
}

export interface TraceItem {
Expand Down
5 changes: 5 additions & 0 deletions src/types/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ export enum LogTraceType {
RuleID = 'ruleid',
}

export enum LogTraceFormatter {
JSON = 'json',
Text = 'text',
}

export const enum TraceEncodeType {
Text = 'text',
HEX = 'hex',
Expand Down
24 changes: 22 additions & 2 deletions src/views/Diagnose/LogTrace/LogTrace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item prop="formatter" :label="tl('formatter')">
<el-select v-model="record.formatter">
<el-option
v-for="{ label, value } in formatterOpt"
:key="value"
:value="value"
:label="label"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
Expand Down Expand Up @@ -218,7 +230,7 @@ import CheckIcon from '@/components/CheckIcon.vue'
import FormItemLabel from '@/components/FormItemLabel.vue'
import useFormRules from '@/hooks/useFormRules'
import { TraceFormRecord, TraceItem, TraceRecord } from '@/types/diagnose'
import { CheckStatus, LogTraceType, TraceEncodeType } from '@/types/enum'
import { CheckStatus, LogTraceType, TraceEncodeType, LogTraceFormatter } from '@/types/enum'
import { Plus } from '@element-plus/icons-vue'
import { ElForm, FormRules, ElMessage as M, ElMessageBox as MB } from 'element-plus'
import { omit, startCase } from 'lodash'
Expand All @@ -237,6 +249,7 @@ const createRawTraceForm = () => ({
ruleid: '',
startTime: ['', ''] as [string, string],
payload_encode: TraceEncodeType.Text,
formatter: LogTraceFormatter.Text,
})
type TraceItemInTable = TraceItem & {
Expand Down Expand Up @@ -297,6 +310,11 @@ export default defineComponent({
{ label: 'Hidden', value: TraceEncodeType.Hidden },
]
const formatterOpt = [
{ label: 'JSON', value: LogTraceFormatter.JSON },
{ label: 'Text', value: LogTraceFormatter.Text },
]
const countTotalLogSize = (sizeMap: Record<string, number>) => {
return Object.keys(sizeMap).reduce((total, currentNode) => total + sizeMap[currentNode], 0)
}
Expand Down Expand Up @@ -328,11 +346,12 @@ export default defineComponent({
createForm.value?.validate(async (valid: boolean) => {
if (!valid) return
createLoading.value = true
const { clientid, topic, ip_address, ruleid, startTime, type } = record.value
const { clientid, topic, ip_address, ruleid, startTime, type, formatter } = record.value
let targetInfo: TraceRecord = {
...omit(record.value, ['clientid', 'topic', 'ip_address', 'startTime']),
start_at: new Date(startTime[0]).toISOString(),
end_at: new Date(startTime[1]).toISOString(),
...(formatter ? { formatter } : {}),
}
switch (type) {
case LogTraceType.ClientID:
Expand Down Expand Up @@ -439,6 +458,7 @@ export default defineComponent({
typeOptions,
record,
encodeTypeOpt,
formatterOpt,
LogTraceType,
startCase,
transMemorySizeNumToStr,
Expand Down

0 comments on commit aa0b28a

Please sign in to comment.