Skip to content

add missing diff socket logic#210

Merged
rst0git merged 10 commits into
checkpoint-restore:mainfrom
hxadogar:socket-diff
Apr 20, 2026
Merged

add missing diff socket logic#210
rst0git merged 10 commits into
checkpoint-restore:mainfrom
hxadogar:socket-diff

Conversation

@hxadogar
Copy link
Copy Markdown
Contributor

diff --sockets was registered but not actually any compared logic.
now shows sockets added or removed.
it handles all socket types.

i have tested and verified manually.
and i will try to follow up with a dedicated pr for tests.

@adrianreber
Copy link
Copy Markdown
Member

Please add the tests to this PR as a second commit.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 26, 2026

Test Results

90 tests  +4   90 ✅ +4   4s ⏱️ -1s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 4cd2e72. ± Comparison against base commit 6e607c0.

♻️ This comment has been updated with latest results.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 87.95812% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.27%. Comparing base (a9e0ef7) to head (4cd2e72).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/diff.go 87.95% 17 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
+ Coverage   79.98%   84.27%   +4.28%     
==========================================
  Files          16       16              
  Lines        1759     1920     +161     
==========================================
+ Hits         1407     1618     +211     
+ Misses        263      224      -39     
+ Partials       89       78      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hxadogar
Copy link
Copy Markdown
Contributor Author

of course, will add tests shortly.

for now here is my manual testing output:

➜ sudo ./checkpointctl diff socket-8080.tar socket-8081_8082.tar --sockets
╔════════════════════════════════════════════════════════════════╗
║ Checkpoint Diff                                                ║
╠════════════════════════════════════════════════════════════════╣
║ Container: socket-test                                         ║
║ Image:     localhost/socket-test:latest                        ║
║ ID:        2088c8c5543c036e2b706e2ca743cd41c86c81b03037a524... ║
╚════════════════════════════════════════════════════════════════╝

Checkpoint A:
  Created: 2026-03-26T16:53:05+05:00
  Size:    5551762 bytes

Checkpoint B:
  Created: 2026-03-26T16:53:05+05:00
  Size:    5551910 bytes

┌─ Memory Changes ─────────────────────────────────────────────┐
│ = No change
└──────────────────────────────────────────────────────────────┘
┌─ Process Changes ────────────────────────────────────────────┐
└──────────────────────────────────────────────────────────────┘
┌─ Socket Changes ─────────────────────────────────────────────┐
│ Added:
│   + PID 1     TCP     0.0.0.0:8081 -> 0.0.0.0:0
│   + PID 1     TCP     0.0.0.0:8082 -> 0.0.0.0:0
│ Removed:
│   - PID 1     TCP     0.0.0.0:8080 -> 0.0.0.0:0
└──────────────────────────────────────────────────────────────┘
Summary:
Checkpoint comparison for container socket-test
Sockets: +2 -1

@hxadogar
Copy link
Copy Markdown
Contributor Author

i have added bats tests and i think its ready for review

@adrianreber
Copy link
Copy Markdown
Member

Thanks. Also add a couple of unit tests, especially for the error cases which are not covered via bats tests.

@hxadogar
Copy link
Copy Markdown
Contributor Author

i added the unit tests and try to covered the error cases too (not too much)

you can take another look when you get time

@adrianreber
Copy link
Copy Markdown
Member

Looks good to me. @rst0git What do you think? The commit messages could contain some more details about the changes.

Comment thread cmd/diff.go Outdated
Comment thread cmd/diff.go Outdated
Comment thread cmd/diff.go
@hxadogar hxadogar requested a review from rst0git April 19, 2026 13:10
@rst0git rst0git self-assigned this Apr 19, 2026
hxadogar and others added 2 commits April 20, 2026 12:06
Detect added, removed, and unchanged sockets by matching on
(PID + protocol + type + addresses + ports). The results are
shown as an ss(8)-style table. We use labels to avoid the
ambiguity of an arrow between two endpoints, and PEER shows
"-" for listeners and unconnected UDP.

Example:

sudo checkpointctl diff --sockets --files --ps-tree-cmd  --ps-tree-env  cp1.tar cp2.tar
╔════════════════════════════════════════════════════════════════╗
║ Checkpoint Diff                                                ║
╠════════════════════════════════════════════════════════════════╣
║ Container: optimistic_mclean                                   ║
║ Image:     docker.io/library/python:alpine                     ║
║ ID:        6ebe04dda2005962a8fb4e971caedfda5e03e22c882e2334... ║
╚════════════════════════════════════════════════════════════════╝

Checkpoint A:
  Created: 2026-04-18T10:15:41+01:00
  Size:    15186908 bytes

Checkpoint B:
  Created: 2026-04-18T10:15:41+01:00
  Size:    15212641 bytes

┌─ Memory Changes ─────────────────────────────────────────────┐
│ ↑ Increased by 0.02 MB
└──────────────────────────────────────────────────────────────┘
┌─ Process Changes ────────────────────────────────────────────┐
└──────────────────────────────────────────────────────────────┘
┌─ File Descriptor Changes ────────────────────────────────────┐
│ Added:
│   + PID 2     INETSK   INETSK.29
│ Unchanged: 11
└──────────────────────────────────────────────────────────────┘
┌─ Socket Changes ──────────────────────────────────────────────────────┐
│     PID   PROTO STATE        LOCAL                 PEER
│  +  2     TCP   ESTABLISHED  10.88.0.3:8080        10.88.0.1:39838
│ Unchanged: 1
└───────────────────────────────────────────────────────────────────────┘

Assisted-by: Claude Code

Signed-off-by: Hamza Dogar <hxadogar@gmail.com>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
The default output now hides "Unchanged: N" entirely as this
is just a numer without userful information.

The --show-unchanged option lists each unchanged process, file descriptor,
and socket (marked with "=") alongside the delta. This context is needed
to interpret the added/removed entries.

The Unchanged field on ProcessDiff/FileDiff/SocketDiff is now a slice
of entries instead of a counter. The "unchanged" key is now an array
(omitted when empty) rather than an integer.

Example:

sudo checkpointctl diff --show-unchanged --sockets --files --ps-tree-cmd  --ps-tree-env  cp1.tar cp2.tar
╔════════════════════════════════════════════════════════════════╗
║ Checkpoint Diff                                                ║
╠════════════════════════════════════════════════════════════════╣
║ Container: optimistic_mclean                                   ║
║ Image:     docker.io/library/python:alpine                     ║
║ ID:        6ebe04dda2005962a8fb4e971caedfda5e03e22c882e2334... ║
╚════════════════════════════════════════════════════════════════╝

Checkpoint A:
  Created: 2026-04-18T10:15:41+01:00
  Size:    15186908 bytes

Checkpoint B:
  Created: 2026-04-18T10:15:41+01:00
  Size:    15212641 bytes

┌─ Memory Changes ─────────────────────────────────────────────┐
│ ↑ Increased by 0.02 MB
└──────────────────────────────────────────────────────────────┘
┌─ Process Changes ────────────────────────────────────────────┐
└──────────────────────────────────────────────────────────────┘
┌─ File Descriptor Changes ────────────────────────────────────┐
│ Added:
│   + PID 2     INETSK   INETSK.29
│ Unchanged:
│   = PID 2              /
│   = PID 2              /
│   = PID 1     PIPE     pipe[70435895]
│   = PID 1              /
│   = PID 2     INETSK   INETSK.28
│   = PID 1     REG      /dev/null
│   = PID 1     PIPE     pipe[70435894]
│   = PID 1              /
│   = PID 2     REG      /dev/null
│   = PID 2     PIPE     pipe[70435894]
│   = PID 2     PIPE     pipe[70435895]
└──────────────────────────────────────────────────────────────┘
┌─ Socket Changes ──────────────────────────────────────────────────────┐
│     PID   PROTO STATE        LOCAL                 PEER
│  +  2     TCP   ESTABLISHED  10.88.0.3:8080        10.88.0.1:39838
│  =  2     TCP   LISTEN       0.0.0.0:8080          -
└───────────────────────────────────────────────────────────────────────┘

Assisted-by: Claude Code

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
@adrianreber
Copy link
Copy Markdown
Member

@hxadogar Sorry, I pressed the wrong button. Can you remove my merge commit? I can also do it if you want.

hxadogar and others added 4 commits April 20, 2026 12:11
Check that `checkpointctl diff --sockets` reports the expected
added, removed and unchanged TCP connections across checkpoints.
These tests cover both the text and the JSON output.

We extend the piggie process to use a pair of command and
acknowledgement FIFOs ($PIGGIE_CMD_FIFO and $PIGGIE_ACK_FIFO)
that allow it to spawn and terminate extra TPC clients inside its
private netns. Each command is acknowledged once the action has
completed (e.g., the new client's connect() call has returned).
The test-imgs-diff.sh script uses this functionality to create
two checkpoints with deterministic differences. This approach
allows us to extend testing with additional use cases in
subsequent commits.

While here, we drop the hard-coded line-index assertions from the
inspect --files test. They broke whenever the process tree PIDs
shifted in the output.

Signed-off-by: Hamza Dogar <hxadogar@gmail.com>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Extend piggie and the command FIFOs with actions for
creating and removing UDP clients between checkpoints.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Signed-off-by: Hamza Dogar <hxadogar@gmail.com>
@rst0git
Copy link
Copy Markdown
Member

rst0git commented Apr 20, 2026

@adrianreber No worries! I will update the PR soon

@hxadogar
Copy link
Copy Markdown
Contributor Author

Thanks @rst0git! I was about to handle it

rst0git added 4 commits April 20, 2026 12:45
Replace the ProcessTree mirror struct with internal.PsNode so diff
reuses the same types as inspect. This allows to render the
process-tree as an annotated treeprint when --show-unchanged is set.
Each PID is prefixed with +, ~, or = for added/modified/unchanged,
and PIDs only present in checkpoint A are listed separately as Removed.

Enable internal.PsTree per-task in getTaskJSON when pstree.img is
available so the section is actually populated (it was always empty
before).

The section header is renamed from "Process Changes" to "Process Tree",
and print "= No change" when the trees match.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Add unit tests covering compareProcessTrees, flattenProcessTree,
buildProcessStatusMap, and renderAnnotatedProcessTree including
the blank-marker fallback for PIDs not in the status map.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Check that Process Tree section shows "No change" for identical
checkpoints, and the annotated tree when unchanged and added PIDs.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
@rst0git
Copy link
Copy Markdown
Member

rst0git commented Apr 20, 2026

@hxadogar I've revised the patches in this branch https://github.com/rst0git/checkpointctl/tree/socket-diff
Would you be able to confirm if you are happy with the changes?

@rst0git
Copy link
Copy Markdown
Member

rst0git commented Apr 20, 2026

I will go ahead and merge these changes; we can make any other changes in follow-up PRs

@rst0git rst0git merged commit eea83bf into checkpoint-restore:main Apr 20, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants