Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias and '--all' option to checkpointctl show #46

Merged
merged 3 commits into from
Apr 26, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ $ checkpointctl show /var/lib/kubelet/checkpoints/checkpoint-counters_default-co
```

It is also possible to display additional checkpoint related information
with the parameter `--print-stats`:
with the parameter `--stats`:

```console
$ checkpointctl show /tmp/dump.tar --print-stats
$ checkpointctl show /tmp/dump.tar --stats

+-----------------+------------------------------------------+--------------+---------+----------------------+--------+------------+-------------------+
| CONTAINER | IMAGE | ID | RUNTIME | CREATED | ENGINE | CHKPT SIZE | ROOT FS DIFF SIZE |
+-----------------+------------------------------------------+--------------+---------+----------------------+--------+------------+-------------------+
| magical_murdock | quay.io/adrianreber/wildfly-hello:latest | f11d11844af0 | crun | 2023-02-28T09:43:52Z | Podman | 338.2 MiB | 177.0 KiB |
+-----------------+------------------------------------------+--------------+---------+----------------------+--------+------------+-------------------+

CRIU dump statistics
+---------------+-------------+--------------+---------------+---------------+---------------+
| FREEZING TIME | FROZEN TIME | MEMDUMP TIME | MEMWRITE TIME | PAGES SCANNED | PAGES WRITTEN |
Expand Down
24 changes: 23 additions & 1 deletion checkpointctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"fmt"
"log"
"os"

"github.com/containers/storage/pkg/archive"
Expand All @@ -16,6 +17,7 @@ var (
printStats bool
showMounts bool
fullPaths bool
showAll bool
)

func main() {
Expand Down Expand Up @@ -50,6 +52,12 @@ func setupShow() *cobra.Command {
false,
"Print checkpointing statistics if available",
)
flags.BoolVar(
&printStats,
"stats",
false,
"Print checkpointing statistics if available",
)
flags.BoolVar(
&showMounts,
"mounts",
Expand All @@ -62,13 +70,27 @@ func setupShow() *cobra.Command {
false,
"Display mounts with full paths",
)
flags.BoolVar(
&showAll,
"all",
false,
"Display all additional information about the checkpoints",
)

err := flags.MarkHidden("print-stats")
if err != nil {
log.Fatal(err)
}
return cmd
}

func show(cmd *cobra.Command, args []string) error {
if showAll {
printStats = true
showMounts = true
}
if fullPaths && !showMounts {
return fmt.Errorf("Cannot use --full-paths without --mounts option")
return fmt.Errorf("Cannot use --full-paths without --mounts/--all option")
}

input := args[0]
Expand Down
32 changes: 24 additions & 8 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,34 @@ function teardown() {
[[ ${lines[4]} == *"containerd"* ]]
}

@test "Run checkpointctl show with tar file and --print-stats and missing stats-dump" {
@test "Run checkpointctl show with tar file and --stats and missing stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --print-stats
checkpointctl show "$TEST_TMP_DIR2"/test.tar --stats
[ "$status" -eq 1 ]
[[ ${lines[6]} == *"unable to display checkpointing statistics"* ]]
}

@test "Run checkpointctl show with tar file and --print-stats and invalid stats-dump" {
@test "Run checkpointctl show with tar file and --stats and invalid stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"/stats-dump
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --print-stats
checkpointctl show "$TEST_TMP_DIR2"/test.tar --stats
[ "$status" -eq 1 ]
[[ ${lines[6]} == *"Unknown magic"* ]]
}

@test "Run checkpointctl show with tar file and --print-stats and valid stats-dump" {
@test "Run checkpointctl show with tar file and --stats and valid stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
cp test/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --print-stats
checkpointctl show "$TEST_TMP_DIR2"/test.tar --stats
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"CRIU dump statistics"* ]]
[[ ${lines[8]} == *"MEMWRITE TIME"* ]]
Expand Down Expand Up @@ -160,15 +160,31 @@ function teardown() {
[[ ${lines[10]} == *"/proc"* ]]
}

@test "Run checkpointctl show with tar file and --all and valid spec.dump and valid stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
cp test/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --all
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"Overview of Mounts"* ]]
[[ ${lines[8]} == *"DESTINATION"* ]]
[[ ${lines[10]} == *"/proc"* ]]
[[ ${lines[11]} == *"/etc/hostname"* ]]
[[ ${lines[13]} == *"CRIU dump statistics"* ]]
[[ ${lines[15]} == *"MEMWRITE TIME"* ]]
[[ ${lines[17]} == *"446571 us"* ]]
}

@test "Run checkpointctl show with tar file and missing --mounts and --full-paths" {
@test "Run checkpointctl show with tar file and missing --mounts/--all and --full-paths" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --full-paths
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"Error: Cannot use --full-paths without --mounts option"* ]]
[[ ${lines[0]} == *"Error: Cannot use --full-paths without --mounts/--all option"* ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and valid spec.dump (CRI-O) and no checkpoint directory" {
Expand Down