(ctx context.Context, serviceId string, start int64, end int64, limit int, apiKind string)
| 385 | } |
| 386 | |
| 387 | func (i *imlMonitorStatisticModule) Top(ctx context.Context, serviceId string, start int64, end int64, limit int, apiKind string) ([]*monitor_dto.TopN, []*monitor_dto.TopN, error) { |
| 388 | wheres, err := i.genOverviewWhere(ctx, serviceId, []string{apiKind}) |
| 389 | if err != nil { |
| 390 | return nil, nil, err |
| 391 | } |
| 392 | |
| 393 | executor, err := i.getExecutor(ctx, cluster.DefaultClusterID) |
| 394 | if err != nil { |
| 395 | return nil, nil, err |
| 396 | } |
| 397 | |
| 398 | errChan := make(chan error, 2) |
| 399 | var wg sync.WaitGroup |
| 400 | apisResult, consumersResult := make([]*monitor_dto.TopN, 0), make([]*monitor_dto.TopN, 0) |
| 401 | var errs []error |
| 402 | |
| 403 | wg.Add(2) |
| 404 | |
| 405 | go func() { |
| 406 | defer wg.Done() |
| 407 | result, err := executor.TopN(ctx, formatTimeByMinute(start), formatTimeByMinute(end), limit, "api", wheres) |
| 408 | if err != nil { |
| 409 | errChan <- err |
| 410 | return |
| 411 | } |
| 412 | if len(result) < 1 { |
| 413 | return |
| 414 | } |
| 415 | apiIds := utils.SliceToSlice(result, func(t *monitor.TopN) string { |
| 416 | return t.Key |
| 417 | }) |
| 418 | apis, err := i.apiService.ListInfo(ctx, apiIds...) |
| 419 | if err != nil { |
| 420 | errChan <- err |
| 421 | return |
| 422 | } |
| 423 | apiMap := utils.SliceToMap(apis, func(t *api.Info) string { |
| 424 | return t.UUID |
| 425 | }) |
| 426 | for _, item := range result { |
| 427 | if v, ok := apiMap[item.Key]; ok { |
| 428 | apisResult = append(apisResult, generateTopN(v.UUID, v.Name, item, apiKind)) |
| 429 | } |
| 430 | } |
| 431 | }() |
| 432 | |
| 433 | go func() { |
| 434 | defer wg.Done() |
| 435 | result, err := executor.TopN(ctx, formatTimeByMinute(start), formatTimeByMinute(end), limit, "app", wheres) |
| 436 | if err != nil { |
| 437 | errChan <- err |
| 438 | return |
| 439 | } |
| 440 | if len(result) < 1 { |
| 441 | return |
| 442 | } |
| 443 | appIds := utils.SliceToSlice(result, func(t *monitor.TopN) string { |
| 444 | return t.Key |
nothing calls this directly
no test coverage detected