From bdc08f42e4ab1e29bebdef9e6e00e465dcd1f886 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Mon, 7 Mar 2022 14:50:33 +0800 Subject: [PATCH] feat: add filters --- src/locales/lang/en.ts | 3 +- src/locales/lang/zh.ts | 4 +- src/store/modules/log.ts | 142 ++++++++ src/views/components/ConditionTags.vue | 11 +- src/views/components/LogTable/LogBrowser.vue | 8 +- src/views/dashboard/controls/Log.vue | 76 +++- src/views/dashboard/controls/index.ts | 3 +- src/views/dashboard/related/log/Header.vue | 343 ++++++++++++++++++ .../related/log/{Filter.vue => List.vue} | 0 src/views/dashboard/related/trace/Filter.vue | 2 +- 10 files changed, 581 insertions(+), 11 deletions(-) create mode 100644 src/store/modules/log.ts create mode 100644 src/views/dashboard/related/log/Header.vue rename src/views/dashboard/related/log/{Filter.vue => List.vue} (100%) diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index b3649192..ac45f3e6 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -324,11 +324,12 @@ const msg = { logContentEmpty: "The content of the log should not be empty.", debug: "Debug", addTraceID: "Please input a trace ID", + addTags: "Please input a tag", addKeywordsOfContent: "Please input a keyword of content", addExcludingKeywordsOfContent: "Please input a keyword of excluding content", noticeTag: "Please press Enter after inputting a tag(key=value).", conditionNotice: - "Notice: Please press enter after inputting a tag, key of content, exclude key of content.", + "Notice: Please press Enter after inputting a tag, key of content, exclude key of content(key=value).", cacheModalTitle: "Clear cache reminder", yes: "Yes", no: "No", diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index d60322cf..0b605780 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -325,10 +325,12 @@ const msg = { logContentEmpty: "日志数据的内容不应该是空。", debug: "调试", addTraceID: "请输入一个Trace ID", + addTags: "请输入一个标签", addKeywordsOfContent: "请输入一个内容关键词", addExcludingKeywordsOfContent: "请输入一个内容不包含的关键词", noticeTag: "请输入一个标签(key=value)之后回车", - conditionNotice: "请输入一个标签、内容关键词或者内容不包含的关键词之后回车", + conditionNotice: + "请输入一个标签、内容关键词或者内容不包含的关键词(key=value)之后回车", cacheModalTitle: "清除缓存提醒", yes: "是的", no: "不", diff --git a/src/store/modules/log.ts b/src/store/modules/log.ts new file mode 100644 index 00000000..6cc2882d --- /dev/null +++ b/src/store/modules/log.ts @@ -0,0 +1,142 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { defineStore } from "pinia"; +import { Duration } from "@/types/app"; +import { Instance, Endpoint, Service } from "@/types/selector"; +import { store } from "@/store"; +import graphql from "@/graphql"; +import { AxiosResponse } from "axios"; +import { useAppStoreWithOut } from "@/store/modules/app"; +import { useSelectorStore } from "@/store/modules/selectors"; + +interface LogState { + services: Service[]; + instances: Instance[]; + endpoints: Endpoint[]; + conditions: any; + durationTime: Duration; + selectorStore: any; + supportQueryLogsByKeywords: boolean; + logs: any[]; + logsTotal: number; +} + +export const logStore = defineStore({ + id: "trace", + state: (): LogState => ({ + services: [{ value: "0", label: "All" }], + instances: [{ value: "0", label: "All" }], + endpoints: [{ value: "0", label: "All" }], + conditions: { + queryDuration: useAppStoreWithOut().durationTime, + paging: { pageNum: 1, pageSize: 15, needTotal: true }, + }, + supportQueryLogsByKeywords: true, + durationTime: useAppStoreWithOut().durationTime, + selectorStore: useSelectorStore(), + logs: [], + logsTotal: 0, + }), + actions: { + setLogCondition(data: any) { + this.conditions = { ...this.conditions, ...data }; + }, + async getServices(layer: string) { + const res: AxiosResponse = await graphql.query("queryServices").params({ + layer, + }); + if (res.data.errors) { + return res.data; + } + this.services = [ + { value: "0", label: "All" }, + ...res.data.data.services, + ] || [{ value: "0", label: "All" }]; + return res.data; + }, + async getInstances() { + const res: AxiosResponse = await graphql.query("queryInstances").params({ + serviceId: this.selectorStore.currentService.id, + duration: this.durationTime, + }); + + if (res.data.errors) { + return res.data; + } + this.instances = [ + { value: "0", label: "All" }, + ...res.data.data.pods, + ] || [{ value: " 0", label: "All" }]; + return res.data; + }, + async getEndpoints() { + const res: AxiosResponse = await graphql.query("queryEndpoints").params({ + serviceId: this.selectorStore.currentService.id, + duration: this.durationTime, + keyword: "", + }); + if (res.data.errors) { + return res.data; + } + this.endpoints = [ + { value: "0", label: "All" }, + ...res.data.data.pods, + ] || [{ value: "0", label: "All" }]; + return res.data; + }, + async queryLogsByKeywords() { + const res: AxiosResponse = await graphql + .query("queryLogsByKeywords") + .params({}); + + if (res.data.errors) { + return res.data; + } + + this.supportQueryLogsByKeywords = res.data.data.support; + return res.data; + }, + async getLogs() { + const res: AxiosResponse = await graphql + .query("queryServiceLogs") + .params({ condition: this.conditions }); + + if (res.data.errors) { + return res.data; + } + this.logs = res.data.data.queryLogs.logs; + this.logsTotal = res.data.data.queryLogs.total; + return res.data; + }, + async getBrowserLogs() { + const res: AxiosResponse = await graphql + .query("queryBrowserErrorLogs") + .params({ condition: this.conditions }); + + if (res.data.errors) { + return res.data; + } + this.logs = res.data.data.queryBrowserErrorLogs.logs; + this.logsTotal = res.data.data.queryBrowserErrorLogs.total; + return res.data; + }, + }, +}); + +export function useLogStore(): any { + return logStore(store); +} diff --git a/src/views/components/ConditionTags.vue b/src/views/components/ConditionTags.vue index b73ae6a0..f755910d 100644 --- a/src/views/components/ConditionTags.vue +++ b/src/views/components/ConditionTags.vue @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> diff --git a/src/views/dashboard/controls/Log.vue b/src/views/dashboard/controls/Log.vue index 35c421ec..542e6448 100644 --- a/src/views/dashboard/controls/Log.vue +++ b/src/views/dashboard/controls/Log.vue @@ -13,5 +13,79 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + + diff --git a/src/views/dashboard/controls/index.ts b/src/views/dashboard/controls/index.ts index 4f2ee20e..7fdcd85a 100644 --- a/src/views/dashboard/controls/index.ts +++ b/src/views/dashboard/controls/index.ts @@ -19,5 +19,6 @@ import Tab from "./Tab.vue"; import Widget from "./Widget.vue"; import Trace from "./Trace.vue"; import Profile from "./Profile.vue"; +import Log from "./Log.vue"; -export default { Tab, Widget, Trace, Topology, Profile }; +export default { Tab, Widget, Trace, Topology, Profile, Log }; diff --git a/src/views/dashboard/related/log/Header.vue b/src/views/dashboard/related/log/Header.vue new file mode 100644 index 00000000..e441c65d --- /dev/null +++ b/src/views/dashboard/related/log/Header.vue @@ -0,0 +1,343 @@ + + + + diff --git a/src/views/dashboard/related/log/Filter.vue b/src/views/dashboard/related/log/List.vue similarity index 100% rename from src/views/dashboard/related/log/Filter.vue rename to src/views/dashboard/related/log/List.vue diff --git a/src/views/dashboard/related/trace/Filter.vue b/src/views/dashboard/related/trace/Filter.vue index 236697b1..7c72741e 100644 --- a/src/views/dashboard/related/trace/Filter.vue +++ b/src/views/dashboard/related/trace/Filter.vue @@ -198,7 +198,7 @@ async function queryTraces() { ElMessage.error(res.errors); } } -function changeField(type: string, opt: any[]) { +function changeField(type: string, opt: any) { state[type] = opt[0]; if (type === "service") { getEndpoints();