mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-06-29 12:47:35 +00:00
feat: enhance processor
This commit is contained in:
parent
b4c1dabfad
commit
1a57665012
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
import { Duration } from "@/types/app";
|
import { Duration } from "@/types/app";
|
||||||
import { RespFields } from "./data";
|
import { RespFields } from "./data";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
export function useQueryProcessor(
|
export function useQueryProcessor(
|
||||||
config: any,
|
config: any,
|
||||||
@ -26,26 +27,28 @@ export function useQueryProcessor(
|
|||||||
if (!(config.metrics && config.metrics.length)) {
|
if (!(config.metrics && config.metrics.length)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const conditions: any = {
|
const conditions: { [key: string]: unknown } = {
|
||||||
duration: durationTime,
|
duration: durationTime,
|
||||||
};
|
};
|
||||||
const variables: string[] = [`$duration: Duration!`];
|
const variables: string[] = [`$duration: Duration!`];
|
||||||
const { currentPod, currentService, currentDestPod, currentDestService } =
|
const { currentPod, currentService, currentDestPod, currentDestService } =
|
||||||
selectorStore;
|
selectorStore;
|
||||||
|
const { normal, destNormal, entity } = dashboardStore;
|
||||||
const isRelation = [
|
const isRelation = [
|
||||||
"ServiceRelation",
|
"ServiceRelation",
|
||||||
"ServiceInstanceRelation",
|
"ServiceInstanceRelation",
|
||||||
"EndpointRelation",
|
"EndpointRelation",
|
||||||
].includes(dashboardStore.entity);
|
].includes(entity);
|
||||||
const fragment = config.metrics.map((name: string, index: number) => {
|
const fragment = config.metrics.map((name: string, index: number) => {
|
||||||
const metricTypes = config.metricTypes[index] || "";
|
const metricTypes = config.metricTypes[index] || "";
|
||||||
|
// const labels = config.metricType === 'LABELED_VALUE' ? labelsIndex : undefined;
|
||||||
if (["readSampledRecords", "sortMetrics"].includes(metricTypes)) {
|
if (["readSampledRecords", "sortMetrics"].includes(metricTypes)) {
|
||||||
variables.push(`$condition${index}: TopNCondition!`);
|
variables.push(`$condition${index}: TopNCondition!`);
|
||||||
conditions[`condition${index}`] = {
|
conditions[`condition${index}`] = {
|
||||||
name,
|
name,
|
||||||
parentService: currentService,
|
parentService: entity === "All" ? null : currentService,
|
||||||
normal: true,
|
normal: normal,
|
||||||
scope: dashboardStore.entity,
|
scope: entity,
|
||||||
topN: Number(config.standard.maxItemNum || 10),
|
topN: Number(config.standard.maxItemNum || 10),
|
||||||
order: config.standard.sortOrder || "DES",
|
order: config.standard.sortOrder || "DES",
|
||||||
};
|
};
|
||||||
@ -54,25 +57,19 @@ export function useQueryProcessor(
|
|||||||
conditions[`condition${index}`] = {
|
conditions[`condition${index}`] = {
|
||||||
name,
|
name,
|
||||||
entity: {
|
entity: {
|
||||||
scope: dashboardStore.entity,
|
scope: entity,
|
||||||
serviceName: currentService,
|
serviceName: entity === "All" ? undefined : currentService,
|
||||||
normal: true,
|
normal: true,
|
||||||
serviceInstanceName: dashboardStore.entity.includes("ServiceInstance")
|
serviceInstanceName: entity.includes("ServiceInstance")
|
||||||
? currentPod
|
? currentPod
|
||||||
: undefined,
|
: undefined,
|
||||||
endpointName: dashboardStore.entity.includes("Endpoint")
|
endpointName: entity.includes("Endpoint") ? currentPod : undefined,
|
||||||
? currentPod
|
destNormal: entity === "All" ? undefined : destNormal,
|
||||||
: undefined,
|
|
||||||
destNormal: true,
|
|
||||||
destServiceName: isRelation ? currentDestService : undefined,
|
destServiceName: isRelation ? currentDestService : undefined,
|
||||||
destServiceInstanceName:
|
destServiceInstanceName:
|
||||||
dashboardStore.entity === "ServiceInstanceRelation"
|
entity === "ServiceInstanceRelation" ? currentDestPod : undefined,
|
||||||
? currentDestPod
|
|
||||||
: undefined,
|
|
||||||
destEndpointName:
|
destEndpointName:
|
||||||
dashboardStore.entity === "EndpointRelation"
|
entity === "EndpointRelation" ? currentDestPod : undefined,
|
||||||
? currentDestPod
|
|
||||||
: undefined,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -85,5 +82,22 @@ export function useQueryProcessor(
|
|||||||
conditions,
|
conditions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// export function useSourceProcessor() {
|
export function useSourceProcessor(
|
||||||
// }
|
resp: { errors: string; data: { [key: string]: any } },
|
||||||
|
config: { metrics: string[] }
|
||||||
|
) {
|
||||||
|
const source: { [key: string]: unknown } = {};
|
||||||
|
if (resp.errors) {
|
||||||
|
ElMessage.error(resp.errors);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const keys = Object.keys(resp.data);
|
||||||
|
keys.forEach((key: string, index) => {
|
||||||
|
const m = config.metrics[index];
|
||||||
|
source[m] = resp.data[key].values.values.map(
|
||||||
|
(d: { value: number }) => d.value
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
@ -26,8 +26,8 @@ export const NewControl = {
|
|||||||
},
|
},
|
||||||
graph: {},
|
graph: {},
|
||||||
standard: {},
|
standard: {},
|
||||||
metrics: [],
|
metrics: [""],
|
||||||
metricTypes: [],
|
metricTypes: [""],
|
||||||
};
|
};
|
||||||
export const ConfigData: any = {
|
export const ConfigData: any = {
|
||||||
x: 0,
|
x: 0,
|
||||||
|
@ -34,6 +34,8 @@ interface DashboardState {
|
|||||||
activedGridItem: string;
|
activedGridItem: string;
|
||||||
durationTime: Duration;
|
durationTime: Duration;
|
||||||
selectorStore: any;
|
selectorStore: any;
|
||||||
|
normal: boolean;
|
||||||
|
destNormal: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const dashboardStore = defineStore({
|
export const dashboardStore = defineStore({
|
||||||
@ -47,6 +49,8 @@ export const dashboardStore = defineStore({
|
|||||||
activedGridItem: "",
|
activedGridItem: "",
|
||||||
durationTime: useAppStoreWithOut().durationTime,
|
durationTime: useAppStoreWithOut().durationTime,
|
||||||
selectorStore: useSelectorStore(),
|
selectorStore: useSelectorStore(),
|
||||||
|
normal: true,
|
||||||
|
destNormal: true,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setLayout(data: LayoutConfig[]) {
|
setLayout(data: LayoutConfig[]) {
|
||||||
|
@ -91,7 +91,6 @@ limitations under the License. -->
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { reactive, defineComponent } from "vue";
|
import { reactive, defineComponent } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useRoute } from "vue-router";
|
|
||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
import { useAppStoreWithOut } from "@/store/modules/app";
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
import {
|
import {
|
||||||
@ -99,6 +98,7 @@ import {
|
|||||||
DefaultGraphConfig,
|
DefaultGraphConfig,
|
||||||
PodsChartTypes,
|
PodsChartTypes,
|
||||||
TableChartTypes,
|
TableChartTypes,
|
||||||
|
EntityType,
|
||||||
} from "../data";
|
} from "../data";
|
||||||
import { Option } from "@/types/app";
|
import { Option } from "@/types/app";
|
||||||
import { WidgetConfig, GraphConfig, StandardConfig } from "@/types/dashboard";
|
import { WidgetConfig, GraphConfig, StandardConfig } from "@/types/dashboard";
|
||||||
@ -122,8 +122,7 @@ export default defineComponent({
|
|||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
const appStoreWithOut = useAppStoreWithOut();
|
const appStoreWithOut = useAppStoreWithOut();
|
||||||
const { selectedGrid } = dashboardStore;
|
const { selectedGrid, entity } = dashboardStore;
|
||||||
const params = useRoute().params;
|
|
||||||
const states = reactive<{
|
const states = reactive<{
|
||||||
activeNames: string;
|
activeNames: string;
|
||||||
source: any;
|
source: any;
|
||||||
@ -149,11 +148,11 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
states.isTable = TableChartTypes.includes(states.graph.type || "");
|
states.isTable = TableChartTypes.includes(states.graph.type || "");
|
||||||
|
|
||||||
if (params.entity === "service") {
|
if (entity === EntityType[0].value) {
|
||||||
states.visType = ChartTypes.filter(
|
states.visType = ChartTypes.filter(
|
||||||
(d: Option) => d.value !== "serviceList"
|
(d: Option) => d.value !== "serviceList"
|
||||||
);
|
);
|
||||||
} else if (params.entity === "all") {
|
} else if (entity === EntityType[1].value) {
|
||||||
states.visType = ChartTypes.filter(
|
states.visType = ChartTypes.filter(
|
||||||
(d: Option) => !PodsChartTypes.includes(d.value)
|
(d: Option) => !PodsChartTypes.includes(d.value)
|
||||||
);
|
);
|
||||||
|
@ -63,11 +63,10 @@ limitations under the License. -->
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { reactive, watch } from "vue";
|
import { reactive, watch } from "vue";
|
||||||
import type { PropType } from "vue";
|
import type { PropType } from "vue";
|
||||||
import { useRoute } from "vue-router";
|
|
||||||
import { Option } from "@/types/app";
|
import { Option } from "@/types/app";
|
||||||
import { GraphConfig } from "@/types/dashboard";
|
import { GraphConfig } from "@/types/dashboard";
|
||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
import { MetricTypes, TableChartTypes } from "../data";
|
import { MetricTypes, TableChartTypes, MetricCatalog } from "../data";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import Icon from "@/components/Icon.vue";
|
import Icon from "@/components/Icon.vue";
|
||||||
|
|
||||||
@ -80,7 +79,7 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
const emit = defineEmits(["update", "apply"]);
|
const emit = defineEmits(["update", "apply"]);
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
const { selectedGrid } = dashboardStore;
|
const { selectedGrid, entity, metrics, metricTypes } = dashboardStore;
|
||||||
const states = reactive<{
|
const states = reactive<{
|
||||||
metrics: string[];
|
metrics: string[];
|
||||||
metricTypes: string[];
|
metricTypes: string[];
|
||||||
@ -90,8 +89,8 @@ const states = reactive<{
|
|||||||
metricList: (Option & { type: string })[];
|
metricList: (Option & { type: string })[];
|
||||||
graph: GraphConfig | any;
|
graph: GraphConfig | any;
|
||||||
}>({
|
}>({
|
||||||
metrics: selectedGrid.metrics || [""],
|
metrics: metrics && metrics.length ? selectedGrid.metrics : [""],
|
||||||
metricTypes: selectedGrid.metricTypes || [""],
|
metricTypes: metricTypes && metricTypes.length ? metricTypes : [""],
|
||||||
metricTypeList: [],
|
metricTypeList: [],
|
||||||
visType: [],
|
visType: [],
|
||||||
isTable: false,
|
isTable: false,
|
||||||
@ -100,8 +99,6 @@ const states = reactive<{
|
|||||||
});
|
});
|
||||||
states.isTable = TableChartTypes.includes(states.graph.type);
|
states.isTable = TableChartTypes.includes(states.graph.type);
|
||||||
|
|
||||||
const params = useRoute().params;
|
|
||||||
|
|
||||||
setMetricType();
|
setMetricType();
|
||||||
|
|
||||||
async function setMetricType() {
|
async function setMetricType() {
|
||||||
@ -111,9 +108,9 @@ async function setMetricType() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
states.metricList = (json.data.metrics || []).filter(
|
states.metricList = (json.data.metrics || []).filter(
|
||||||
(d: { catalog: string }) =>
|
(d: { catalog: string }) => entity === (MetricCatalog as any)[d.catalog]
|
||||||
String(params.entity).toUpperCase() === d.catalog
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const metrics: any = states.metricList.filter(
|
const metrics: any = states.metricList.filter(
|
||||||
(d: { value: string; type: string }) => {
|
(d: { value: string; type: string }) => {
|
||||||
const metric = states.metrics.filter((m: string) => m === d.value)[0];
|
const metric = states.metrics.filter((m: string) => m === d.value)[0];
|
||||||
|
@ -62,9 +62,8 @@ import { useDashboardStore } from "@/store/modules/dashboard";
|
|||||||
import { useSelectorStore } from "@/store/modules/selectors";
|
import { useSelectorStore } from "@/store/modules/selectors";
|
||||||
import { useAppStoreWithOut } from "@/store/modules/app";
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
import graphs from "../graphs";
|
import graphs from "../graphs";
|
||||||
import { ElMessage } from "element-plus";
|
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useQueryProcessor } from "@/hooks/useProcessor";
|
import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor";
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
data: {
|
data: {
|
||||||
@ -80,36 +79,30 @@ export default defineComponent({
|
|||||||
setup(props) {
|
setup(props) {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const loading = ref<boolean>(false);
|
const loading = ref<boolean>(false);
|
||||||
const state = reactive<{ source: any }>({
|
const state = reactive<{ source: { [key: string]: unknown } }>({
|
||||||
source: {},
|
source: {},
|
||||||
});
|
});
|
||||||
const { data } = toRefs(props);
|
const { data } = toRefs(props);
|
||||||
const appStore = useAppStoreWithOut();
|
const appStore = useAppStoreWithOut();
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
const selectorStore = useSelectorStore();
|
const selectorStore = useSelectorStore();
|
||||||
|
|
||||||
queryMetrics();
|
queryMetrics();
|
||||||
async function queryMetrics() {
|
async function queryMetrics() {
|
||||||
loading.value = true;
|
|
||||||
const params = useQueryProcessor(
|
const params = useQueryProcessor(
|
||||||
props.data,
|
props.data,
|
||||||
selectorStore,
|
selectorStore,
|
||||||
dashboardStore,
|
dashboardStore,
|
||||||
appStore.durationTime
|
appStore.durationTime
|
||||||
);
|
);
|
||||||
|
if (!params) {
|
||||||
|
state.source = {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loading.value = true;
|
||||||
const json = await dashboardStore.fetchMetricValue(params);
|
const json = await dashboardStore.fetchMetricValue(params);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
if (!json) {
|
state.source = useSourceProcessor(json, props.data);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (json.error) {
|
|
||||||
ElMessage.error(json.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const keys = Object.keys(json.data);
|
|
||||||
keys.forEach((key: string, index) => {
|
|
||||||
const m = props.data.metrics[index];
|
|
||||||
state.source[m] = json.data[key].values.values.map((d: any) => d.value);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeWidget() {
|
function removeWidget() {
|
||||||
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const PodsChartTypes = ["EndpointList", "InstanceList"];
|
export const PodsChartTypes = ["EndpointList", "InstanceList"];
|
||||||
|
|
||||||
export const TableChartTypes = ["EndpointList", "InstanceList", "ServiceList"];
|
export const TableChartTypes = ["EndpointList", "InstanceList", "ServiceList"];
|
||||||
@ -137,7 +138,15 @@ export const ReadValueChartType = [
|
|||||||
{ value: "ChartSlow", label: "Slow Chart" },
|
{ value: "ChartSlow", label: "Slow Chart" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export const MaxItemNum = 10;
|
export enum MetricCatalog {
|
||||||
|
SERVICE = "Service",
|
||||||
|
SERVICE_INSTANCE = "ServiceInstance",
|
||||||
|
ENDPOINT = "Endpoint",
|
||||||
|
ALL = "All",
|
||||||
|
SERVICE_RELATION = "ServiceRelation",
|
||||||
|
SERVICE_INSTANCE_RELATION = "ServiceInstanceRelation",
|
||||||
|
ENDPOINT_RELATION = "EndpointRelation",
|
||||||
|
}
|
||||||
|
|
||||||
export enum MetricsName {
|
export enum MetricsName {
|
||||||
SERVICE_RESP_TIME = "service_resp_time",
|
SERVICE_RESP_TIME = "service_resp_time",
|
||||||
|
Loading…
Reference in New Issue
Block a user