MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / statisticOnApi

Method statisticOnApi

module/monitor/iml.go:789–861  ·  view source on GitHub ↗
(ctx context.Context, clusterId string, apiId string, groupBy string, input *monitor_dto.StatisticInput)

Source from the content-addressed store, hash-verified

787}
788
789func (i *imlMonitorStatisticModule) statisticOnApi(ctx context.Context, clusterId string, apiId string, groupBy string, input *monitor_dto.StatisticInput) ([]*monitor_dto.ServiceStatisticBasicItem, error) {
790 _, err := i.clusterService.Get(ctx, clusterId)
791 if err != nil {
792 return nil, err
793 }
794 var services []*service.Service
795 switch groupBy {
796 case "app":
797 services, err = i.serviceService.AppList(ctx)
798 if err != nil {
799 return nil, err
800 }
801 services = append(services, &service.Service{
802 Id: "apipark-global",
803 Name: "System Consumer",
804 })
805
806 case "provider":
807 services, err = i.serviceService.ServiceList(ctx)
808 if err != nil {
809 return nil, err
810 }
811
812 default:
813 return nil, errors.New("invalid group by")
814 }
815
816 wheres, err := i.genCommonWheres(ctx, clusterId)
817 if err != nil {
818 return nil, err
819 }
820 wheres = append(wheres, monitor.MonWhereItem{
821 Key: "api",
822 Operation: "=",
823 Values: []string{apiId},
824 })
825
826 statisticMap, err := i.statistics(ctx, clusterId, groupBy, formatTimeByMinute(input.Start), formatTimeByMinute(input.End), wheres, 0)
827 if err != nil {
828 return nil, err
829 }
830
831 result := make([]*monitor_dto.ServiceStatisticBasicItem, 0, len(statisticMap))
832 for _, item := range services {
833
834 statisticItem := &monitor_dto.ServiceStatisticBasicItem{
835 Id: item.Id,
836 Name: item.Name,
837 MonCommonData: new(monitor_dto.MonCommonData),
838 }
839 if val, ok := statisticMap[item.Id]; ok {
840 statisticItem.MonCommonData = monitor_dto.ToMonCommonData(val)
841 delete(statisticMap, item.Id)
842 }
843 result = append(result, statisticItem)
844 }
845 for key, item := range statisticMap {
846 statisticItem := &monitor_dto.ServiceStatisticBasicItem{

Callers 2

Calls 6

genCommonWheresMethod · 0.95
statisticsMethod · 0.95
formatTimeByMinuteFunction · 0.70
GetMethod · 0.65
AppListMethod · 0.65
ServiceListMethod · 0.65

Tested by

no test coverage detected