Thanks to visit codestin.com
Credit goes to github.com

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
5 changes: 3 additions & 2 deletions internal/lib/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ func (s *Sandbox) UnmountShm() error {
return nil
}

// try to unmount, ignoring "not mounted" (EINVAL) error
if err := unix.Unmount(fp, unix.MNT_DETACH); err != nil && err != unix.EINVAL {
// try to unmount, ignoring "not mounted" (EINVAL) error and
// "already unmounted" (ENOENT) error
if err := unix.Unmount(fp, unix.MNT_DETACH); err != nil && err != unix.EINVAL && err != unix.ENOENT {
return errors.Wrapf(err, "unable to unmount %s", fp)
}

Expand Down
78 changes: 25 additions & 53 deletions test/stats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,43 @@ function teardown() {
# given
run crictl run "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
[ "$status" -eq 0 ]
id="$output"

# when
run crictl stats -o json
echo "$output"
[ "$status" -eq 0 ]

# then
JSON="$output"
run echo $JSON | jq -e '.stats[0].attributes.id != ""'
[ "$status" -eq 0 ]

run echo $JSON | jq -e '.stats[0].cpu.timestamp > 0'
[ "$status" -eq 0 ]

run echo $JSON | jq -e '.stats[0].cpu.usageCoreNanoSeconds.value > 0'
[ "$status" -eq 0 ]

run echo $JSON | jq -e '.stats[0].memory.timestamp > 0'
[ "$status" -eq 0 ]

run echo $JSON | jq -e '.stats[0].memory.workingSetBytes.value > 0'
[ "$status" -eq 0 ]
jq -e '.stats[0].attributes.id = "'"$id"'"' <<< "$output"
jq -e '.stats[0].cpu.timestamp > 0' <<< "$output"
jq -e '.stats[0].cpu.usageCoreNanoSeconds.value > 0' <<< "$output"
jq -e '.stats[0].memory.timestamp > 0' <<< "$output"
jq -e '.stats[0].memory.workingSetBytes.value > 0' <<< "$output"
}

@test "container stats" {
# given
container2config=$(cat "$TESTDATA"/container_redis.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["name"] = ["podsandbox1-redis2"];obj["metadata"]["name"] = "podsandbox1-redis2"; json.dump(obj, sys.stdout)')
echo "$container2config" > "$TESTDIR"/container_redis2.json
run crictl runp "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
run crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
ctr1_id="$output"
run crictl create "$pod_id" "$TESTDIR"/container_redis2.json "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
ctr2_id="$output"
run crictl start "$ctr1_id"
echo "$output"
[ "$status" -eq 0 ]
run crictl start "$ctr2_id"
echo "$output"
[ "$status" -eq 0 ]

# when
run crictl stats -o json "$ctr1_id"
echo "$output"
[ "$status" -eq 0 ]
ctr1_stats_JSON="$output"
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)

run crictl stats -o json "$crt2_id"
echo "$output"
[ "$status" -eq 0 ]
ctr2_stats_JSON="$output"
ctr1_id=$(crictl create "$pod_id" "$TESTDATA"/container_sleep.json "$TESTDATA"/sandbox_config.json)
crictl start "$ctr1_id"

run echo $ctr1_stats_JSON | jq -e '.stats[0].memory.workingSetBytes.value'
[ "$status" -eq 0 ]
ctr1_memory_bytes="$output"
run echo $ctr2_stats_JSON | jq -e '.stats[0].memory.workingSetBytes.value'
[ "$status" -eq 0 ]
ctr2_memory_bytes="$output"
ctr2_id=$(crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json)
crictl start "$ctr2_id"

run echo $ctr1_memory_bytes != $ctr2_memory_bytes
[ "$status" -eq 0 ]
# when
json=$(crictl stats -o json "$ctr1_id")
echo "$json"
jq -e '.stats[0].attributes.id == "'"$ctr1_id"'"' <<< "$json"
ctr1_mem=$(jq -e '.stats[0].memory.workingSetBytes.value' <<< "$json")

json=$(crictl stats -o json "$ctr2_id")
echo "$json"
jq -e '.stats[0].attributes.id == "'"$ctr2_id"'"' <<< "$json"
ctr2_mem=$(jq -e '.stats[0].memory.workingSetBytes.value' <<< "$json")

# Assuming the two containers can't have exactly same memory usage
echo "checking $ctr1_mem != $ctr2_mem"
[ "$ctr1_mem" != "$ctr2_mem" ]
}