feat: highlight search log keywords (#398)

This commit is contained in:
Starry 2024-06-02 18:33:43 +08:00 committed by GitHub
parent 065337c344
commit 5419a69700
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 59 additions and 45 deletions

View File

@ -300,7 +300,7 @@ const msg = {
viewLogs: "View Logs", viewLogs: "View Logs",
logsTagsTip: `Only tags defined in the core/default/searchableLogsTags are searchable. logsTagsTip: `Only tags defined in the core/default/searchableLogsTags are searchable.
Check more details on the Configuration Vocabulary page`, Check more details on the Configuration Vocabulary page`,
keywordsOfContentLogTips: "Current storage of SkyWalking OAP server does not support this.", keywordsOfContentLogTips: "Current storage of SkyWalking OAP server does not support this",
setEvent: "Set Event", setEvent: "Set Event",
viewAttributes: "View", viewAttributes: "View",
attributes: "Attributes", attributes: "Attributes",
@ -355,7 +355,7 @@ const msg = {
addKeywordsOfContent: "Please input a keyword of content", addKeywordsOfContent: "Please input a keyword of content",
addExcludingKeywordsOfContent: "Please input a keyword of excluding content", addExcludingKeywordsOfContent: "Please input a keyword of excluding content",
noticeTag: "Please press Enter after inputting a tag(key=value).", noticeTag: "Please press Enter after inputting a tag(key=value).",
conditionNotice: "Notice: Please press Enter after inputting a key of content, exclude key of content(key=value).", conditionNotice: "Notice: Please press Enter after inputting a key of content, exclude key of content(key=value)",
language: "Language", language: "Language",
save: "Save", save: "Save",
editStrategy: "Edit Policies", editStrategy: "Edit Policies",

View File

@ -299,7 +299,7 @@ const msg = {
viewLogs: "Ver Registro de Datos", viewLogs: "Ver Registro de Datos",
logsTagsTip: `Solamente etiquetas definidas en core/default/searchableLogsTags pueden ser buscadas. logsTagsTip: `Solamente etiquetas definidas en core/default/searchableLogsTags pueden ser buscadas.
Más información en la página de Vocabulario de Configuración`, Más información en la página de Vocabulario de Configuración`,
keywordsOfContentLogTips: "El almacenamiento actual del servidor SkyWalking OAP no lo soporta.", keywordsOfContentLogTips: "El almacenamiento actual del servidor SkyWalking OAP no lo soporta",
setEvent: "Establecer Evento", setEvent: "Establecer Evento",
viewAttributes: "Ver", viewAttributes: "Ver",
serviceEvents: "Eventos Servico", serviceEvents: "Eventos Servico",

View File

@ -53,6 +53,9 @@ export const logStore = defineStore({
setLogCondition(data: Recordable) { setLogCondition(data: Recordable) {
this.conditions = { ...this.conditions, ...data }; this.conditions = { ...this.conditions, ...data };
}, },
getLogKeywords() {
return this.conditions.keywordsOfContent;
},
resetState() { resetState() {
this.logs = []; this.logs = [];
this.conditions = { this.conditions = {

View File

@ -67,51 +67,55 @@ limitations under the License. -->
</div> </div>
<ConditionTags :type="'LOG'" @update="updateTags" /> <ConditionTags :type="'LOG'" @update="updateTags" />
</div> </div>
<div class="row tips" v-show="!isBrowser"> <div v-show="!isBrowser">
<b>{{ t("conditionNotice") }}</b> <div class="row tips">
</div> <b>{{ t("conditionNotice") }}</b>
<div class="flex-h" v-show="!isBrowser">
<div class="mr-5" v-show="logStore.supportQueryLogsByKeywords">
<span class="mr-5 grey">{{ t("keywordsOfContent") }}:</span>
<span class="log-tags">
<span class="selected" v-for="(item, index) in keywordsOfContent" :key="`keywordsOfContent${index}`">
<span>{{ item }}</span>
<span class="remove-icon" @click="removeContent(index)">×</span>
</span>
</span>
<el-input
size="small"
class="inputs-max"
:placeholder="t('addKeywordsOfContent')"
v-model="contentStr"
@change="addLabels('keywordsOfContent')"
/>
</div>
<div class="mr-5" v-show="logStore.supportQueryLogsByKeywords">
<span class="grey mr-5"> {{ t("excludingKeywordsOfContent") }}: </span>
<span class="log-tags">
<span
class="selected"
v-for="(item, index) in excludingKeywordsOfContent"
:key="`excludingKeywordsOfContent${index}`"
>
<span>{{ item }}</span>
<span class="remove-icon" @click="removeExcludeContent(index)"> × </span>
</span>
</span>
<el-input
class="inputs-max"
size="small"
:placeholder="t('addExcludingKeywordsOfContent')"
v-model="excludingContentStr"
@change="addLabels('excludingKeywordsOfContent')"
/>
<el-tooltip :content="t('keywordsOfContentLogTips')"> <el-tooltip :content="t('keywordsOfContentLogTips')">
<span v-show="!logStore.supportQueryLogsByKeywords"> <span v-show="!logStore.supportQueryLogsByKeywords">
<Icon iconName="help" class="mr-5" /> <Icon iconName="help" />
</span> </span>
</el-tooltip> </el-tooltip>
</div> </div>
<div v-show="logStore.supportQueryLogsByKeywords">
<div class="flex-h">
<div class="mr-5">
<span class="mr-5 grey">{{ t("keywordsOfContent") }}:</span>
<span class="log-tags">
<span class="selected" v-for="(item, index) in keywordsOfContent" :key="`keywordsOfContent${index}`">
<span>{{ item }}</span>
<span class="remove-icon" @click="removeContent(index)">×</span>
</span>
</span>
<el-input
size="small"
class="inputs-max"
:placeholder="t('addKeywordsOfContent')"
v-model="contentStr"
@change="addLabels('keywordsOfContent')"
/>
</div>
<div class="mr-5">
<span class="grey mr-5"> {{ t("excludingKeywordsOfContent") }}: </span>
<span class="log-tags">
<span
class="selected"
v-for="(item, index) in excludingKeywordsOfContent"
:key="`excludingKeywordsOfContent${index}`"
>
<span>{{ item }}</span>
<span class="remove-icon" @click="removeExcludeContent(index)"> × </span>
</span>
</span>
<el-input
class="inputs-max"
size="small"
:placeholder="t('addExcludingKeywordsOfContent')"
v-model="excludingContentStr"
@change="addLabels('excludingKeywordsOfContent')"
/>
</div>
</div>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -35,7 +35,7 @@ limitations under the License. -->
import { BrowserLogConstants } from "./data"; import { BrowserLogConstants } from "./data";
import { dateFormat } from "@/utils/dateFormat"; import { dateFormat } from "@/utils/dateFormat";
/*global defineProps, defineEmits, NodeListOf */ /* global defineProps, defineEmits */
const props = defineProps({ const props = defineProps({
data: { type: Object as any, default: () => ({}) }, data: { type: Object as any, default: () => ({}) },
}); });

View File

@ -30,7 +30,7 @@ limitations under the License. -->
<Icon iconName="merge" /> <Icon iconName="merge" />
</el-tooltip> </el-tooltip>
</span> </span>
<span v-else>{{ data[item.label] }}</span> <span v-else v-html="highlightKeywords(data[item.label])"></span>
</div> </div>
</div> </div>
</template> </template>
@ -42,6 +42,8 @@ limitations under the License. -->
import type { LayoutConfig } from "@/types/dashboard"; import type { LayoutConfig } from "@/types/dashboard";
import { dateFormat } from "@/utils/dateFormat"; import { dateFormat } from "@/utils/dateFormat";
import { WidgetType } from "@/views/dashboard/data"; import { WidgetType } from "@/views/dashboard/data";
import { useLogStore } from "@/store/modules/log";
const logStore = useLogStore();
/*global defineProps, defineEmits, Recordable */ /*global defineProps, defineEmits, Recordable */
const props = defineProps({ const props = defineProps({
@ -58,6 +60,11 @@ limitations under the License. -->
} }
return (props.data.tags.find((d: { key: string; value: string }) => d.key === "level") || {}).value || ""; return (props.data.tags.find((d: { key: string; value: string }) => d.key === "level") || {}).value || "";
}); });
const highlightKeywords = (data: string) => {
const keywords = Object.values(logStore.getLogKeywords());
const regex = new RegExp(keywords.join("|"), "gi");
return data.replace(regex, (match) => `<span style="color: red">${match}</span>`);
};
function selectLog(label: string, value: string) { function selectLog(label: string, value: string) {
if (label === "traceId") { if (label === "traceId") {