Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions server/container_stats_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ func (s *Server) ListContainerStats(ctx context.Context, req *types.ListContaine
if err != nil {
return nil, err
}
filter := req.Filter
if filter != nil {
if req.Filter != nil {
cFilter := &types.ContainerFilter{
Id: req.Filter.Id,
PodSandboxId: req.Filter.PodSandboxId,
LabelSelector: req.Filter.LabelSelector,
}
ctrList = s.filterContainerList(ctx, cFilter, ctrList)

filteredCtrList := []*oci.Container{}
for _, ctr := range ctrList {
if filterContainer(ctr.CRIContainer(), cFilter) {
filteredCtrList = append(filteredCtrList, ctr)
}
}
ctrList = filteredCtrList
}

return &types.ListContainerStatsResponse{
Expand Down
4 changes: 4 additions & 0 deletions test/stats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ function teardown() {
# Assuming the two containers can't have exactly same memory usage
echo "checking $ctr1_mem != $ctr2_mem"
[ "$ctr1_mem" != "$ctr2_mem" ]

# Test if the label filtering works
[ "$(crictl stats | wc -l)" == 3 ]
[ "$(crictl stats --label tier=backend | wc -l)" == 2 ]
}

@test "pod stats" {
Expand Down