Skip to content

Commit

Permalink
refactor(rule): add label for some log block
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinplemelon committed May 10, 2024
1 parent d967760 commit accaac3
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 29 deletions.
12 changes: 2 additions & 10 deletions src/hooks/Rule/rule/useDebugRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,8 @@ export default () => {
syncPolling(getNewestLog, 1500)
}

const submitMockDataForTestRule = async (ruleId: string, data: Record<string, any>) => {
try {
await applyRuleTest(ruleId, data)
if (!needPolling.value) {
needPolling.value = true
startPolling()
}
} catch (error) {
//
}
const submitMockDataForTestRule = (ruleId: string, data: Record<string, any>) => {
return applyRuleTest(ruleId, data)
}

/**
Expand Down
66 changes: 59 additions & 7 deletions src/hooks/Rule/rule/useFormatDebugLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const enum LogMsg {
ActionSuccess = 'action_success',
ActionTemplateRendered = 'action_template_rendered',
AsyncSendMsgToRemoteNode = 'async_send_msg_to_remote_node',
OutOfService = 'out_of_service',
ActionFailed = 'action_failed',
RequestExpired = 'request_expired',
/* Do Not Need Start */
CallActionFunction = 'call_action_function',
RepublishMessage = 'republish_message',
Expand Down Expand Up @@ -101,6 +104,8 @@ type TargetLogGenerator = (log: TargetLogInfo) => TargetLogInfo
const detectLogItemResult = (log: LogItem): boolean => {
if (log.meta.reason) {
return log.msg !== LogMsg.StopRendering ? false : true
} else if (log.msg === LogMsg.OutOfService) {
return false
}
return true
}
Expand All @@ -118,7 +123,10 @@ const detectRuleExecLogArrResult = (logArr: Array<LogItem>): LogResult => {
}

const detectActionLogArrResult = (logArr: Array<LogItem>): LogResult => {
if (logArr.length === 0 || logArr.every(({ meta }) => !meta.result && !meta.reason)) {
if (
logArr.length === 0 ||
logArr.every(({ meta, msg }) => !meta.result && !meta.reason && msg !== LogMsg.OutOfService)
) {
return LogResult.Pending
}
return logArr.every(detectLogItemResult) ? LogResult.OK : LogResult.Error
Expand Down Expand Up @@ -258,6 +266,23 @@ export default () => {
return logArr.filter((item) => getLogItemTriggerTime(item) >= startTimestamp)
}

/**
* return true if the log need be dropped
*/
const detectLogNeedBeDropped = (log: LogItem) => {
let needBeDropped = false
if (EXCLUDED_LOGS.includes(log.msg)) {
needBeDropped = true
}
if (/connector/i.test(log.msg) && log.meta.connector) {
needBeDropped = true
}
if (/msg =>/.test(log.msg) && !log.meta.action_info) {
needBeDropped = true
}
return needBeDropped
}

const formatLog = (logArr: Array<LogItem>) => {
const ret: FormattedLog = {}
const timeGroupedMap = groupBy(logArr, getLogItemTriggerTime)
Expand All @@ -275,7 +300,7 @@ export default () => {
rawLogArr: [],
}
}
if (EXCLUDED_LOGS.includes(logItem.msg)) {
if (detectLogNeedBeDropped(logItem)) {
return obj
}
obj[target].info[logItem.msg] = { time: logItem.time, logContent: logItem }
Expand Down Expand Up @@ -310,22 +335,43 @@ export default () => {

export const useShowLog = () => {
const { tl } = useI18nTl('RuleEngine')
const commonActionLogMsgMap = new Map([
[LogMsg.ActionTemplateRendered, tl('requestParameter')],
[LogMsg.ActionSuccess, tl('actionExecutionLog')],
[LogMsg.OutOfService, tl('actionOutOfService')],
[LogMsg.ActionFailed, tl('actionFailed')],
[LogMsg.RequestExpired, tl('requestExpired')],
])
const ruleLogMsgMap = new Map([[LogMsg.RuleActivated, tl('eventData')]])
const getRuleLogMsgTitle = (logMsg: LogMsg) => {
const title = ruleLogMsgMap.get(logMsg)
return title ? title : tl('executionResult')
}
const republishLogMsgMap = new Map([[LogMsg.ActionSuccess, tl('messagePublishParameters')]])
const republishLogMsgMap = new Map([[LogMsg.ActionTemplateRendered, tl('requestParameter')]])
const getRepublishLogMsgTitle = (logMsg: LogMsg) => {
const title = republishLogMsgMap.get(logMsg)
let title = republishLogMsgMap.get(logMsg)
if (!title) {
const sTitle = commonActionLogMsgMap.get(logMsg)
if (sTitle) {
title = sTitle
}
}
return title ? title : startCase(logMsg)
}
const consoleLogMsgMap = new Map([
[LogMsg.ActionTemplateRendered, tl('consoleActionTemplateRendered')],
[LogMsg.ActionSuccess, tl('actionExecutionLog')],
])
const getConsoleLogMsgTitle = (logMsg: LogMsg) => {
const title = consoleLogMsgMap.get(logMsg)
return title ? title : startCase(logMsg)
}
const httpActionLogMsgMap = new Map([
[LogMsg.ActionTemplateRendered, tl('requestParameter')],
[LogMsg.ActionSuccess, tl('responseResult')],
[LogMsg.StopRendering, tl('responseResult')],
])
const actionTypeLogMsgMap = new Map([[BridgeType.Webhook, httpActionLogMsgMap]])

const getActionLogMsgTitle = (targetLogData: TargetLog, logMsg: LogMsg) => {
const { type } = targetLogData.targetInfo || {}
let title: undefined | string = undefined
Expand All @@ -338,8 +384,11 @@ export const useShowLog = () => {
}
}
}
if (!title && logMsg === LogMsg.ActionSuccess) {
title = tl('actionExecutionLog')
if (!title) {
const sTitle = commonActionLogMsgMap.get(logMsg)
if (sTitle) {
title = sTitle
}
}
return title || startCase(logMsg)
}
Expand All @@ -351,6 +400,9 @@ export const useShowLog = () => {
if (type === LogTargetType.Republish) {
return getRepublishLogMsgTitle(logMsg)
}
if (type === LogTargetType.Console) {
return getConsoleLogMsgTitle(logMsg)
}
if (type === LogTargetType.Action) {
return getActionLogMsgTitle(targetLogData, logMsg)
}
Expand Down
22 changes: 19 additions & 3 deletions src/i18n/RuleEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,12 @@ export default {
zh: '消息发布参数',
en: 'Message Publish Parameters',
},
consoleActionTemplateRendered: {
zh: '动作模板渲染结果',
en: 'Action Template Rendered Result',
},
requestParameter: {
zh: '请求参数',
zh: '请求信息',
en: 'Request',
},
responseResult: {
Expand All @@ -1030,8 +1034,20 @@ export default {
en: 'No response: Request is disabled',
},
actionExecutionLog: {
zh: '动作执行日志',
en: 'Action Execution Log',
zh: '执行结果',
en: 'Result',
},
actionOutOfService: {
zh: '服务不可用',
en: 'Out of Service',
},
actionFailed: {
zh: '动作执行失败',
en: 'Action Failed',
},
requestExpired: {
zh: '请求超时',
en: 'Request Expired',
},
debugLeaveConfirm: {
zh: '离开页面将停止测试,是否确认离开?',
Expand Down
11 changes: 6 additions & 5 deletions src/views/RuleEngine/components/LogDataDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{{ getLogItemTitle(targetLogData, logMsg as LogMsg) }}
</el-radio-button>
</el-radio-group>
<p v-else>
<p class="log-item-title" v-else>
{{ getLogItemTitle(targetLogData, getSelectedBlock(logTarget)) }}
</p>
<!-- <span class="log-time">
Expand Down Expand Up @@ -388,12 +388,8 @@ watch(
margin-right: 16px;
}
.event {
flex-grow: 2;
flex-shrink: 0;
}
.topic {
flex-grow: 1;
}
}
.execution-item-time,
.log-time {
Expand Down Expand Up @@ -422,6 +418,11 @@ watch(
.target-info-hd {
align-items: center;
margin-bottom: 12px;
.log-item-title {
margin-top: 4px;
margin-bottom: 0;
line-height: 1.4;
}
}
.icon-status {
margin-right: 8px;
Expand Down
8 changes: 4 additions & 4 deletions src/views/RuleEngine/components/MockDataDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ const props = defineProps({
type: Object,
required: true,
},
isSubmitting: {
type: Boolean,
default: false,
},
})
const emit = defineEmits(['update:modelValue', 'submit'])
Expand Down Expand Up @@ -93,14 +97,10 @@ const {
watch(showDrawer, (val) => {
if (val) {
setDataTypeNContext()
} else {
isSubmitting.value = false
}
})
const isSubmitting = ref(false)
const submit = () => {
isSubmitting.value = true
const context = getMockContext()
emit('submit', context)
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/RuleEngine/components/RuleTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
v-model="showMockDataDrawer"
:rule-data="ruleData"
:ingress-bridge-list="ingressBridgeList"
:is-submitting="isSubmittingMockData"
@submit="handleSubmitMockData"
/>
</div>
Expand Down Expand Up @@ -67,6 +68,7 @@ const { tl } = useI18nTl('RuleEngine')
const { savedAfterRuleChange } = useStatusController()
const showMockDataDrawer = ref(false)
const isSubmittingMockData = ref(false)
const { logData, handleStopTest, submitMockDataForTestRule, startTest, setCbAfterPolling } =
useDebugRule()
Expand Down Expand Up @@ -114,6 +116,8 @@ const handleSubmitMockData = async (context: Record<string, any>) => {
showMockDataDrawer.value = false
} catch (error) {
//
} finally {
isSubmittingMockData.value = false
}
}
Expand Down

0 comments on commit accaac3

Please sign in to comment.