diff --git a/src/graphql/fragments/alarm.ts b/src/graphql/fragments/alarm.ts index a2e9ba0c..76ed4672 100644 --- a/src/graphql/fragments/alarm.ts +++ b/src/graphql/fragments/alarm.ts @@ -24,6 +24,7 @@ export const Alarm = { message startTime scope + name tags { key value @@ -43,6 +44,35 @@ export const Alarm = { startTime endTime } + snapshot { + expression + metrics { + name + results { + metric { + labels { + key + value + } + } + values { + id + owner { + scope + serviceID + serviceName + normal + serviceInstanceID + serviceInstanceName + endpointID + endpointName + } + value + traceID + } + } + } + } } }`, }; diff --git a/src/hooks/useSnapshot.ts b/src/hooks/useSnapshot.ts new file mode 100644 index 00000000..2ddfc9b7 --- /dev/null +++ b/src/hooks/useSnapshot.ts @@ -0,0 +1,47 @@ +/** + * 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 type { MetricsResults } from "@/types/dashboard"; + +export function useSnapshot(metrics: { name: string; results: MetricsResults[] }[]) { + function processResults() { + const sources = metrics.map((metric: { name: string; results: MetricsResults[] }) => { + const values = metric.results.map( + (r: { values: { value: string }[]; metric: { labels: { key: string; value: string }[] } }) => { + const arr = r.values.map((v: { value: string }) => Number(v.value)); + if (!r.metric.labels.length) { + return { values: arr }; + } + const name = r.metric.labels + .map( + (label: { key: string; value: string }) => + `${metric.name}${label ? "{" : ""}${label.key}=${label.value}${label ? "}" : ""}`, + ) + .join(","); + return { name, values: arr }; + }, + ); + + return { name: metric.name, values }; + }); + + return sources; + } + + return { + processResults, + }; +} diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index 5640a21d..98764453 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -395,5 +395,7 @@ const msg = { profilingEvents: "Async Profiling Events", execArgs: "Exec Args", instances: "Instances", + snapshot: "Snapshot", + expression: "Expression", }; export default msg; diff --git a/src/locales/lang/es.ts b/src/locales/lang/es.ts index 4496b367..bc030873 100644 --- a/src/locales/lang/es.ts +++ b/src/locales/lang/es.ts @@ -395,5 +395,7 @@ const msg = { profilingEvents: "Async Profiling Events", execArgs: "Exec Args", instances: "Instances", + snapshot: "Snapshot", + expression: "Expression", }; export default msg; diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index 800d8c78..359ebb97 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -393,5 +393,7 @@ const msg = { profilingEvents: "异步分析事件", execArgs: "String任务扩展", instances: "实例", + snapshot: "快照", + expression: "表达式", }; export default msg; diff --git a/src/types/alarm.d.ts b/src/types/alarm.d.ts index 06c09958..df791ca2 100644 --- a/src/types/alarm.d.ts +++ b/src/types/alarm.d.ts @@ -27,6 +27,7 @@ export interface Alarm { scope: string; tags: Array<{ key: string; value: string }>; events: Event[]; + snapshot: Indexable; } export interface Event { diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index fa72ce4a..d021e48d 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -111,6 +111,8 @@ export interface LineConfig extends AreaConfig { showYAxis?: boolean; smallTips?: boolean; showlabels?: boolean; + noTooltips?: boolean; + showLegend?: boolean; } export interface AreaConfig { @@ -197,3 +199,17 @@ export type LegendOptions = { toTheRight: boolean; width: number; }; +export type MetricsResults = { + metric: { labels: MetricLabel[] }; + values: MetricValue[]; +}; +type MetricLabel = { + key: string; + value: string; +}; +type MetricValue = { + name: string; + value: string; + owner: null | string; + refId: null | string; +}; diff --git a/src/views/alarm/Content.vue b/src/views/alarm/Content.vue index 0a8988ae..aee06071 100644 --- a/src/views/alarm/Content.vue +++ b/src/views/alarm/Content.vue @@ -22,15 +22,17 @@ limitations under the License. -->
-