fix(metrics): fallback to mock writer on file open failure to prevent panic#596
fix(metrics): fallback to mock writer on file open failure to prevent panic#596abhaygoudannavar wants to merge 2 commits into
Conversation
✅ Deploy Preview for urunc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hello @abhaygoudannavar , please do not overwrite the PR description. Read the contribution guide for more information. |
|
@cmainas i have updated the PR description as asked for now it can be merged. |
cmainas
left a comment
There was a problem hiding this comment.
Hello @abhaygoudannavar ,
you have linked a PR instead of the issue in the description. Also, I left a comment for the unit test.
51ba5c5 to
8a31ff9
Compare
|
@cmainas i have done the changes asked for.
|
cmainas
left a comment
There was a problem hiding this comment.
Hello @abhaygoudannavar ,
thank you for the changes. I have added a comment.
8a31ff9 to
2b92199
Compare
When timestamps are enabled but the target file cannot be opened, NewZerologMetrics returned nil. This caused a nil pointer dereference on subsequent metrics.Capture() calls. This fix gracefully degrades to a no-op mockWriter and logs a warning. Adds a regression test to verify the fallback behavior. Fixes urunc-dev#595 Signed-off-by: abhaygoudannavar <abhaysgoudnvr@gmail.com>
2b92199 to
05344a3
Compare
cmainas
left a comment
There was a problem hiding this comment.
Hello @abhaygoudannavar ,
it seems there was a misunderstanding. Maybe I di not place the comment in the correct line. The check for the nil return should remain, the call later to Capture should get removed. We should not test by checking if the test crashes.
9a4d910 to
852d6d6
Compare
|
@cmainas Thanks for the clarification, I've updated the test to explicitly check for a non-nil writer instead of relying on the panic recovery. The PR has been updated. |
…esting Signed-off-by: abhaygoudannavar <abhaysgoudnvr@gmail.com>
852d6d6 to
f5df606
Compare
Description
When timestamps are enabled in the urunc configuration (
/etc/urunc/config.toml) but the target file path is invalid or the parent directory does not exist,NewZerologMetrics()returnsnil. Because the caller assigns this directly without a nil check, any subsequentmetrics.Capture()calls result in a nil pointer dereference, crashing urunc silently.This PR fixes the issue by returning a
&mockWriter{}(safe no-op fallback) and logging a warning instead of returningnilon file open failure. This ensures urunc gracefully disables metrics rather than panicking.Related issues
How was this tested?
/etc/urunc/config.tomlwithenabled = trueand destination set to a non-existent directory (/var/log/urunc/timestamps.log).sudo nerdctl run --rm --runtime io.containerd.urunc.v2 harbor.nbfc.io/nubificus/urunc/nginx-qemu-unikraft-initrd:latest.uruncstarts normally, logs a warning about the file, and gracefully disables metrics without crashing.make unittestto ensure no existing tests were broken.LLM usage
No usage
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).