update standard config

This commit is contained in:
Qiuxia Fan 2022-03-13 17:39:49 +08:00
parent 592fb8220f
commit 1ac8071285
10 changed files with 115 additions and 59 deletions

View File

@ -111,7 +111,7 @@ export const ServiceLayout = {
y: 0, y: 0,
w: 8, w: 8,
h: 12, h: 12,
i: "6", i: "0",
metrics: ["service_percentile"], metrics: ["service_percentile"],
metricTypes: ["readLabeledMetricsValues"], metricTypes: ["readLabeledMetricsValues"],
type: "Widget", type: "Widget",
@ -127,6 +127,26 @@ export const ServiceLayout = {
labelsIndex: "0, 1, 2, 3, 4", 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",
},
},
], ],
}, },
{ {

View File

@ -85,11 +85,3 @@ export const RespFields: any = {
refId refId
}`, }`,
}; };
export enum CalculationType {
Plus = "+",
Minus = "-",
Multiplication = "*",
Division = "/",
"Convert Unix Timestamp(milliseconds)" = "milliseconds",
"Convert Unix Timestamp(seconds)" = "seconds",
}

View File

@ -14,6 +14,7 @@
* 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.
*/ */
import dayjs from "dayjs";
import { RespFields, MetricQueryTypes } from "./data"; import { RespFields, MetricQueryTypes } from "./data";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
@ -62,7 +63,7 @@ export function useQueryProcessor(config: any) {
normal: selectorStore.currentService.normal, normal: selectorStore.currentService.normal,
scope: dashboardStore.entity, scope: dashboardStore.entity,
topN: 10, topN: 10,
order: "DES", order: config.standard.sortOrder || "DES",
}; };
} else { } else {
if (metricType === MetricQueryTypes.ReadLabeledMetricsValues) { if (metricType === MetricQueryTypes.ReadLabeledMetricsValues) {
@ -142,7 +143,7 @@ export function useSourceProcessor(
if (type === MetricQueryTypes.ReadMetricsValues) { if (type === MetricQueryTypes.ReadMetricsValues) {
source[m] = resp.data[keys[index]].values.values.map( 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) { if (type === MetricQueryTypes.ReadLabeledMetricsValues) {
@ -154,8 +155,8 @@ export function useSourceProcessor(
.split(",") .split(",")
.map((item: string) => item.replace(/^\s*|\s*$/g, "")); .map((item: string) => item.replace(/^\s*|\s*$/g, ""));
for (const item of resVal) { for (const item of resVal) {
const values = item.values.values.map( const values = item.values.values.map((d: { value: number }) =>
(d: { value: number }) => d.value aggregation(Number(d.value), config.standard)
); );
const indexNum = labelsIdx.findIndex((d: string) => d === item.label); const indexNum = labelsIdx.findIndex((d: string) => d === item.label);
@ -167,13 +168,22 @@ export function useSourceProcessor(
} }
} }
if (type === MetricQueryTypes.ReadMetricsValue) { if (type === MetricQueryTypes.ReadMetricsValue) {
source[m] = Object.values(resp.data)[0]; source[m] = aggregation(
Number(Object.values(resp.data)[0]),
config.standard
);
} }
if ( if (
type === MetricQueryTypes.SortMetrics || type === MetricQueryTypes.SortMetrics ||
type === MetricQueryTypes.ReadSampledRecords 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) { if (type === MetricQueryTypes.READHEATMAP) {
const resVal = Object.values(resp.data)[0] || {}; const resVal = Object.values(resp.data)[0] || {};
@ -297,3 +307,34 @@ export function useQueryTopologyMetrics(metrics: string[], ids: string[]) {
return { queryStr, conditions }; 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;
}

View File

@ -48,7 +48,7 @@ export const ConfigData: any = {
showYAxis: true, showYAxis: true,
}, },
standard: { standard: {
sortOrder: "DEC", sortOrder: "DES",
unit: "min", unit: "min",
}, },
children: [], children: [],
@ -72,7 +72,7 @@ export const ConfigData1: any = {
showYAxis: true, showYAxis: true,
}, },
standard: { standard: {
sortOrder: "DEC", sortOrder: "DES",
unit: "min", unit: "min",
}, },
children: [], children: [],
@ -96,7 +96,7 @@ export const ConfigData2: any = {
showYAxis: true, showYAxis: true,
}, },
standard: { standard: {
sortOrder: "DEC", sortOrder: "DES",
unit: "min", unit: "min",
}, },
children: [], children: [],

View File

@ -129,7 +129,7 @@ export const dashboardStore = defineStore({
if (idx < 0) { if (idx < 0) {
return; return;
} }
const tabIndex = this.layout[idx].activedTabIndex; const tabIndex = this.layout[idx].activedTabIndex || 0;
const { children } = this.layout[idx].children[tabIndex]; const { children } = this.layout[idx].children[tabIndex];
const newItem: LayoutConfig = { const newItem: LayoutConfig = {
...NewControl, ...NewControl,

View File

@ -17,6 +17,9 @@ limitations under the License. -->
<div class="graph" v-loading="loading"> <div class="graph" v-loading="loading">
<div class="header"> <div class="header">
<span>{{ dashboardStore.selectedGrid.widget.title }}</span> <span>{{ dashboardStore.selectedGrid.widget.title }}</span>
<span v-show="dashboardStore.selectedGrid.standard.unit" class="unit">
({{ dashboardStore.selectedGrid.standard.unit }})
</span>
<div class="tips" v-show="dashboardStore.selectedGrid.widget.tips"> <div class="tips" v-show="dashboardStore.selectedGrid.widget.tips">
<el-tooltip :content="dashboardStore.selectedGrid.widget.tips"> <el-tooltip :content="dashboardStore.selectedGrid.widget.tips">
<Icon iconName="info_outline" size="sm" /> <Icon iconName="info_outline" size="sm" />
@ -209,4 +212,9 @@ export default defineComponent({
.ds-name { .ds-name {
margin-bottom: 10px; margin-bottom: 10px;
} }
.unit {
display: inline-block;
margin-left: 5px;
}
</style> </style>

View File

@ -256,7 +256,8 @@ function changeMetricType(index: number, opt: Option[] | any) {
queryMetrics(); queryMetrics();
} }
async function queryMetrics() { async function queryMetrics() {
const params = useQueryProcessor(states); const { standard } = dashboardStore.selectedGrid;
const params = useQueryProcessor({ ...states, standard });
if (!params) { if (!params) {
emit("update", {}); emit("update", {});
return; return;
@ -269,7 +270,6 @@ async function queryMetrics() {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
const { standard } = dashboardStore.selectedGrid;
const source = useSourceProcessor(json, { ...states, standard }); const source = useSourceProcessor(json, { ...states, standard });
emit("update", source); emit("update", source);
} }

View File

@ -17,106 +17,97 @@ limitations under the License. -->
<span class="label">{{ t("unit") }}</span> <span class="label">{{ t("unit") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.unit" v-model="selectedGrid.standard.unit"
size="small" size="small"
placeholder="Please input Unit" placeholder="Please input Unit"
@change="changeStandardOpt({ unit: state.unit })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("sortOrder") }}</span> <span class="label">{{ t("sortOrder") }}</span>
<Selector <Selector
:value="state.sortOrder" :value="sortOrder"
:options="SortOrder" :options="SortOrder"
size="small" size="small"
placeholder="Select a sort order" placeholder="Select a sort order"
class="selector" class="selector"
@change="changeStandardOpt({ sortOrder: state.sortOrder })" @change="changeStandardOpt({ sortOrder })"
/> />
</div> </div>
<div class="item"> <div class="item" v-show="percentile">
<span class="label">{{ t("labels") }}</span> <span class="label">{{ t("labels") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.metricLabels" v-model="selectedGrid.standard.metricLabels"
size="small" size="small"
placeholder="auto" placeholder="auto"
@change="changeStandardOpt({ metricLabels: state.metricLabels })"
/> />
</div> </div>
<div class="item"> <div class="item" v-show="percentile">
<span class="label">{{ t("labelsIndex") }}</span> <span class="label">{{ t("labelsIndex") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.labelsIndex" v-model="selectedGrid.standard.labelsIndex"
size="small" size="small"
placeholder="auto" placeholder="auto"
@change="changeStandardOpt({ labelsIndex: state.labelsIndex })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("plus") }}</span> <span class="label">{{ t("plus") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.plus" v-model="selectedGrid.standard.plus"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt({ plus: state.plus })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("minus") }}</span> <span class="label">{{ t("minus") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.minus" v-model="selectedGrid.standard.minus"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt({ minus: state.minus })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("multiply") }}</span> <span class="label">{{ t("multiply") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.multiply" v-model="selectedGrid.standard.multiply"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt({ multiply: state.multiply })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("divide") }}</span> <span class="label">{{ t("divide") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.divide" v-model="selectedGrid.standard.divide"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt({ divide: state.divide })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("convertToMilliseconds") }}</span> <span class="label">{{ t("convertToMilliseconds") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.milliseconds" v-model="selectedGrid.standard.milliseconds"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt({ milliseconds: state.milliseconds })"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("convertToSeconds") }}</span> <span class="label">{{ t("convertToSeconds") }}</span>
<el-input <el-input
class="input" class="input"
v-model="state.seconds" v-model="selectedGrid.standard.seconds"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt({ seconds: state.seconds })"
/> />
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { reactive } from "vue"; import { ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { SortOrder } from "../../data"; import { SortOrder } from "../../data";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
@ -124,18 +115,10 @@ import { useDashboardStore } from "@/store/modules/dashboard";
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const { selectedGrid } = dashboardStore; const { selectedGrid } = dashboardStore;
const { t } = useI18n(); const { t } = useI18n();
const state = reactive({ const percentile = ref<boolean>(
unit: selectedGrid.standard.unit, selectedGrid.metricTypes.includes("readLabeledMetricsValues")
labelsIndex: selectedGrid.standard.labelsIndex, );
metricLabels: selectedGrid.standard.metricLabels, const sortOrder = ref<string>(selectedGrid.standard.sortOrder || "DES");
plus: "",
minus: "",
multiply: "",
divide: "",
milliseconds: "",
seconds: "",
sortOrder: selectedGrid.standard.sortOrder,
});
function changeStandardOpt(param: { [key: string]: unknown }) { function changeStandardOpt(param: { [key: string]: unknown }) {
const standard = { const standard = {

View File

@ -20,8 +20,8 @@ limitations under the License. -->
v-model="fontSize" v-model="fontSize"
show-input show-input
input-size="small" input-size="small"
:min="10" :min="12"
:max="20" :max="50"
:step="1" :step="1"
@change="updateConfig({ fontSize })" @change="updateConfig({ fontSize })"
/> />

View File

@ -15,7 +15,14 @@ limitations under the License. -->
<template> <template>
<div class="widget"> <div class="widget">
<div class="header flex-h"> <div class="header flex-h">
<div>{{ data.widget?.title || "" }}</div> <div>
<span>
{{ data.widget?.title || "" }}
</span>
<span class="unit" v-show="data.standard?.unit">
({{ data.standard?.unit }})
</span>
</div>
<div> <div>
<el-tooltip :content="data.widget?.tips"> <el-tooltip :content="data.widget?.tips">
<span> <span>
@ -223,4 +230,9 @@ export default defineComponent({
text-align: center; text-align: center;
padding-top: 20px; padding-top: 20px;
} }
.unit {
display: inline-block;
margin-left: 5px;
}
</style> </style>