query metrics with standard config

This commit is contained in:
Qiuxia Fan 2022-03-17 17:32:17 +08:00
parent 0117c44c0e
commit c9af35cf1e
4 changed files with 46 additions and 21 deletions

View File

@ -31,12 +31,7 @@ limitations under the License. -->
:is="dashboardStore.selectedGrid.graph.type" :is="dashboardStore.selectedGrid.graph.type"
:intervalTime="appStoreWithOut.intervalTime" :intervalTime="appStoreWithOut.intervalTime"
:data="states.source" :data="states.source"
:config="{ :config="dashboardStore.selectedGrid"
...dashboardStore.selectedGrid.graph,
i: dashboardStore.selectedGrid.i,
metrics: dashboardStore.selectedGrid.metrics,
metricTypes: dashboardStore.selectedGrid.metricTypes,
}"
/> />
<div v-show="!dashboardStore.selectedGrid.graph.type" class="no-data"> <div v-show="!dashboardStore.selectedGrid.graph.type" class="no-data">
{{ t("noData") }} {{ t("noData") }}
@ -58,7 +53,7 @@ limitations under the License. -->
<WidgetOptions /> <WidgetOptions />
</el-collapse-item> </el-collapse-item>
<el-collapse-item :title="t('standardOptions')" name="4"> <el-collapse-item :title="t('standardOptions')" name="4">
<StandardOptions /> <StandardOptions @update="getSource" />
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
</div> </div>
@ -101,7 +96,7 @@ export default defineComponent({
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const states = reactive<{ const states = reactive<{
activeNames: string; activeNames: string;
source: any; source: unknown;
index: string; index: string;
visType: Option[]; visType: Option[];
}>({ }>({
@ -120,7 +115,6 @@ export default defineComponent({
} }
function applyConfig() { function applyConfig() {
console.log(dashboardStore.selectedGrid);
dashboardStore.setConfigs(dashboardStore.selectedGrid); dashboardStore.setConfigs(dashboardStore.selectedGrid);
dashboardStore.setConfigPanel(false); dashboardStore.setConfigPanel(false);
} }

View File

@ -40,6 +40,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.metricLabels" v-model="selectedGrid.standard.metricLabels"
size="small" size="small"
placeholder="auto" placeholder="auto"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item" v-show="percentile"> <div class="item" v-show="percentile">
@ -49,6 +50,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.labelsIndex" v-model="selectedGrid.standard.labelsIndex"
size="small" size="small"
placeholder="auto" placeholder="auto"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
@ -58,6 +60,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.plus" v-model="selectedGrid.standard.plus"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
@ -67,6 +70,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.minus" v-model="selectedGrid.standard.minus"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
@ -76,6 +80,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.multiply" v-model="selectedGrid.standard.multiply"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
@ -85,6 +90,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.divide" v-model="selectedGrid.standard.divide"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
@ -94,6 +100,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.milliseconds" v-model="selectedGrid.standard.milliseconds"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
@ -103,6 +110,7 @@ limitations under the License. -->
v-model="selectedGrid.standard.seconds" v-model="selectedGrid.standard.seconds"
size="small" size="small"
placeholder="none" placeholder="none"
@change="changeStandardOpt"
/> />
</div> </div>
</template> </template>
@ -111,21 +119,46 @@ 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";
import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor";
import { ElMessage } from "element-plus";
/*global defineEmits */
const { t } = useI18n();
const emit = defineEmits(["update", "loading"]);
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const { selectedGrid } = dashboardStore; const { selectedGrid } = dashboardStore;
const { t } = useI18n();
const percentile = ref<boolean>( const percentile = ref<boolean>(
selectedGrid.metricTypes.includes("readLabeledMetricsValues") selectedGrid.metricTypes.includes("readLabeledMetricsValues")
); );
const sortOrder = ref<string>(selectedGrid.standard.sortOrder || "DES"); const sortOrder = ref<string>(selectedGrid.standard.sortOrder || "DES");
function changeStandardOpt(param: { [key: string]: unknown }) { function changeStandardOpt(param?: any) {
const standard = { let standard = dashboardStore.selectedGrid.standard;
...selectedGrid.standard, if (param) {
...param, standard = {
}; ...dashboardStore.selectedGrid.standard,
dashboardStore.selectWidget({ ...selectedGrid, standard }); ...param,
};
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, standard });
}
queryMetrics();
}
async function queryMetrics() {
const params = useQueryProcessor(dashboardStore.selectedGrid);
if (!params) {
emit("update", {});
return;
}
emit("loading", true);
const json = await dashboardStore.fetchMetricValue(params);
emit("loading", false);
if (json.errors) {
ElMessage.error(json.errors);
return;
}
const source = useSourceProcessor(json, dashboardStore.selectedGrid);
emit("update", source);
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -139,7 +139,7 @@ export default defineComponent({
} }
} }
watch( watch(
() => [props.data.metricTypes, props.data.metrics], () => [props.data.metricTypes, props.data.metrics, props.data.standard],
() => { () => {
if (!dashboardStore.selectedGrid) { if (!dashboardStore.selectedGrid) {
return; return;

View File

@ -37,8 +37,6 @@ const props = defineProps({
smooth: false, smooth: false,
showSymbol: false, showSymbol: false,
opacity: 0.4, opacity: 0.4,
showXAxis: true,
showYAxis: true,
}), }),
}, },
}); });
@ -175,7 +173,7 @@ function getOption() {
}, },
xAxis: { xAxis: {
type: "category", type: "category",
show: props.config.showXAxis, show: true,
axisTick: { axisTick: {
lineStyle: { color: "#c1c5ca41" }, lineStyle: { color: "#c1c5ca41" },
alignWithLabel: true, alignWithLabel: true,
@ -192,7 +190,7 @@ function getOption() {
axisLabel: { axisLabel: {
color: "#9da5b2", color: "#9da5b2",
fontSize: "11", fontSize: "11",
show: props.config.showYAxis, show: true,
}, },
}, },
series: temp, series: temp,