1
0
mirror of https://github.com/docker/compose.git synced 2025-04-08 17:05:13 +02:00

review: move Summary/Replica collection from cmd/ to pkg/

Signed-off-by: Dominik Menke <dom@digineo.de>
This commit is contained in:
Dominik Menke 2025-03-12 19:25:43 +01:00 committed by Nicolas De loof
parent 62e832eb50
commit f70209cf15
4 changed files with 18 additions and 19 deletions
cmd/compose
pkg
api
compose

@ -80,24 +80,16 @@ func collectTop(containers []api.ContainerProcSummary) (topHeader, []topEntries)
for _, container := range containers {
for _, proc := range container.Processes {
svc := container.Name
if tmp, ok := container.Labels[api.ServiceLabel]; ok {
svc = tmp
entry := topEntries{
"SERVICE": container.Service,
"#": container.Replica,
}
replica := "-"
if tmp, ok := container.Labels[api.ContainerNumberLabel]; ok {
replica = tmp
}
entry := topEntries{"SERVICE": svc, "#": replica}
for i, title := range container.Titles {
if _, exists := header[title]; !exists {
header[title] = len(header)
}
entry[title] = proc[i]
}
entries = append(entries, entry)
}
}

@ -213,10 +213,8 @@ func TestRunTopCore(t *testing.T) {
Name: "not used",
Titles: tc.titles,
Processes: tc.procs,
Labels: map[string]string{
api.ServiceLabel: tc.name,
api.ContainerNumberLabel: "1",
},
Service: tc.name,
Replica: "1",
}
all = append(all, summary)

@ -523,7 +523,8 @@ type ContainerProcSummary struct {
Name string
Processes [][]string
Titles []string
Labels map[string]string
Service string
Replica string
}
// ImageSummary holds container image description

@ -42,13 +42,21 @@ func (s *composeService) Top(ctx context.Context, projectName string, services [
if err != nil {
return err
}
summary[i] = api.ContainerProcSummary{
name := getCanonicalContainerName(ctr)
s := api.ContainerProcSummary{
ID: ctr.ID,
Name: getCanonicalContainerName(ctr),
Name: name,
Processes: topContent.Processes,
Titles: topContent.Titles,
Labels: container.Labels,
Service: name,
}
if service, exists := ctr.Labels[api.ServiceLabel]; exists {
s.Service = service
}
if replica, exists := ctr.Labels[api.ContainerNumberLabel]; exists {
s.Replica = replica
}
summary[i] = s
return nil
})
}