Description
xref: #6113 (comment)
Currently for the ListContainerStats RPC in CRI, if a nil filter is supplied, the response is empty. This is not consistent with other containerd CRI List calls which provide full list if nil filter is supplied.
For ListContainerStats, in the current implementation is
-
We create a metrics request
|
request, containers, err := c.buildTaskMetricsRequest(in) |
-
If the request is nil, we return req, nil, nil
|
func (c *criService) buildTaskMetricsRequest( |
|
r *runtime.ListContainerStatsRequest, |
|
) (tasks.MetricsRequest, []containerstore.Container, error) { |
|
var req tasks.MetricsRequest |
|
if r.GetFilter() == nil { |
|
return req, nil, nil |
|
} |
- We call
toCRIContainerStats passing nil for containers
|
criStats, err := c.toCRIContainerStats(resp.Metrics, containers) |
- Since
containers is nil, we will ultimately skip the for loop and return an empty response
|
containerStats := new(runtime.ListContainerStatsResponse) |
|
for _, cntr := range containers { |
|
cs, err := c.containerMetrics(cntr.Metadata, statsMap[cntr.ID]) |
|
if err != nil { |
|
return nil, errors.Wrapf(err, "failed to decode container metrics for %q", cntr.ID) |
|
} |
|
containerStats.Stats = append(containerStats.Stats, cs) |
As a comparison, for the ContainerList RPC, if filter is nil, all containers are returned.
|
func (c *criService) filterCRIContainers(containers []*runtime.Container, filter *runtime.ContainerFilter) []*runtime.Container { |
|
if filter == nil { |
|
return containers |
|
} |
This is behavior is also not consistent with CRI-O implementation for ListContainerStats.
We should identify it make sense to change the functionality so a nil filter will return full response.
Description
xref: #6113 (comment)
Currently for the
ListContainerStatsRPC in CRI, if a nil filter is supplied, the response is empty. This is not consistent with other containerd CRIListcalls which provide full list if nil filter is supplied.For
ListContainerStats, in the current implementation isWe create a metrics request
containerd/pkg/cri/server/container_stats_list.go
Line 34 in 11ed340
If the request is nil, we return
req, nil, nilcontainerd/pkg/cri/server/container_stats_list.go
Lines 79 to 85 in 11ed340
toCRIContainerStatspassing nil forcontainerscontainerd/pkg/cri/server/container_stats_list.go
Line 42 in 11ed340
containersis nil, we will ultimately skip the for loop and return an empty responsecontainerd/pkg/cri/server/container_stats_list.go
Lines 57 to 63 in 11ed340
As a comparison, for the
ContainerListRPC, if filter is nil, all containers are returned.containerd/pkg/cri/server/container_list.go
Lines 67 to 70 in 11ed340
This is behavior is also not consistent with CRI-O implementation for
ListContainerStats.We should identify it make sense to change the functionality so a nil filter will return full response.