-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Added flag to set verbose output size limit for newman run #2883
base: develop
Are you sure you want to change the base?
Added flag to set verbose output size limit for newman run #2883
Conversation
…t, the current limit was hardcoded to 2KB or 2048 bytes.
Codecov Report
@@ Coverage Diff @@
## develop #2883 +/- ##
===========================================
+ Coverage 90.96% 91.55% +0.59%
===========================================
Files 21 21
Lines 1151 1161 +10
Branches 349 352 +3
===========================================
+ Hits 1047 1063 +16
+ Misses 104 98 -6
Flags with carried forward coverage won't be shown. Click here to find out more.
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.
Also, this codecov seems to be failing. We did cross the threshold in the PR, no clue why it's still failing.
lib/reporters/cli/index.js
Outdated
].join(` ${colors.gray(symbols.star)} `); | ||
].join(` ${colors.gray(symbols.star)} `), | ||
|
||
bodyClipSize = options.outputSize * KB_TO_BYTE_MULTIPLIER; |
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.
Handle fallback for invalid bodySize in-line here
README.md
Outdated
@@ -174,6 +174,9 @@ For more details on [Reporters](#reporters) and writing your own [External Repor | |||
- `--timeout-script <ms>`<br /> | |||
Specify the time (in milliseconds) to wait for scripts to complete execution. | |||
|
|||
- `--output-size <KB>`<br /> |
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.
As we all know, naming is the hardest part of the equation. This name has some way to go to resonate with what it does - "specify the truncation point of a body in verbose CLI output for requests and responses."
How about bracketing it under "reporter-cli-*" params?
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.
Having gone through the reporter-cli params, I think bracketing it under reporter-cli-* would be more appropriate
How about replacing the current output-size flag with two reporter-cli flags
reporter-cli-verbose-output-limit <Size in any memory unit>
reporter-cli-no-verbose-output limit
: Sets the limit to Infinite
It's rare to see Command Line tools allow users to pass arguments as infinite. Plus spelling errors might creep in.Mostly, they achieve by simply setting some flag.
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.
Hey @shamasis, any thoughts regarding this?
README.md
Outdated
@@ -288,6 +291,7 @@ return of the `newman.run` function is a run instance, which emits run events th | |||
| options.timeout | Specify the time (in milliseconds) to wait for the entire collection run to complete execution.<br /><br />_Optional_<br />Type: `number`, Default value: `Infinity` | | |||
| options.timeoutRequest | Specify the time (in milliseconds) to wait for requests to return a response.<br /><br />_Optional_<br />Type: `number`, Default value: `Infinity` | | |||
| options.timeoutScript | Specify the time (in milliseconds) to wait for scripts to return a response.<br /><br />_Optional_<br />Type: `number`, Default value: `Infinity` | | |||
| options.outputSize | Specify the output size limit ( in KB ) when verbose flag is set.<br /><br />For example, `outputSize = 2` sets the verbose output limit to 2KB or 2048 bytes.<br /><br />To remove any verbose output limit, pass `infinite` to `--output-size`. This would set `outputSize` to `Number. POSITIVE_INFINITY`<br /><br />_Optional_<br />Type: `number`, Default value: `2` | |
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.
Is KB the right unit? Any other option around size that we can draw pattern from?
Any way we can take more dynamic input by parsing units? I'm sure there will be some popular library that can take "10kb", "1Mb" as inputs and spit out absolute bytes. 😛
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.
Sure, will implement this. In case of invalid inputs, should we proceed with default 2KB or throw an error?
bin/newman.js
Outdated
@@ -50,6 +50,7 @@ program | |||
.option('--timeout [n]', 'Specify a timeout for collection run (milliseconds)', util.cast.integer, 0) | |||
.option('--timeout-request [n]', 'Specify a timeout for requests (milliseconds)', util.cast.integer, 0) | |||
.option('--timeout-script [n]', 'Specify a timeout for scripts (milliseconds)', util.cast.integer, 0) | |||
.option('--output-size [n]', 'Specify the output size limit for CLI ( in KB )', util.cast.integerOrInfinity, 2) |
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.
English here is ambiguous "output size of what? Entire CLI, body always, body in verbose"?!
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.
Technically, this PR limits the verbose body output only. I'll make the necessary changes to remove this ambiguity.
bin/util.js
Outdated
* @param {String} arg - The stringified number argument or infinite. | ||
* @returns {Number} - The supplied argument, casted to an integer or positive infinity. | ||
*/ | ||
integerOrInfinity: (arg) => { |
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.
How does Newman handle other properties that can have infinity? Any pattern to draw from there?
test/cli/verbose.test.js
Outdated
@@ -33,4 +37,37 @@ describe('newman run --verbose', function () { | |||
done(); | |||
}); | |||
}); | |||
|
|||
it('should limit to 2KB with --verbose option only without setting output-size', function (done) { |
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.
Very neat and creative test. Like it ❤️😊.
Another improvement could be if the body was autogenerated series of number marking increasing size. That way, we can both assert points and accuracy.
@shamasis can you provide me with some additional feedback so that I can continue working on this? |
Hey @shamasis, @codenirvana @coditva, I have updated this PR with the necessary changes. Currently there are 2 flags,
The --reporter-cli-verbose-output-limit uses bytes to convert string input to bytes. In case of any invalid input, a warning is shown and a fallback size of 2KB is used. |
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.
We do not need to introduce two parameters for this. In the grand scheme of things this is a small feature and one parameter should do. Here's what we can do:
-
We ALWAYS clip. No matter what.
Providing Infinity as an input option can then automatically prevent clipping with least complicated codes. (And we mention this behaviour in docs as a short byline.) -
We take only one option --reporter-cli-truncate-body-output (people will 99% chance refer documentation to get to this, hence we name accordingly.)
-
In the documentation, mention example input such as '1024', '1KB', etc so that users know what to input here and not need to refer the "bytes" readme doc.
PS - apologies for slow review, we are busy with a tonne of year change activities.
lib/reporters/cli/index.js
Outdated
@@ -26,7 +27,7 @@ var _ = require('lodash'), | |||
process: 'process', | |||
total: 'total' | |||
}, | |||
BODY_CLIP_SIZE = 2048, | |||
DEFAULT_VERBOSE_OUTPUT_TRUNCATION_LIMIT = '2KB', |
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.
Let's keep the constant name to body clip size. This way there is no ambiguity as to what output it is clipping.
lib/reporters/cli/index.js
Outdated
@@ -70,6 +71,8 @@ extractSNR = function (executions) { | |||
* @param {Boolean=} reporterOptions.noFailures - Boolean flag to turn off failure reporting altogether, if set to true. | |||
* @param {Boolean=} reporterOptions.noConsole - Boolean flag to turn off console logging, if set to true. | |||
* @param {Boolean=} reporterOptions.noBanner - Boolean flag to turn off newman banner, if set to true. | |||
* @param {String=} reporterOptions.verboseOutputLimit - Specify the truncation size of body in verbose CLI output. |
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.
We do not need to introduce two parameters for this. In the grand scheme of things this is a small feature and one parameter should do. Here's what we can do:
- We ALWAYS clip. No matter what.
- Providing
Infinity
as an input option can then automatically prevent clipping with least complicated codes. (And we mention this behaviour in docs as a short byline.) - We take only one option
--reporter-cli-truncate-body-output
(people will 99% chance refer documentation to get to this, hence we name accordingly.)
Check for isNaN much earlier and prevent NaN from flowing too much down the code flow.
lib/reporters/cli/index.js
Outdated
|
||
].join(` ${colors.gray(symbols.star)} `), | ||
// eslint-disable-next-line max-len | ||
bodyClipSize = reporterOptions.verboseOutputLimit ? bytes(reporterOptions.verboseOutputLimit) : bytes(DEFAULT_VERBOSE_OUTPUT_TRUNCATION_LIMIT); |
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.
Set the default value here. No need to compute. Instead at the below if
block, set it if !isNaN
and warn user in else of that block
lib/reporters/cli/index.js
Outdated
reqText = reqText.substr(0, BODY_CLIP_SIZE) + | ||
colors.brightWhite(`\n(showing ${util.filesize(BODY_CLIP_SIZE)}/${util.filesize(reqTextLen)})`); | ||
// truncate very large request (if noVerboseOutputLimit flag is set, remove any limitations) | ||
if (!reporterOptions.noVerboseOutputLimit && reqTextLen > bodyClipSize) { |
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.
If the above recommendations are followed, then this if block become almost as original.
@shamasis, I have simplified the implementation by using a single flag.
|
I think this is ready for approval. Feature now looks cool. I've marked it as approved, but there's one tiny comment to resolve for you. |
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.
Approved. One comment to be resolved.
lib/reporters/cli/index.js
Outdated
|
||
if (reporterOptions.truncateBodyOutput) { | ||
// if infinite is passed to truncate-body-output | ||
if (reporterOptions.truncateBodyOutput === 'infinite') { |
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.
Why not take input as "infinity"? (Lowercase compare to ensure we don't need case sensitivity)
If you don't like the word infinity, then can use "none" too.
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 think infinity would be better since the description for --reporter-cli-truncate-body-output is specify the truncation size of body in verbose CLI output for requests and responses.
Hello, this improvement is waiting for 1 year already, is there an eta when it'll be published or is there an alternative to avoid output limiting? |
I would love to have this |
Hello, Is there any forecast to have this option published on newman? That's really something that will help a lot everyone, have the full request / response body written into a log. We work with images base64 inside the body and is impossible to check if everything was sent as expected Eduardo |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #2883 +/- ##
===========================================
+ Coverage 90.96% 91.55% +0.59%
===========================================
Files 21 21
Lines 1151 1161 +10
Branches 349 352 +3
===========================================
+ Hits 1047 1063 +16
+ Misses 104 98 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Flag for Verbose Output Size Limit
Previously, the output limit when the verbose flag was set was 2KB or 2048 bytes which were hardcoded in the codebase. The main argument that can be made for hardcoding the limit to 2KB is large data streams can crash the terminal. However, this limit is unfair in cases when the output size is just beyond the 2KB size limit. Moreover in cases when you want to pipe the output of newman run to a file, setting a size limit doesn't make sense and moreover, the terminal won't crash.
This PR adds two new flags under --reporter-cli-*
Syntax
Changes
Closes #2845