(ctx context.Context, projectName string, services []string)
| 27 | ) |
| 28 | |
| 29 | func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { |
| 30 | projectName = strings.ToLower(projectName) |
| 31 | var containers Containers |
| 32 | containers, err := s.getContainers(ctx, projectName, oneOffInclude, false) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | if len(services) > 0 { |
| 37 | containers = containers.filter(isService(services...)) |
| 38 | } |
| 39 | summary := make([]api.ContainerProcSummary, len(containers)) |
| 40 | eg, ctx := errgroup.WithContext(ctx) |
| 41 | for i, ctr := range containers { |
| 42 | eg.Go(func() error { |
| 43 | topContent, err := s.apiClient().ContainerTop(ctx, ctr.ID, client.ContainerTopOptions{ |
| 44 | Arguments: []string{}, |
| 45 | }) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | name := getCanonicalContainerName(ctr) |
| 50 | s := api.ContainerProcSummary{ |
| 51 | ID: ctr.ID, |
| 52 | Name: name, |
| 53 | Processes: topContent.Processes, |
| 54 | Titles: topContent.Titles, |
| 55 | Service: name, |
| 56 | } |
| 57 | if service, exists := ctr.Labels[api.ServiceLabel]; exists { |
| 58 | s.Service = service |
| 59 | } |
| 60 | if replica, exists := ctr.Labels[api.ContainerNumberLabel]; exists { |
| 61 | s.Replica = replica |
| 62 | } |
| 63 | summary[i] = s |
| 64 | return nil |
| 65 | }) |
| 66 | } |
| 67 | return summary, eg.Wait() |
| 68 | } |
nothing calls this directly
no test coverage detected