(ctx context.Context, clusterId string, groupBy string, input *monitor_dto.CommonInput, limit int)
| 1083 | } |
| 1084 | |
| 1085 | func (i *imlMonitorStatisticModule) topProjectStatistics(ctx context.Context, clusterId string, groupBy string, input *monitor_dto.CommonInput, limit int) ([]*monitor_dto.ServiceStatisticItem, error) { |
| 1086 | wheres, err := i.genCommonWheres(ctx, clusterId) |
| 1087 | if err != nil { |
| 1088 | return nil, err |
| 1089 | } |
| 1090 | statisticMap, err := i.statistics(ctx, clusterId, groupBy, formatTimeByMinute(input.Start), formatTimeByMinute(input.End), wheres, limit) |
| 1091 | if err != nil { |
| 1092 | return nil, err |
| 1093 | } |
| 1094 | var projects []*service.Service |
| 1095 | switch groupBy { |
| 1096 | case "app": |
| 1097 | projects, err = i.serviceService.AppList(ctx) |
| 1098 | case "provider": |
| 1099 | projects, err = i.serviceService.ServiceList(ctx) |
| 1100 | default: |
| 1101 | return nil, errors.New("invalid group by") |
| 1102 | } |
| 1103 | if err != nil { |
| 1104 | return nil, err |
| 1105 | } |
| 1106 | projectMap := utils.SliceToMap(projects, func(t *service.Service) string { |
| 1107 | return t.Id |
| 1108 | }) |
| 1109 | |
| 1110 | result := make([]*monitor_dto.ServiceStatisticItem, 0, len(statisticMap)) |
| 1111 | for key, item := range statisticMap { |
| 1112 | statisticItem := &monitor_dto.ServiceStatisticItem{ |
| 1113 | ServiceStatisticBasicItem: &monitor_dto.ServiceStatisticBasicItem{ |
| 1114 | Id: key, |
| 1115 | MonCommonData: monitor_dto.ToMonCommonData(item), |
| 1116 | }, |
| 1117 | } |
| 1118 | if a, ok := projectMap[item.ID]; ok { |
| 1119 | statisticItem.Name = a.Name |
| 1120 | } else { |
| 1121 | statisticItem.IsRed = true |
| 1122 | if key == "-" { |
| 1123 | statisticItem.Name = "无系统" |
| 1124 | } else { |
| 1125 | statisticItem.Name = fmt.Sprintf("未知系统-%s", key) |
| 1126 | } |
| 1127 | } |
| 1128 | result = append(result, statisticItem) |
| 1129 | } |
| 1130 | sort.Slice(result, func(i, j int) bool { |
| 1131 | return result[i].RequestTotal > result[j].RequestTotal |
| 1132 | }) |
| 1133 | return result, nil |
| 1134 | } |
| 1135 | func (i *imlMonitorStatisticModule) getExecutor(ctx context.Context, clusterId string) (driver.IExecutor, error) { |
| 1136 | info, err := i.monitorService.GetByCluster(ctx, clusterId) |
| 1137 | if err != nil { |
no test coverage detected