Skip to content

Commit f70209c

Browse files
dmkendeloof
authored andcommitted
review: move Summary/Replica collection from cmd/ to pkg/
Signed-off-by: Dominik Menke <[email protected]>
1 parent 62e832e commit f70209c

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

cmd/compose/top.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,16 @@ func collectTop(containers []api.ContainerProcSummary) (topHeader, []topEntries)
8080

8181
for _, container := range containers {
8282
for _, proc := range container.Processes {
83-
svc := container.Name
84-
if tmp, ok := container.Labels[api.ServiceLabel]; ok {
85-
svc = tmp
83+
entry := topEntries{
84+
"SERVICE": container.Service,
85+
"#": container.Replica,
8686
}
87-
replica := "-"
88-
if tmp, ok := container.Labels[api.ContainerNumberLabel]; ok {
89-
replica = tmp
90-
}
91-
92-
entry := topEntries{"SERVICE": svc, "#": replica}
93-
9487
for i, title := range container.Titles {
9588
if _, exists := header[title]; !exists {
9689
header[title] = len(header)
9790
}
9891
entry[title] = proc[i]
9992
}
100-
10193
entries = append(entries, entry)
10294
}
10395
}

cmd/compose/top_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,8 @@ func TestRunTopCore(t *testing.T) {
213213
Name: "not used",
214214
Titles: tc.titles,
215215
Processes: tc.procs,
216-
Labels: map[string]string{
217-
api.ServiceLabel: tc.name,
218-
api.ContainerNumberLabel: "1",
219-
},
216+
Service: tc.name,
217+
Replica: "1",
220218
}
221219
all = append(all, summary)
222220

pkg/api/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ type ContainerProcSummary struct {
523523
Name string
524524
Processes [][]string
525525
Titles []string
526-
Labels map[string]string
526+
Service string
527+
Replica string
527528
}
528529

529530
// ImageSummary holds container image description

pkg/compose/top.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ func (s *composeService) Top(ctx context.Context, projectName string, services [
4242
if err != nil {
4343
return err
4444
}
45-
summary[i] = api.ContainerProcSummary{
45+
name := getCanonicalContainerName(ctr)
46+
s := api.ContainerProcSummary{
4647
ID: ctr.ID,
47-
Name: getCanonicalContainerName(ctr),
48+
Name: name,
4849
Processes: topContent.Processes,
4950
Titles: topContent.Titles,
50-
Labels: container.Labels,
51+
Service: name,
5152
}
53+
if service, exists := ctr.Labels[api.ServiceLabel]; exists {
54+
s.Service = service
55+
}
56+
if replica, exists := ctr.Labels[api.ContainerNumberLabel]; exists {
57+
s.Replica = replica
58+
}
59+
summary[i] = s
5260
return nil
5361
})
5462
}

0 commit comments

Comments
 (0)