-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Redirect console to a file. #833
Conversation
Codecov Report
@@ Coverage Diff @@
## master #833 +/- ##
==========================================
- Coverage 69.82% 69.74% -0.09%
==========================================
Files 112 112
Lines 8776 8804 +28
==========================================
+ Hits 6128 6140 +12
- Misses 2251 2262 +11
- Partials 397 402 +5
Continue to review full report at Codecov.
|
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.
Thanks for tackling this and sorry for the delay in reviewing! Here's my initial impression of the changes.
lib/options.go
Outdated
@@ -268,6 +268,9 @@ type Options struct { | |||
|
|||
// Discard Http Responses Body | |||
DiscardResponseBodies null.Bool `json:"discardResponseBodies" envconfig:"discard_response_bodies"` | |||
|
|||
// Redirect console logging to a file | |||
RedirectConsoleToFile null.String `json:"redirectConsoleToFile" envconfig:"redirect_console_to_file"` |
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 not sure if this option should actually be accessible from the exported in-script options
. It feels like we should disable it (maybe a json:"-"
struct tag here will be enough?) for the same security and UX reasons (mostly with regards to distributed and cloud execution) we don't allow scripts to write stuff in files directly.
I see this functionality as something that, for the moment at least, would be meant primarily to help with local debugging of k6 scripts. We can probably extend it in the future, when we properly implement distributed execution inside of k6 (#140), but for now I think we should only allow configuring this via environment variables or CLI flags.
js/console.go
Outdated
f, err := fs.OpenFile(filepath, os.O_APPEND|os.O_WRONLY, os.ModeAppend) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
if f, err = fs.Create(filepath); err != nil { |
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 would prefer if you use os.O_CREATE above and change the file permissions to 0644
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.
So, this may take some time to resolve. os.O_CREATE
doesn't work with afero.CacheOnReadFs
that we use as the base FS for the runner. I have raised issue spf13/afero#193 to track this.
@cheesedosa ping! Hi I would like if we could, merge this. If you can't or don't want to do the changes we required I will be happy to do it myself :) |
@mstoykov , I am sorry, I totally forgot about this PR 😞 |
After another look and actually trying the code I realized two things:
Because of all this I would like if this redone so that
|
d88179f
to
65afa75
Compare
Yes, it was because the Currently, in k6 each VU gets its own |
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.
Thanks again for this PR!
This is better but as I have said I think we can do everything in SetOptions instead of adding new Methods to the interface. I tested it a little bit and everything seems to be working correctly so far though :).
Can you as well move the update of logrus before actually using it and having just two commits like:
- Updating logrus
- Implementing the console redirect
So that it looks cleaner in the history.
65afa75
to
f6f29e9
Compare
`console-output` attaches a new file based console to the VUs. This allows users to redirect all their `console.log/warn/etc.` to the given file. This prevents the stdout from getting cluttered with debug statements that may be printed in the test `.js` files.
f6f29e9
to
b8c8aee
Compare
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.
LGTM, though as a future extension to this, I'm wondering if it would be worth it to support outputting the console to a unix pipe or to something like /dev/null
?
Since these are Unix files, passing |
WIP for #831