-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix flaky TestHotReloadUIConfigTempFile #2713
Fix flaky TestHotReloadUIConfigTempFile #2713
Conversation
Signed-off-by: albertteoh <albert.teoh@logz.io>
Codecov Report
@@ Coverage Diff @@
## master #2713 +/- ##
==========================================
+ Coverage 95.59% 95.72% +0.12%
==========================================
Files 215 216 +1
Lines 9580 9588 +8
==========================================
+ Hits 9158 9178 +20
+ Misses 344 337 -7
+ Partials 78 73 -5
Continue to review full report at Codecov.
|
Signed-off-by: albertteoh <albert.teoh@logz.io>
Signed-off-by: albertteoh <albert.teoh@logz.io>
I don't understand why codecov thinks the Happy to add some simple tests instead of |
cmd/query/app/static_handler.go
Outdated
h.watch() | ||
|
||
return h, nil | ||
return h, h.watch() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is necessary? Failure to instantiate a watcher can now prevent the service from starting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you asked as I don't understand how critical UI config watching is and leaned on the side of bubbling errors up.
If it's something that historically has been brittle (as I noticed from unit tests), I'd be happy to revert this back (it'd also simplify the PR); and errors are reported through logging anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, watching is only enabled (hence possible failure to start) if the user provides a UI configuration and, by default, the UI config path is ""
which means watch()
should just return a nil
error. If the user provides UI configuration, they should expect the config to be watched and reloaded automatically. If it fails, I think it should prevent the service from starting, unless if we provide an opt-out flag.
If this error is encountered, the error message is quite clear and I believe, in most cases, is a straightforward resolution. e.g.:
{"level":"panic","ts":1609905512.493839,"caller":"app/static_handler.go:56","msg":"Could not create static assets handler","error":"cannot read UI config file /does/not/exist.json: open /does/not/exist.json: no such file or directory"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of an obvious error like this I'd agree. But fsnotify/NewWatcher can return an error even without a file name, that error is likely to me much less sensible. Imaging collector is running on an architecture where fsnotify does not work, but the user wasn't interested in hot reload anyway, they just wanted to start with a custom config file. The old code would only log an error and continue working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, agree with this if existing users have an expectation of just running UI config without hot reloads. I'll revert back to returning nil.
Perhaps because you exercise it from another package? Go tests to not extend coverage to other packages unless explicitly requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps because you exercise it from another package? Go tests to not extend coverage to other packages unless explicitly requested.
Yup, I did indeed exercise it from another package. I'll add some simple tests to cover this package as well.
cmd/query/app/static_handler.go
Outdated
h.watch() | ||
|
||
return h, nil | ||
return h, h.watch() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you asked as I don't understand how critical UI config watching is and leaned on the side of bubbling errors up.
If it's something that historically has been brittle (as I noticed from unit tests), I'd be happy to revert this back (it'd also simplify the PR); and errors are reported through logging anyway.
Signed-off-by: albertteoh <albert.teoh@logz.io>
Signed-off-by: albertteoh <albert.teoh@logz.io>
Signed-off-by: albertteoh <albert.teoh@logz.io>
Thanks, Albert! |
* Fix flaky TestHotReloadUIConfigTempFile Signed-off-by: albertteoh <albert.teoh@logz.io> * Address codecov warnings Signed-off-by: albertteoh <albert.teoh@logz.io> * make fmt Signed-off-by: albertteoh <albert.teoh@logz.io> * Address lint err: missing test file Signed-off-by: albertteoh <albert.teoh@logz.io> * Move to pkg/fswatcher, address other comments Signed-off-by: albertteoh <albert.teoh@logz.io> * Avoid failing hard when init watch() Signed-off-by: albertteoh <albert.teoh@logz.io> * Test Errors chan and validate error logs Signed-off-by: albertteoh <albert.teoh@logz.io>
Signed-off-by: albertteoh albert.teoh@logz.io
Which problem is this PR solving?
Short description of the changes
cert_watcher_test.go
, using log messages as a signal.Testing