From 7aaed5c8c3a8f75adfa9cfce6945ae76287cb5e4 Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Sun, 28 Apr 2024 11:37:38 +0800 Subject: [PATCH 1/2] feat(log trace): support `formatter` --- src/hooks/Rule/rule/useDebugRule.ts | 4 ++-- src/i18n/LogTrace.js | 4 ++++ src/types/diagnose.d.ts | 5 +++-- src/types/enum.ts | 5 +++++ src/views/Diagnose/LogTrace/LogTrace.vue | 24 ++++++++++++++++++++++-- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/hooks/Rule/rule/useDebugRule.ts b/src/hooks/Rule/rule/useDebugRule.ts index a002a886f..ef498854a 100644 --- a/src/hooks/Rule/rule/useDebugRule.ts +++ b/src/hooks/Rule/rule/useDebugRule.ts @@ -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' @@ -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() diff --git a/src/i18n/LogTrace.js b/src/i18n/LogTrace.js index 29c6980a8..eba6739ab 100644 --- a/src/i18n/LogTrace.js +++ b/src/i18n/LogTrace.js @@ -119,4 +119,8 @@ export default { zh: `确定跟踪文件中有效负载格式的格式。
\`text\`:基于文本的协议或纯文本协议。建议在有效负载为JSON编码时使用
\`hex\`:二进制十六进制编码。当有效负载是自定义二进制协议时,建议使用此选项
\`hidden\`:有效负载被模糊化为 \`******\``, en: `Determine the format of the payload format in the trace file.
\`text\`: Text-based protocol or plain text protocol.It is recommended when payload is JSON encoded.
\`hex\`: Binary hexadecimal encode. It is recommended when payload is a custom binary protocol.
\`hidden\`: payload is obfuscated as \`******\``, }, + formatter: { + zh: '格式化', + en: 'Formatter', + }, } diff --git a/src/types/diagnose.d.ts b/src/types/diagnose.d.ts index 058832d1f..5e1cb1b64 100644 --- a/src/types/diagnose.d.ts +++ b/src/types/diagnose.d.ts @@ -1,4 +1,4 @@ -import { LogTraceType, SlowSubType, TraceEncodeType } from './enum' +import { LogTraceFormatter, LogTraceType, SlowSubType, TraceEncodeType } from './enum' export interface SlowSubConfig { enable: boolean @@ -26,7 +26,7 @@ export type TraceRecord = { start_at: string end_at: string payload_encode: TraceEncodeType - formatter?: 'json' | 'plain' + formatter?: LogTraceFormatter } export type TraceFormRecord = { @@ -38,6 +38,7 @@ export type TraceFormRecord = { ruleid: string startTime: [string, string] | [Date, Date] payload_encode: TraceEncodeType + formatter?: LogTraceFormatter } export interface TraceItem { diff --git a/src/types/enum.ts b/src/types/enum.ts index 6981060b0..d0c478efe 100644 --- a/src/types/enum.ts +++ b/src/types/enum.ts @@ -319,6 +319,11 @@ export enum LogTraceType { RuleID = 'ruleid', } +export enum LogTraceFormatter { + JSON = 'json', + Text = 'text', +} + export const enum TraceEncodeType { Text = 'text', HEX = 'hex', diff --git a/src/views/Diagnose/LogTrace/LogTrace.vue b/src/views/Diagnose/LogTrace/LogTrace.vue index 00c25d1d1..fa749f9f1 100644 --- a/src/views/Diagnose/LogTrace/LogTrace.vue +++ b/src/views/Diagnose/LogTrace/LogTrace.vue @@ -175,6 +175,18 @@ + + + + + + +