diff --git a/src/constants/templates.ts b/src/constants/templates.ts index 4adfd9e5..a7057af8 100644 --- a/src/constants/templates.ts +++ b/src/constants/templates.ts @@ -111,7 +111,7 @@ export const ServiceLayout = { y: 0, w: 8, h: 12, - i: "6", + i: "0", metrics: ["service_percentile"], metricTypes: ["readLabeledMetricsValues"], type: "Widget", @@ -127,6 +127,26 @@ export const ServiceLayout = { labelsIndex: "0, 1, 2, 3, 4", }, }, + { + x: 8, + y: 0, + w: 8, + h: 12, + i: "1", + metrics: ["service_apdex"], + metricTypes: ["readMetricsValue"], + type: "Widget", + widget: { + title: "Service Apdex", + tips: "Tooltip", + }, + graph: { + type: "Card", + }, + standard: { + divide: "10000", + }, + }, ], }, { diff --git a/src/hooks/data.ts b/src/hooks/data.ts index 3bd270bf..8914aff6 100644 --- a/src/hooks/data.ts +++ b/src/hooks/data.ts @@ -85,11 +85,3 @@ export const RespFields: any = { refId }`, }; -export enum CalculationType { - Plus = "+", - Minus = "-", - Multiplication = "*", - Division = "/", - "Convert Unix Timestamp(milliseconds)" = "milliseconds", - "Convert Unix Timestamp(seconds)" = "seconds", -} diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index 6666657d..7dc9bb07 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import dayjs from "dayjs"; import { RespFields, MetricQueryTypes } from "./data"; import { ElMessage } from "element-plus"; import { useDashboardStore } from "@/store/modules/dashboard"; @@ -62,7 +63,7 @@ export function useQueryProcessor(config: any) { normal: selectorStore.currentService.normal, scope: dashboardStore.entity, topN: 10, - order: "DES", + order: config.standard.sortOrder || "DES", }; } else { if (metricType === MetricQueryTypes.ReadLabeledMetricsValues) { @@ -142,7 +143,7 @@ export function useSourceProcessor( if (type === MetricQueryTypes.ReadMetricsValues) { source[m] = resp.data[keys[index]].values.values.map( - (d: { value: number }) => d.value + (d: { value: number }) => aggregation(d.value, config.standard) ); } if (type === MetricQueryTypes.ReadLabeledMetricsValues) { @@ -154,8 +155,8 @@ export function useSourceProcessor( .split(",") .map((item: string) => item.replace(/^\s*|\s*$/g, "")); for (const item of resVal) { - const values = item.values.values.map( - (d: { value: number }) => d.value + const values = item.values.values.map((d: { value: number }) => + aggregation(Number(d.value), config.standard) ); const indexNum = labelsIdx.findIndex((d: string) => d === item.label); @@ -167,13 +168,22 @@ export function useSourceProcessor( } } if (type === MetricQueryTypes.ReadMetricsValue) { - source[m] = Object.values(resp.data)[0]; + source[m] = aggregation( + Number(Object.values(resp.data)[0]), + config.standard + ); } if ( type === MetricQueryTypes.SortMetrics || type === MetricQueryTypes.ReadSampledRecords ) { - source[m] = Object.values(resp.data)[0] || []; + source[m] = (Object.values(resp.data)[0] || []).map( + (d: { value: unknown; name: string }) => { + d.value = aggregation(Number(d.value), config.standard); + + return d; + } + ); } if (type === MetricQueryTypes.READHEATMAP) { const resVal = Object.values(resp.data)[0] || {}; @@ -297,3 +307,34 @@ export function useQueryTopologyMetrics(metrics: string[], ids: string[]) { return { queryStr, conditions }; } + +function aggregation(val: number, standard: any): number | string { + let data: number | string = val; + + if (!isNaN(standard.plus)) { + data = val + Number(standard.plus); + return data; + } + if (!isNaN(standard.minus)) { + data = val - Number(standard.plus); + return data; + } + if (!isNaN(standard.multiply)) { + data = val * Number(standard.multiply); + return data; + } + if (!isNaN(standard.divide)) { + data = val / Number(standard.divide); + return data; + } + if (standard.milliseconds) { + data = dayjs(val).format("YYYY-MM-DD HH:mm:ss"); + return data; + } + if (standard.milliseconds) { + data = dayjs.unix(val).format("YYYY-MM-DD HH:mm:ss"); + return data; + } + + return data; +} diff --git a/src/store/data.ts b/src/store/data.ts index 5f72159e..e7b51416 100644 --- a/src/store/data.ts +++ b/src/store/data.ts @@ -48,7 +48,7 @@ export const ConfigData: any = { showYAxis: true, }, standard: { - sortOrder: "DEC", + sortOrder: "DES", unit: "min", }, children: [], @@ -72,7 +72,7 @@ export const ConfigData1: any = { showYAxis: true, }, standard: { - sortOrder: "DEC", + sortOrder: "DES", unit: "min", }, children: [], @@ -96,7 +96,7 @@ export const ConfigData2: any = { showYAxis: true, }, standard: { - sortOrder: "DEC", + sortOrder: "DES", unit: "min", }, children: [], diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index c3cf9f48..31e6da3e 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -129,7 +129,7 @@ export const dashboardStore = defineStore({ if (idx < 0) { return; } - const tabIndex = this.layout[idx].activedTabIndex; + const tabIndex = this.layout[idx].activedTabIndex || 0; const { children } = this.layout[idx].children[tabIndex]; const newItem: LayoutConfig = { ...NewControl, diff --git a/src/views/dashboard/configuration/Widget.vue b/src/views/dashboard/configuration/Widget.vue index 045fd802..44f038c0 100644 --- a/src/views/dashboard/configuration/Widget.vue +++ b/src/views/dashboard/configuration/Widget.vue @@ -17,6 +17,9 @@ limitations under the License. -->
{{ dashboardStore.selectedGrid.widget.title }} + + ({{ dashboardStore.selectedGrid.standard.unit }}) +
@@ -209,4 +212,9 @@ export default defineComponent({ .ds-name { margin-bottom: 10px; } + +.unit { + display: inline-block; + margin-left: 5px; +} diff --git a/src/views/dashboard/configuration/widget/MetricOptions.vue b/src/views/dashboard/configuration/widget/MetricOptions.vue index 831322c5..441c4384 100644 --- a/src/views/dashboard/configuration/widget/MetricOptions.vue +++ b/src/views/dashboard/configuration/widget/MetricOptions.vue @@ -256,7 +256,8 @@ function changeMetricType(index: number, opt: Option[] | any) { queryMetrics(); } async function queryMetrics() { - const params = useQueryProcessor(states); + const { standard } = dashboardStore.selectedGrid; + const params = useQueryProcessor({ ...states, standard }); if (!params) { emit("update", {}); return; @@ -269,7 +270,6 @@ async function queryMetrics() { ElMessage.error(json.errors); return; } - const { standard } = dashboardStore.selectedGrid; const source = useSourceProcessor(json, { ...states, standard }); emit("update", source); } diff --git a/src/views/dashboard/configuration/widget/StandardOptions.vue b/src/views/dashboard/configuration/widget/StandardOptions.vue index a049a3ad..fe374d52 100644 --- a/src/views/dashboard/configuration/widget/StandardOptions.vue +++ b/src/views/dashboard/configuration/widget/StandardOptions.vue @@ -17,106 +17,97 @@ limitations under the License. --> {{ t("unit") }}
{{ t("sortOrder") }}
-
+
{{ t("labels") }}
-
+
{{ t("labelsIndex") }}
{{ t("plus") }}
{{ t("minus") }}
{{ t("multiply") }}
{{ t("divide") }}
{{ t("convertToMilliseconds") }}
{{ t("convertToSeconds") }}