Add truncindex for filter in List and Stat
fix #344 Signed-off-by: yanxuean <yan.xuean@zte.com.cn>
This commit is contained in:
parent
4a4a860dfa
commit
6234337459
@ -296,6 +296,29 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
|
||||
testStats(t, s, config)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("Fetch container stats for sandbox truncID and container truncID filter ")
|
||||
for id, config := range containerConfigMap {
|
||||
require.NoError(t, Eventually(func() (bool, error) {
|
||||
stats, err = runtimeService.ListContainerStats(
|
||||
&runtime.ContainerStatsFilter{Id: id[:3], PodSandboxId: sb[:3]})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(stats) != 1 {
|
||||
return false, fmt.Errorf("Unexpected stats length")
|
||||
}
|
||||
if stats[0].GetWritableLayer().GetUsedBytes().GetValue() != 0 &&
|
||||
stats[0].GetWritableLayer().GetInodesUsed().GetValue() != 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}, time.Second, 30*time.Second))
|
||||
t.Logf("Verify container stats for sandbox %q and container %q filter", sb, id)
|
||||
for _, s := range stats {
|
||||
testStats(t, s, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make this as options to use for dead container tests
|
||||
|
@ -54,12 +54,22 @@ func toCRIContainer(container containerstore.Container) *runtime.Container {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *criContainerdService) normalizeContainerFilter(filter *runtime.ContainerFilter) {
|
||||
if cntr, err := c.containerStore.Get(filter.GetId()); err == nil {
|
||||
filter.Id = cntr.ID
|
||||
}
|
||||
if sb, err := c.sandboxStore.Get(filter.GetPodSandboxId()); err == nil {
|
||||
filter.PodSandboxId = sb.ID
|
||||
}
|
||||
}
|
||||
|
||||
// filterCRIContainers filters CRIContainers.
|
||||
func (c *criContainerdService) filterCRIContainers(containers []*runtime.Container, filter *runtime.ContainerFilter) []*runtime.Container {
|
||||
if filter == nil {
|
||||
return containers
|
||||
}
|
||||
|
||||
c.normalizeContainerFilter(filter)
|
||||
filtered := []*runtime.Container{}
|
||||
for _, cntr := range containers {
|
||||
if filter.GetId() != "" && filter.GetId() != cntr.Id {
|
||||
|
@ -119,6 +119,15 @@ func (c *criContainerdService) getContainerMetrics(
|
||||
return &cs, nil
|
||||
}
|
||||
|
||||
func (c *criContainerdService) normalizeContainerStatsFilter(filter *runtime.ContainerStatsFilter) {
|
||||
if cntr, err := c.containerStore.Get(filter.GetId()); err == nil {
|
||||
filter.Id = cntr.ID
|
||||
}
|
||||
if sb, err := c.sandboxStore.Get(filter.GetPodSandboxId()); err == nil {
|
||||
filter.PodSandboxId = sb.ID
|
||||
}
|
||||
}
|
||||
|
||||
// buildTaskMetricsRequest constructs a tasks.MetricsRequest based on
|
||||
// the information in the stats request and the containerStore
|
||||
func (c *criContainerdService) buildTaskMetricsRequest(
|
||||
@ -128,6 +137,7 @@ func (c *criContainerdService) buildTaskMetricsRequest(
|
||||
if r.GetFilter() == nil {
|
||||
return req, nil, nil
|
||||
}
|
||||
c.normalizeContainerStatsFilter(r.GetFilter())
|
||||
var containers []containerstore.Container
|
||||
for _, cntr := range c.containerStore.List() {
|
||||
if r.GetFilter().GetId() != "" && cntr.ID != r.GetFilter().GetId() {
|
||||
|
@ -84,12 +84,19 @@ func toCRISandbox(meta sandboxstore.Metadata, state runtime.PodSandboxState, cre
|
||||
}
|
||||
}
|
||||
|
||||
func (c *criContainerdService) normalizePodSandboxFilter(filter *runtime.PodSandboxFilter) {
|
||||
if sb, err := c.sandboxStore.Get(filter.GetId()); err == nil {
|
||||
filter.Id = sb.ID
|
||||
}
|
||||
}
|
||||
|
||||
// filterCRISandboxes filters CRISandboxes.
|
||||
func (c *criContainerdService) filterCRISandboxes(sandboxes []*runtime.PodSandbox, filter *runtime.PodSandboxFilter) []*runtime.PodSandbox {
|
||||
if filter == nil {
|
||||
return sandboxes
|
||||
}
|
||||
|
||||
c.normalizePodSandboxFilter(filter)
|
||||
filtered := []*runtime.PodSandbox{}
|
||||
for _, s := range sandboxes {
|
||||
// Filter by id
|
||||
|
Loading…
Reference in New Issue
Block a user