Skip to content

Commit

Permalink
fix: chart
Browse files Browse the repository at this point in the history
fix: bug

fix: add metric request flag
  • Loading branch information
mizy committed Mar 20, 2023
1 parent f1e45eb commit eac001e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 76 deletions.
60 changes: 10 additions & 50 deletions src/store/models/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function MachineModelWrapper(service,) {
}
return {
...state,
metricsFilterValues
metricsFilterValues
}
}
},
Expand All @@ -77,23 +77,12 @@ export function MachineModelWrapper(service,) {
end,
step,
})) as any;
let result:any = [];
let result: any = [];
if (code === 0) {
if (NEED_ADD_SUM_QUERYS.includes(metric)) {
result = (await this.asyncGetSumDataByRange({
clusterID,
query: PROMQL(clusterID)[metric],
start: start,
end: end,
step,
data: data.result,
})) as any;
} else {
result = data.result;
}
result = data.result;
}
if (isCommunityVersion()) {
const instanceList = result.map(item => item.metric.instance).filter(instance => instance !== 'total' );
const instanceList = result.map(item => item.metric.instance).filter(instance => instance !== 'total');
this.updateInstanceList(instanceList);
}
return result;
Expand All @@ -114,7 +103,7 @@ export function MachineModelWrapper(service,) {
});
return cpuStat;
},

async asyncGetMemoryStatByRange(payload: {
start: number;
end: number;
Expand All @@ -130,7 +119,7 @@ export function MachineModelWrapper(service,) {
});
return memoryStat;
},

async asyncGetMemorySizeStat(clusterID?: string) {
const { code, data } = (await service.execPromQL({
clusterID,
Expand All @@ -145,7 +134,7 @@ export function MachineModelWrapper(service,) {
});
return memorySizeStat;
},

async asyncGetDiskStatByRange(payload: {
start: number;
end: number;
Expand All @@ -161,7 +150,7 @@ export function MachineModelWrapper(service,) {
});
return diskStat;
},

async asyncGetDiskSizeStat(clusterID?: string) {
const { code, data } = await service.execPromQL({
clusterID,
Expand All @@ -176,7 +165,7 @@ export function MachineModelWrapper(service,) {
});
return diskSizeStat;
},

async asyncGetLoadByRange(payload: {
start: number;
end: number;
Expand All @@ -192,7 +181,7 @@ export function MachineModelWrapper(service,) {
});
return loadStat;
},

async asyncGetNetworkStatByRange(payload: {
start: number;
end: number;
Expand Down Expand Up @@ -220,35 +209,6 @@ export function MachineModelWrapper(service,) {
}
return networkStat;
},

async asyncGetSumDataByRange(payload: {
clusterID?: string;
query: string;
start: number;
end: number;
step: number;
data: any[];
}) {
const { query, start, end, step, data, clusterID } = payload;
const { code, data: dataStat } = (await service.execPromQLByRange({
clusterID,
query: `sum(${query})`,
start,
end,
step,
})) as any;
if (code === 0 && dataStat.result.length !== 0) {
const sumData = {
metric: {
instance: 'total',
job: 'total',
},
} as any;
sumData.values = dataStat.result[0].values;
return data.concat(sumData);
}
return data;
},

updateMetricsFiltervalues(values: MetricsPanelValue) {
this.updateMetricsFilterValues({
Expand Down
31 changes: 13 additions & 18 deletions src/store/models/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import { getClusterPrefix, diskPararms } from '@/utils/promQL';
import { formatVersion } from '@/utils/dashboard';
import { ServiceName } from '@/utils/interface';

interface IState {
graphd: any[];
metad: any;
storaged: any[];
spaces: string[];
devices: string[]
}

export function MetricModelWrapper(serviceApi) {
return createModel({
state: {
Expand All @@ -25,10 +17,11 @@ export function MetricModelWrapper(serviceApi) {
[ServiceName.StoragedListener]: [],
[ServiceName.Drainer]: [],
spaces: [],
devices: []
devices: [],
ready: false
},
reducers: {
update: (state: IState, payload: any) => ({
update: (state: any, payload: any) => ({
...state,
...payload,
}),
Expand Down Expand Up @@ -57,6 +50,15 @@ export function MetricModelWrapper(serviceApi) {
}
case compare(curVersion, '3.0.0', '>='):
{
const { code, data: metricData } =
(await serviceApi.getMetrics({
clusterID,
'match[]': `{componentType="${componentType}"${componentType === ServiceName.GRAPHD ? `,space=""` : ''},__name__!~"ALERTS.*",__name__!~".*count"${clusterSuffix1}}`,
})) as any;
if (code === 0) {
metricList = metricData;
}

if (componentType === ServiceName.GRAPHD) {
const { code, data } = (await serviceApi.getMetrics({
clusterID,
Expand All @@ -66,14 +68,6 @@ export function MetricModelWrapper(serviceApi) {
spaceMetricList = data;
}
}
const { code, data: metricData } =
(await serviceApi.getMetrics({
clusterID,
'match[]': `{componentType="${componentType}"${componentType === ServiceName.GRAPHD ? `,space=""` : ''},__name__!~"ALERTS.*",__name__!~".*count"${clusterSuffix1}}`,
})) as any;
if (code === 0) {
metricList = metricData;
}
}
break;
default:
Expand All @@ -89,6 +83,7 @@ export function MetricModelWrapper(serviceApi) {
[componentType]: metrics,
});
},

async asyncGetSpaces({ clusterID, start, end }) {
start = start / 1000;
end = end / 1000;
Expand Down
8 changes: 4 additions & 4 deletions src/store/models/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isCommunityVersion, unique } from '@/utils';
import { getClusterPrefix } from '@/utils/promQL';
import { InitMetricsFilterValues } from '@/utils/metric';

interface IState {
interface IServiceState {
panelConfig: IPanelConfig;
instanceList: string[];
metricsFilterValues: ServiceMetricsPanelValue;
Expand All @@ -25,15 +25,15 @@ export function SereviceModelWrapper(serviceApi) {
metricsFilterValues: InitMetricsFilterValues
},
reducers: {
update: (state: IState, payload: any) => ({
update: (state: IServiceState, payload: any) => ({
...state,
...payload,
}),
updateInstanceList: (state: IState, payload: any) => {
updateInstanceList: (state: IServiceState, payload: any) => {
const instanceList = unique(state.instanceList.concat(payload));
return { ...state, instanceList };
},
updateMetricsFilterValues: (state: IState, payload: any) => {
updateMetricsFilterValues: (state: IServiceState, payload: any) => {
const metricsFilterValues = {
...state.metricsFilterValues,
...payload.metricsFilterValues
Expand Down
16 changes: 15 additions & 1 deletion src/utils/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,21 @@ export const getProperByteDesc = (bytes: number) => {
desc: value + unit,
}
}

export const getAutoLatency = (latency: number) => {
if (latency > 60 * 1000 * 1000) {
// min
return `${(latency / 60 / 1000 / 1000).toFixed(2)}min`;
}
if (latency > 1000 * 1000) {
// s
return `${(latency / 1000 / 1000).toFixed(2)}s`;
}
if (latency > 1000) {
// ms
return `${(latency / 1000).toFixed(2)}ms`;
}
return `${latency}μs`;
};
export const getDataByType = (payload: {
data: IStatRangeItem[];
type?: string | string[];
Expand Down
24 changes: 23 additions & 1 deletion src/utils/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'loadsh';

import { VALUE_TYPE } from '@/utils/promQL';
import { INTERVAL_FREQUENCY_LIST, SERVICE_QUERY_PERIOD } from './service';
import { AggregationType, AGGREGATION_OPTIONS, getProperByteDesc, TIME_OPTION_TYPE } from './dashboard';
import { AggregationType, AGGREGATION_OPTIONS, getAutoLatency, getProperByteDesc, TIME_OPTION_TYPE } from './dashboard';
import { IServiceMetricItem, ServiceName } from './interface';
import dayjs from 'dayjs';

Expand Down Expand Up @@ -401,6 +401,28 @@ export const updateChartByValueType = (options, chartInstance) => {
title: tooltipTitle,
});
break;
case VALUE_TYPE.latency:
chartInstance.axis('value', {
label: {
formatter: processNum => {
return getAutoLatency(processNum);
},
},
});
chartInstance.tooltip({
customItems: items =>
items.map(item => {
let value = getAutoLatency(item.value);
return {
...item,
value,
};
}),
showCrosshairs: true,
shared: true,
title: tooltipTitle,
});
break;
default:
}
}
4 changes: 2 additions & 2 deletions src/utils/promQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const enum VALUE_TYPE {
byteSecondNet = 'BYTE_SECOND_NET',
number = 'NUMBER',
numberSecond = 'numberSecond',
status = 'status'
status = 'status',
latency = 'latency'
}

export let SUPPORT_METRICS =
{
cpu: [
Expand Down

0 comments on commit eac001e

Please sign in to comment.