Skip to content

Commit

Permalink
Merge branch 'dev/1.9.0' into enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinplemelon committed May 17, 2024
2 parents 3d64fa2 + 74a0b66 commit 99fc681
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/hooks/Rule/rule/useDebugRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getKeywordsFromSQL } from '@/common/tools'
import useI18nTl from '@/hooks/useI18nTl'
import useSyncPolling from '@/hooks/useSyncPolling'
import { TraceRecord } from '@/types/diagnose'
import { LogTraceFormatter, RuleInputType, TraceEncodeType } from '@/types/enum'
import { EventForRule, LogTraceFormatter, RuleInputType, TraceEncodeType } from '@/types/enum'
import { BasicRule, BridgeItem, RuleEvent, RuleItem } from '@/types/rule'
import { ElMessageBox } from 'element-plus'
import { cloneDeep, debounce, isArray, isEqual, isFunction, mergeWith, startCase } from 'lodash'
Expand Down Expand Up @@ -386,6 +386,8 @@ export const useMockData = (
const setDataType = (type: RuleInputType, firstInput: string) => {
if (type === RuleInputType.Topic) {
dataType.value = TOPIC_EVENT
} else if (type === RuleInputType.Bridge) {
dataType.value = EventForRule.MessagePublish
} else {
dataType.value = firstInput
}
Expand Down
37 changes: 25 additions & 12 deletions src/hooks/Rule/rule/useFormatDebugLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ const EXCLUDED_LOGS = [
LogMsg.AsyncSendMsgToRemoteNode,
]

const RULE_LOGS = [
LogMsg.RuleActivated,
LogMsg.SQLSelectClauseException,
LogMsg.SQLWhereClauseException,
LogMsg.SQLForeachClauseException,
LogMsg.SQLIncaseClauseException,
LogMsg.ApplyRuleFailed,
LogMsg.SQLYieldedResult,
LogMsg.SQLYieldedNoResult,
]

export interface LogItem {
time: string
msg: LogMsg
Expand Down Expand Up @@ -132,6 +143,16 @@ const detectActionLogArrResult = (logArr: Array<LogItem>): LogResult => {
return logArr.every(detectLogItemResult) ? LogResult.OK : LogResult.Error
}

const neededInfoMap = new Map([
[LogMsg.RuleActivated, 'meta.input'],
[LogMsg.SQLYieldedResult, 'meta.result'],
[LogMsg.SQLSelectClauseException, 'meta'],
[LogMsg.SQLWhereClauseException, 'meta'],
[LogMsg.SQLForeachClauseException, 'meta'],
[LogMsg.SQLIncaseClauseException, 'meta'],
[LogMsg.ApplyRuleFailed, 'meta'],
])

export default () => {
const convertLogStrToLogArr = (logStr: string): Array<LogItem> =>
logStr
Expand All @@ -151,7 +172,7 @@ export default () => {
const getLogTypeAndTarget = (
log: LogItem,
): { target: string; type: LogTargetTypeValue; targetInfo?: TargetLog['targetInfo'] } => {
if (log.meta.action_info) {
if (log.meta.action_info && !RULE_LOGS.includes(log.msg)) {
const { type, name, func, args } = log.meta.action_info
if (type && name) {
return {
Expand All @@ -172,15 +193,6 @@ export default () => {
return { target: log.meta.rule_id || log.meta.rule_ids?.[0], type: LogTargetType.Rule }
}

const neededInfoMap = new Map([
[LogMsg.RuleActivated, 'meta.input'],
[LogMsg.SQLYieldedResult, 'meta.result'],
[LogMsg.SQLSelectClauseException, 'meta'],
[LogMsg.SQLWhereClauseException, 'meta'],
[LogMsg.SQLForeachClauseException, 'meta'],
[LogMsg.SQLIncaseClauseException, 'meta'],
[LogMsg.ApplyRuleFailed, 'meta'],
])
const ruleLogMsgOrder: Map<string, number> = new Map([[LogMsg.RuleActivated, 99]])
const handleRuleExecLogInfo: TargetLogGenerator = (log) => {
return Object.keys(log)
Expand Down Expand Up @@ -294,7 +306,7 @@ export default () => {
if (EXCLUDED_LOGS.includes(log.msg)) {
needBeDropped = true
}
if (/connector/i.test(log.msg) && log.meta.connector) {
if (/connector/i.test(log.msg) && !log.meta.action_info) {
needBeDropped = true
}
if (/msg =>/.test(log.msg) && !log.meta.action_info) {
Expand Down Expand Up @@ -439,7 +451,8 @@ export const useShowLog = () => {
if (logMsg === LogMsg.SQLYieldedNoResult) {
return `SQL ${tl('failedNoResult')}`
}
if (logContent.reason) {
const infoKey = neededInfoMap.get(logMsg as LogMsg)
if ((infoKey === 'meta' && logContent.reason) || (!infoKey && logContent.meta.reason)) {
return `SQL ${tl('failedException')}\n${logContent.reason}`
}
}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/Rule/rule/useRuleEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default (): {
}
return Promise.resolve(eventList)
} catch (error) {
commit('SET_RULE_EVENT_REQUEST', null)
return Promise.reject(error)
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/views/Clients/components/ClientFieldSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ const reset = () => {
</script>

<style lang="scss">
.table-dropdown-btn {
// FIXME: style of plain primary button
height: 30px;
.client-field-select {
.table-dropdown-btn {
// FIXME: style of plain primary button
height: 30px;
}
}
.client-field-select-dropdown {
padding: 4px;
Expand Down
4 changes: 2 additions & 2 deletions src/views/RuleEngine/components/MockDataDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ import InfoTooltip from '@/components/InfoTooltip.vue'
import { useMockData } from '@/hooks/Rule/rule/useDebugRule'
import useI18nTl from '@/hooks/useI18nTl'
import { BridgeItem } from '@/types/rule'
import { PropType, WritableComputedRef, computed, defineEmits, defineProps, ref, watch } from 'vue'
import { CaretRight, RefreshRight } from '@element-plus/icons-vue'
import { PropType, WritableComputedRef, computed, defineEmits, defineProps, watch } from 'vue'
import FromSelect from '../components/FromSelect.vue'
import TestSQLContextForm from './TestSQLContextForm.vue'
import { CaretRight, RefreshRight } from '@element-plus/icons-vue'
const props = defineProps({
modelValue: {
Expand Down
1 change: 1 addition & 0 deletions src/views/RuleEngine/components/RuleTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const openMockDataDrawer = () => {
}
const handleSubmitMockData = async (context: Record<string, any>) => {
try {
isSubmittingMockData.value = true
await submitMockDataForTestRule(props.ruleData.id, context)
setCbAfterPolling(scrollLogToBottom)
showMockDataDrawer.value = false
Expand Down

0 comments on commit 99fc681

Please sign in to comment.