Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: metric related bugfix #194

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Charts/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ function LineChart(props: IProps, ref) {
max = max + 5;
min = min < 0 ? min - 5 : 0;
} else {
min = 0;
min = Math.min(min, 0);
}

yMin.current = min;
yMax.current = max;
const tickInterval = Math.round((max - min) / 5);
return {
min: yMin.current,
min: yMin.current < 0 ? yMin.current - tickInterval : yMin.current,
max: yMax.current + tickInterval,
tickInterval,
}
Expand Down
6 changes: 1 addition & 5 deletions src/components/Service/ServiceCardEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ function ServiceCardEdit(props: IProps) {

const curServiceMetricItems = useMemo<IServiceMetricItem[]>(() => serviceMetric[editType], [serviceMetric, editType]);

const handleUpdateMetricType = (value: string) => {
const metric = curServiceMetricItems.find(
item => item.metric === value,
);
const handleUpdateMetricType = (_value: string) => {
formRef.current.setFieldsValue({
aggregation: metric?.aggregations[0],
space: '',
});
};
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MachineDashboard/Cards/CPUCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { VALUE_TYPE } from '@/utils/promQL';
import { MetricScene } from '@/utils/interface';

const mapState = (state: IRootState) => {
const { cpuStat, metricsFilterValues } = state.machine;
const { cpuStat, metricsFilterValues, instanceList } = state.machine;
const { aliasConfig } = state.app;
return {
data: getDataByType({
data: cpuStat,
type: metricsFilterValues.instanceList,
nameObj: getMetricsUniqName(MetricScene.CPU),
aliasConfig,
instanceList
}),
valueType: VALUE_TYPE.percentage,
loading: false,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MachineDashboard/Cards/LoadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { VALUE_TYPE } from '@/utils/promQL';
import { MetricScene } from '@/utils/interface';

const mapState = (state: IRootState) => {
const { loadStat, metricsFilterValues } = state.machine;
const { loadStat, metricsFilterValues, instanceList } = state.machine;
const { aliasConfig } = state.app;
return {
data: getDataByType({
data: loadStat,
type: metricsFilterValues.instanceList,
nameObj: getMetricsUniqName(MetricScene.LOAD),
aliasConfig,
instanceList,
}),
valueType: VALUE_TYPE.number,
loading: false,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MachineDashboard/Cards/MemoryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { VALUE_TYPE } from '@/utils/promQL';
import { MetricScene } from '@/utils/interface';

const mapState = (state: IRootState) => {
const { memoryStat, memorySizeStat, metricsFilterValues } = state.machine;
const { memoryStat, memorySizeStat, metricsFilterValues, instanceList } = state.machine;
const { aliasConfig } = state.app;
return {
data: getDataByType({
data: memoryStat,
type: metricsFilterValues.instanceList,
nameObj: getMetricsUniqName(MetricScene.MEMORY),
aliasConfig,
instanceList,
}),
sizes: memorySizeStat,
valueType: VALUE_TYPE.percentage,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MachineDashboard/Cards/NetworkIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { VALUE_TYPE } from '@/utils/promQL';
import { MetricScene } from '@/utils/interface';

const mapState = (state: IRootState) => {
const { networkInStat, metricsFilterValues } = state.machine;
const { networkInStat, metricsFilterValues, instanceList } = state.machine;
const { aliasConfig } = state.app;
return {
data: getDataByType({
data: networkInStat,
type: metricsFilterValues.instanceList,
nameObj: getMetricsUniqName(MetricScene.NETWORK),
aliasConfig,
instanceList,
}),
valueType: VALUE_TYPE.byteSecondNet,
loading: false,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MachineDashboard/Cards/NetworkOut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { getDataByType, getMetricsUniqName } from '@/utils/dashboard';
import { MetricScene } from '@/utils/interface';

const mapState = (state: IRootState) => {
const { networkOutStat, metricsFilterValues } = state.machine;
const { networkOutStat, metricsFilterValues, instanceList } = state.machine;
const { aliasConfig } = state.app;
return {
data: getDataByType({
data: networkOutStat,
type: metricsFilterValues.instanceList,
nameObj: getMetricsUniqName(MetricScene.NETWORK),
aliasConfig,
instanceList,
}),
valueType: VALUE_TYPE.byteSecondNet,
loading: false,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/MachineDashboard/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ function Detail(props: IProps) {
type: metricsFilterValues.instanceList,
nameObj: dataTypeObj,
aliasConfig,
instanceList: instances,
}) :
getDataByType({
data: dataSources[i] || [],
type: metricsFilterValues.instanceList,
nameObj: dataTypeObj,
aliasConfig,
instanceList: instances,
});
const values = data.map(d => d.value) as number[];
const maxNum = values.length > 0 ? Math.floor(Math.max(...values) * 100) / 100 : undefined;
Expand Down
30 changes: 8 additions & 22 deletions src/pages/MetricDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ const mapState = (state: IRootState) => ({
});

const mapDispatch: any = (dispatch: IDispatch) => ({
// asyncUpdateBaseLine: (key, value) =>
// dispatch.setting.update({
// [key]: value,
// }),
updateMetricsFiltervalues: dispatch.machine.updateMetricsFiltervalues,
updateServiceMetricsFiltervalues: dispatch.service.updateMetricsFiltervalues,
asyncFetchMachineMetricsData: dispatch.machine.asyncGetMetricsData,
Expand Down Expand Up @@ -186,18 +182,21 @@ function MetricDetail(props: Props) {

const updateChart = () => {
const metricScene = getMetricSecene(metricType);
const instanceList = isServiceMetric(metricType) ? serviceInstanceList : instances;
const data = metricType === MetricTypeName.Disk ?
getDiskData({
data: dataSource || [],
type: curMetricsFilterValues.instanceList,
nameObj: getMetricsUniqName(metricScene),
aliasConfig,
instanceList
}) :
getDataByType({
data: dataSource || [],
type: curMetricsFilterValues.instanceList,
nameObj: getMetricsUniqName(metricScene),
aliasConfig,
instanceList,
});
const values = data.map(d => d.value) as number[];
const maxNum = values.length > 0 ? Math.floor(Math.max(...values) * 100) / 100 : undefined;
Expand All @@ -212,32 +211,19 @@ function MetricDetail(props: Props) {
}).changeData(data);
};

const metricTypeMap = useMemo(() => {
const map = {};
if (metricOption && isServiceMetric(metricType)) {
metricOption.aggregations.forEach(type => {
if (!map[type]) {
map[type] = [metricOption];
} else {
map[type].push(metricOption)
}
})
}
return map;
}, [metricType, metricOption])

const getData = async () => {
const [startTimestamps, endTimestamps] = calcTimeRange(curMetricsFilterValues.timeRange);
if (isServiceMetric(metricType)) {
const { period, space, metricType: aggregration } = curMetricsFilterValues;
const item = metricTypeMap[aggregration]?.find(metricItem => metricItem.metric === metricChart.metric.metric);
if (item) {
const { space } = curMetricsFilterValues;
if (metricChart.metric.metric.length) {
const aggregation = metricChart.metric.aggregations[0];
asyncFetchServiceMetricsData({
query: getQueryByMetricType(item, aggregration, period),
query: getQueryByMetricType(metricChart.metric, aggregation, '5'),
start: startTimestamps,
end: endTimestamps,
space: metricType === MetricTypeName.Graphd ? space : undefined,
clusterID: cluster?.id,
aggregation,
}).then(res => {
setDataSource(res);
});
Expand Down
1 change: 1 addition & 0 deletions src/pages/ServiceDashboard/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function ServiceDetail(props: IProps) {
type: instanceList,
nameObj: getMetricsUniqName(MetricScene.SERVICE),
aliasConfig,
instanceList: props.instanceList,
});
const realRange = data.length>0?(data[data.length-1].time - data[0].time):0;
const tickInterval = getTickIntervalByGap(Math.floor(realRange / 10)); // 10 ticks max
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const mapState = (state: IRootState) => ({
cluster: (state as any).cluster?.cluster,
metricsFilterValues: state.service.metricsFilterValues,
serviceMetric: state.serviceMetric,
instances: state.service.instanceList,
});

interface IProps
Expand All @@ -35,7 +36,7 @@ interface IProps

function CustomServiceQueryPanel(props: IProps) {

const { config, cluster, asyncGetMetricsData, onConfigPanel, aliasConfig, metricsFilterValues, isHidePeriod, serviceMetric, serviceType } = props;
const { config, cluster, asyncGetMetricsData, onConfigPanel, aliasConfig, metricsFilterValues, isHidePeriod, serviceMetric, serviceType, instances } = props;

const [data, setData] = useState<any[]>([])

Expand Down Expand Up @@ -117,6 +118,7 @@ function CustomServiceQueryPanel(props: IProps) {
type: metricsFilterValues.instanceList,
nameObj: getMetricsUniqName(MetricScene.SERVICE),
aliasConfig,
instanceList: instances
})}
serviceType={serviceType}
loading={false}
Expand Down
19 changes: 15 additions & 4 deletions src/utils/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ export const getDataByType = (payload: {
showName: (name: string) => string;
};
aliasConfig?: any;
instanceList?: string[];
}) => {
const { nameObj, type, data, aliasConfig } = payload;
const { nameObj, data, aliasConfig, instanceList } = payload;
let { type } = payload;
const { name, showName } = nameObj;
const res = [] as ILineChartMetric[];
data.forEach(instance => {
Expand All @@ -170,7 +172,11 @@ export const getDataByType = (payload: {
if (typeof type === 'string') {
shouldPush = (type === 'all' && _name !== 'total') || _name === type;
} else if (Array.isArray(type)) {
shouldPush = (type.includes('all') && _name !== 'total') || !!type.find(t => _name.includes(t))
if (type.includes('all')) {
shouldPush= instanceList ? instanceList.some(instance => _name.includes(instance)) : true;
} else {
shouldPush = !!type.find(t => _name.includes(t))
}
}
if (shouldPush) {
res.push({
Expand All @@ -192,8 +198,9 @@ export let getDiskData = (payload: {
name: string;
showName: (name: string) => string;
};
instanceList?: string[];
}) => {
const { type, data, nameObj } = payload;
const { type, data, nameObj, instanceList } = payload;
const { name, showName } = nameObj;
const res = [] as ILineChartMetric[];
data.forEach(instance => {
Expand All @@ -204,7 +211,11 @@ export let getDiskData = (payload: {
if (typeof type === 'string') {
shouldPush = (type === 'all' && _name !== 'total') || _name === type;
} else if (Array.isArray(type)) {
shouldPush = (type.includes('all') && _name !== 'total') || !!type.find(t => _name.includes(t))
if (type.includes('all')) {
shouldPush= instanceList ? instanceList.some(instance => _name.includes(instance)) : true;
} else {
shouldPush = !!type.find(t => _name.includes(t))
}
}
if (shouldPush) {
res.push({
Expand Down