feat: add queries for alarm tags (#417)

This commit is contained in:
Fine0830 2024-09-29 15:15:35 +08:00 committed by GitHub
parent a5b0acda06
commit d65c18bd38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 56 additions and 17 deletions

View File

@ -46,3 +46,14 @@ export const Alarm = {
} }
}`, }`,
}; };
export const AlarmTagKeys = {
variable: "$duration: Duration!",
query: `
tagKeys: queryAlarmTagAutocompleteKeys(duration: $duration)`,
};
export const AlarmTagValues = {
variable: "$tagKey: String!, $duration: Duration!",
query: `
tagValues: queryAlarmTagAutocompleteValues(tagKey: $tagKey, duration: $duration)`,
};

View File

@ -15,6 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { Alarm } from "../fragments/alarm"; import { Alarm, AlarmTagKeys, AlarmTagValues } from "../fragments/alarm";
export const queryAlarms = `query queryAlarms(${Alarm.variable}) {${Alarm.query}}`; export const queryAlarms = `query queryAlarms(${Alarm.variable}) {${Alarm.query}}`;
export const queryAlarmTagValues = `query queryTagValues(${AlarmTagValues.variable}) {${AlarmTagValues.query}}`;
export const queryAlarmTagKeys = `query queryTagKeys(${AlarmTagKeys.variable}) {${AlarmTagKeys.query}}`;

View File

@ -19,6 +19,7 @@ import { store } from "@/store";
import graphql from "@/graphql"; import graphql from "@/graphql";
import type { AxiosResponse } from "axios"; import type { AxiosResponse } from "axios";
import type { Alarm } from "@/types/alarm"; import type { Alarm } from "@/types/alarm";
import { useAppStoreWithOut } from "@/store/modules/app";
interface AlarmState { interface AlarmState {
loading: boolean; loading: boolean;
@ -35,7 +36,9 @@ export const alarmStore = defineStore({
}), }),
actions: { actions: {
async getAlarms(params: Recordable) { async getAlarms(params: Recordable) {
this.loading = true;
const res: AxiosResponse = await graphql.query("queryAlarms").params(params); const res: AxiosResponse = await graphql.query("queryAlarms").params(params);
this.loading = false;
if (res.data.errors) { if (res.data.errors) {
return res.data; return res.data;
} }
@ -45,6 +48,20 @@ export const alarmStore = defineStore({
} }
return res.data; return res.data;
}, },
async getAlarmTagKeys() {
const res: AxiosResponse = await graphql
.query("queryAlarmTagKeys")
.params({ duration: useAppStoreWithOut().durationTime });
return res.data;
},
async getAlarmTagValues(tagKey: string) {
const res: AxiosResponse = await graphql
.query("queryAlarmTagValues")
.params({ tagKey, duration: useAppStoreWithOut().durationTime });
return res.data;
},
}, },
}); });

View File

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div class="timeline-table clear"> <div class="timeline-table clear" v-loading="alarmStore.loading">
<div v-for="(i, index) in alarmStore.alarms" :key="index" class="clear timeline-item"> <div v-for="(i, index) in alarmStore.alarms" :key="index" class="clear timeline-item">
<div class="g-sm-3 grey sm hide-xs time-line tr"> <div class="g-sm-3 grey sm hide-xs time-line tr">
{{ dateFormat(parseInt(i.startTime)) }} {{ dateFormat(parseInt(i.startTime)) }}

View File

@ -21,15 +21,7 @@ limitations under the License. -->
<span class="remove-icon" @click="removeTags(index)">×</span> <span class="remove-icon" @click="removeTags(index)">×</span>
</span> </span>
</span> </span>
<el-input <el-popover trigger="click" :visible="visible" width="300px">
v-if="type === 'ALARM'"
size="small"
v-model="tags"
class="trace-new-tag"
@change="addLabels"
:placeholder="t('addTags')"
/>
<el-popover v-else trigger="click" :visible="visible" width="300px">
<template #reference> <template #reference>
<el-input <el-input
size="small" size="small"
@ -47,7 +39,7 @@ limitations under the License. -->
</span> </span>
</div> </div>
</el-popover> </el-popover>
<span class="tags-tip" :class="type !== 'ALARM' && tagArr.length ? 'link-tips' : ''"> <span class="tags-tip" :class="tagArr.length ? 'link-tips' : ''">
<a <a
target="blank" target="blank"
href="https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/configuration-vocabulary.md" href="https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/configuration-vocabulary.md"
@ -68,6 +60,7 @@ limitations under the License. -->
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useTraceStore } from "@/store/modules/trace"; import { useTraceStore } from "@/store/modules/trace";
import { useLogStore } from "@/store/modules/log"; import { useLogStore } from "@/store/modules/log";
import { useAlarmStore } from "@/store/modules/alarm";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
@ -79,6 +72,7 @@ limitations under the License. -->
const traceStore = useTraceStore(); const traceStore = useTraceStore();
const logStore = useLogStore(); const logStore = useLogStore();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const alarmStore = useAlarmStore();
const { t } = useI18n(); const { t } = useI18n();
const tags = ref<string>(""); const tags = ref<string>("");
const tagsList = ref<string[]>([]); const tagsList = ref<string[]>([]);
@ -121,10 +115,18 @@ limitations under the License. -->
let resp: Recordable = {}; let resp: Recordable = {};
if (props.type === "TRACE") { if (props.type === "TRACE") {
resp = await traceStore.getTagKeys(); resp = await traceStore.getTagKeys();
} else { }
if (props.type === "LOG") {
resp = await logStore.getLogTagKeys(); resp = await logStore.getLogTagKeys();
} }
if (props.type === "ALARM") {
resp = await alarmStore.getAlarmTagKeys();
}
if (!resp.data) {
return;
}
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return; return;
@ -140,10 +142,17 @@ limitations under the License. -->
let resp: Recordable = {}; let resp: Recordable = {};
if (props.type === "TRACE") { if (props.type === "TRACE") {
resp = await traceStore.getTagValues(param); resp = await traceStore.getTagValues(param);
} else { }
if (props.type === "LOG") {
resp = await logStore.getLogTagValues(param); resp = await logStore.getLogTagValues(param);
} }
if (props.type === "ALARM") {
resp = await alarmStore.getAlarmTagValues(param);
}
if (!resp.data) {
return;
}
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return; return;

View File

@ -110,7 +110,7 @@ limitations under the License. -->
<div> <div>
<span class="grey title">Tags:</span> <span class="grey title">Tags:</span>
<div class="mb-5" v-for="(tag, index) in currentEvent.tags || []" :key="index" style="white-space: pre-wrap"> <div class="mb-5" v-for="(tag, index) in currentEvent.tags || []" :key="index" style="white-space: pre-wrap">
{{ tag.key + "=" + tag.value }}; {{ `${tag.key}=${tag.value}` }};
</div> </div>
</div> </div>
</div> </div>