feat: update expression metrics

This commit is contained in:
Fine 2023-06-03 11:52:47 +08:00
parent e2670b872f
commit 94dc2f3642
6 changed files with 53 additions and 11 deletions

View File

@ -15,16 +15,24 @@
* limitations under the License.
*/
import { MetricQueryTypes, Calculations } from "./data";
import { ExpressionResultType } from "@/views/dashboard/data";
export function useListConfig(config: Indexable, index: string) {
const i = Number(index);
const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg];
const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation;
const isLinear =
[MetricQueryTypes.ReadMetricsValues, MetricQueryTypes.ReadLabeledMetricsValues].includes(config.metricTypes[i]) &&
!types.includes(calculation);
[
MetricQueryTypes.ReadMetricsValues,
MetricQueryTypes.ReadLabeledMetricsValues,
ExpressionResultType.TIME_SERIES_VALUES,
].includes(config.metricTypes[i]) && !types.includes(calculation);
const isAvg =
[MetricQueryTypes.ReadMetricsValues, MetricQueryTypes.ReadLabeledMetricsValues].includes(config.metricTypes[i]) &&
types.includes(calculation);
[
MetricQueryTypes.ReadMetricsValues,
MetricQueryTypes.ReadLabeledMetricsValues,
ExpressionResultType.TIME_SERIES_VALUES,
].includes(config.metricTypes[i]) && types.includes(calculation);
return {
isLinear,
isAvg,

View File

@ -22,6 +22,7 @@ import { useSelectorStore } from "@/store/modules/selectors";
import { useAppStoreWithOut } from "@/store/modules/app";
import type { Instance, Endpoint, Service } from "@/types/selector";
import type { MetricConfigOpt } from "@/types/dashboard";
import type { E } from "vitest/dist/types-c441ef31";
export function useQueryProcessor(config: Indexable) {
if (!(config.metrics && config.metrics[0])) {
@ -277,7 +278,7 @@ export function usePodsSource(
const names: string[] = [];
const metricConfigArr: MetricConfigOpt[] = [];
const metricTypesArr: string[] = [];
const data = pods.map((d: Instance & Indexable, idx: number) => {
const data = pods.map((d: any, idx: number) => {
config.metrics.map((name: string, index: number) => {
const c: any = (config.metricConfig && config.metricConfig[index]) || {};
const key = name + idx + index;

View File

@ -21,6 +21,7 @@ export type Service = {
layers?: string[];
normal?: boolean;
group?: string;
merge?: string;
};
export type Instance = {
@ -30,12 +31,14 @@ export type Instance = {
instanceUUID?: string;
attributes?: { name: string; value: string }[];
id?: string;
merge?: boolean;
};
export type Endpoint = {
id?: string;
label: string;
value: string;
merge?: string;
};
export type Service = {

View File

@ -120,10 +120,18 @@ limitations under the License. -->
endpoints.value = resp.data.pods || [];
queryEndpointMetrics(endpoints.value);
}
async function queryEndpointMetrics(currentPods: Endpoint[]) {
if (!currentPods.length) {
async function queryEndpointMetrics(arr: Endpoint[]) {
if (!arr.length) {
return;
}
const currentPods = arr.map((d: Endpoint) => {
return {
id: d.id,
value: d.value,
label: d.label,
merge: d.merge,
};
});
if (props.config.metricMode === "Expression") {
queryEndpointExpressions(currentPods);
return;

View File

@ -150,10 +150,21 @@ limitations under the License. -->
queryInstanceMetrics(instances.value);
}
async function queryInstanceMetrics(currentInstances: Instance[]) {
if (!currentInstances.length) {
async function queryInstanceMetrics(arr: Instance[]) {
if (!arr.length) {
return;
}
const currentInstances = arr.map((d: Instance) => {
return {
id: d.id,
value: d.value,
label: d.label,
merge: d.merge,
language: d.language,
instanceUUID: d.instanceUUID,
attributes: d.attributes,
};
});
if (props.config.metricMode === "Expression") {
queryInstanceExpressions(currentInstances);
return;

View File

@ -191,10 +191,21 @@ limitations under the License. -->
router.push(path);
}
async function queryServiceMetrics(currentServices: Service[]) {
if (!currentServices.length) {
async function queryServiceMetrics(arr: Service[]) {
if (!arr.length) {
return;
}
const currentServices = arr.map((d: Service) => {
return {
id: d.id,
value: d.value,
label: d.label,
layers: d.layers,
group: d.group,
normal: d.normal,
merge: d.merge,
};
});
if (props.config.metricMode === "Expression") {
queryServiceExpressions(currentServices);
return;