(ctx context.Context, input *monitor_dto.StatisticInput)
| 481 | } |
| 482 | |
| 483 | func (i *imlMonitorStatisticModule) ApiStatistics(ctx context.Context, input *monitor_dto.StatisticInput) ([]*monitor_dto.ApiStatisticBasicItem, error) { |
| 484 | clusterId := cluster.DefaultClusterID |
| 485 | _, err := i.clusterService.Get(ctx, clusterId) |
| 486 | if err != nil { |
| 487 | return nil, err |
| 488 | } |
| 489 | wheres, err := i.genCommonWheres(ctx, clusterId) |
| 490 | if err != nil { |
| 491 | return nil, err |
| 492 | } |
| 493 | |
| 494 | wm := make(map[string]interface{}) |
| 495 | if len(input.Apis) > 0 { |
| 496 | wm["uuid"] = input.Apis |
| 497 | wheres = append(wheres, monitor.MonWhereItem{ |
| 498 | Key: "api", |
| 499 | Operation: "in", |
| 500 | Values: input.Apis, |
| 501 | }) |
| 502 | } |
| 503 | if len(input.Services) > 0 { |
| 504 | wm["service"] = input.Services |
| 505 | wheres = append(wheres, monitor.MonWhereItem{ |
| 506 | Key: "project", |
| 507 | Operation: "in", |
| 508 | Values: input.Services, |
| 509 | }) |
| 510 | } |
| 511 | // 查询符合条件的API |
| 512 | apis, err := i.apiService.Search(ctx, input.Path, wm) |
| 513 | if err != nil { |
| 514 | return nil, err |
| 515 | } |
| 516 | if len(apis) < 1 { |
| 517 | // 没有符合条件的API |
| 518 | return make([]*monitor_dto.ApiStatisticBasicItem, 0), nil |
| 519 | } |
| 520 | apiIds := utils.SliceToSlice(apis, func(t *api.API) string { |
| 521 | return t.UUID |
| 522 | }) |
| 523 | |
| 524 | apiInfos, err := i.apiService.ListInfo(ctx, apiIds...) |
| 525 | if err != nil { |
| 526 | return nil, err |
| 527 | } |
| 528 | return i.apiStatistics(ctx, clusterId, apiInfos, formatTimeByMinute(input.Start), formatTimeByMinute(input.End), wheres, 0) |
| 529 | } |
| 530 | |
| 531 | func (i *imlMonitorStatisticModule) apiStatistics(ctx context.Context, clusterId string, apiInfos []*api.Info, start time.Time, end time.Time, wheres []monitor.MonWhereItem, limit int) ([]*monitor_dto.ApiStatisticBasicItem, error) { |
| 532 | statisticMap, err := i.statistics(ctx, clusterId, "api", start, end, wheres, limit) |
nothing calls this directly
no test coverage detected