GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Support JSON/CSV export in run command via format detection by diegolovison · Pull Request #951 · Hyperfoil/Hyperfoil Conversation
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
A few things to fix before merge:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0d8f053 to
0380b9a
Compare
|
@stalep all your review notes were addressed and pretty nice, tbh. Commits:
For the smaller notes I opened 3 diff issues I will address in diff PRs: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks Diego. JSON/CSV/ZIP output works for me end to end on both run and wrk2, and the new test-suite tests fail without the change, which is good. There is one regression I think needs fixing before merge, plus a few smaller things:
-o <dir> / -o <name> regressed. The extension is taken from output.split("\\."), so run.sh -o /tmp/reports now fails with Unknown format '/tmp/reports'. On master it writes /tmp/reports/<runId>.html, and that is the documented usage in docs/.../howtos/run_scripts.md (--output <path-to-dir>, example run.sh -o /tmp/reports …). Extensionless names (-o report) and dots in directory names (-o /a/my.dir/out → Unknown format 'dir/out') break the same way. Could you take the extension from the file name only, and fall back to HTML for directories and extensionless paths? #981 (better message) wouldn't restore the old behaviour.-o foo.csv writes foo.zip but prints nothing. Please print where the file was written (as report does). Also, because -y is forced, an existing foo.zip the user never named gets overwritten silently. Maybe drop -y for the rewritten path, or reject .csv and ask for .zip.run_scripts.md (still "HTML report"/"path-to-dir", old help text) and the "Use --output to generate an HTML report." hint in LoadAndRun.ControllerVerticle change is a real fix: a non-clustered startBenchmark with agents leaves terminateTime incomplete on master (I checked with a small unit test). But it isn't related to CLI output and it has no test here. Could it go in a separate PR with a test?RunTest and WrkTest; ExportTest would be less fragile with a @TempDir than with mockStatic(Files.class).Other notes (outside the diff):
cli/src/main/java/io/hyperfoil/cli/commands/Export.java:52 — nothing is printed on success, unlike Report ("Report written to …"). With the .csv→.zip rename the user has no way to know the file name.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| public static void executeOutputCommand(HyperfoilCommandInvocation invocation, String output) throws CommandException { | ||
| if (output != null && !output.isBlank()) { | ||
| String[] extensionPart = output.split("\\."); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
split("\\.") on the whole path: /tmp/reports → format /tmp/reports, /a/my.dir/out → dir/out. Use the file name's extension, and fall back to HTML (old behaviour) for directories and extensionless paths.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| extension = "csv"; | ||
| } else if ("csv".equalsIgnoreCase(extension)) { | ||
| // CSV export is actually a zip archive, save it with the correct extension. | ||
| destination = destination.substring(0, destination.length() - extension.length()) + "zip"; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the user asked for foo.csv but gets foo.zip, with no message, and -y overwrites an existing foo.zip. Please print the final path and avoid forcing overwrite of a name the user didn't give.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| invocation.executeSwitchable("report --silent -y --destination " + output); | ||
| OutputCommandUtil.executeOutputCommand(invocation, output); | ||
| } else { | ||
| invocation.println("Run files are in " + runDir(invocation) + ". Use --output to generate an HTML report."); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the hint still says "generate an HTML report".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| vertx.deployVerticle(AgentVerticle.class, new DeploymentOptions().setConfig(config)); | ||
| } | ||
| } else { | ||
| if (!vertx.isClustered()) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
correct and matches the sibling branches from #957, but unrelated to this PR and untested. Please split it out with a test (non-clustered Vertx, benchmark with one agent, assert terminateTime completed and persistenceComplete failed).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| assertEquals(CommandResult.FAILURE.getResultValue(), result); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
please add a case for --output <existing dir> (the documented form).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
71ac190 to
f307aee
Compare
|
All comments were addressed. The remaining is #991 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
f307aee to
9316c81
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks Diego, this is much better. Extension detection now works for everything I tried end to end: an existing dir, an extensionless name, x.json, x.csv → x.zip (with the "Export written to" message), a dot in a directory name, and an existing dir with a dot in its name. The new tests fail when the behaviour they cover is broken (I checked each one by breaking the code). The shared OutputValidation and the @TempDir tests are nice too.
Two things before merge:
-y (38d08c8) breaks non-interactive re-runs. When the output file already exists and stdin isn't a terminal, run.sh now fails with NullPointerException: ... Shell.readLine() is null, writes nothing, and still exits 0. Even piping y doesn't help; only a real TTY works. The simplest way to hit it is the documented run.sh -o /tmp/reports ... in a fresh container/CI job: the run id is 0000 again, so 0000.html already exists. On master the same sequence just overwrites the report. It also contradicts "No CLI interactions" in run_scripts.md. Could you keep passing -y for paths the user typed, as master does, and special-case only the renamed foo.csv → foo.zip (fail with a clear message if foo.zip exists, or just require .zip)? If we want overwrite prompts for reports, I'd do that in its own PR, together with handling EOF in readYes. WrkAbstract (wrk/wrk2 -o) got the same change at line 193, so I expect the same failure there; I've only read that code, not run it.ControllerVerticle change is still in this PR (commit 5015e72). Thanks for opening #991. Please drop the commit here and send it with #991 plus a test.Smaller things:
<tmp>/my.dir). If I remove the Files.isDirectory(...) fallback, all RunTest tests still pass.run.sh still exits 0 on any output failure: LoadAndRun.main ignores exec()'s result, and executeSwitchable ignores the sub-command's result, so exec() returns 0 for -o /nonexistent/x.json. This was already the case on master, so it doesn't block this PR, but could you open an issue for it? #983 only covered Export's return value.run_scripts.md:61 still shows [-o OUTPUT_DIR]. The help line in the docs says "for the report" while the code says "for the statistics".user.home to a @TempDir instead of mockStatic(Files.class).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // A directory or an extensionless name falls back to an HTML report, like on master. | ||
| String extension = (dotIndex < 0 || Files.isDirectory(Path.of(output))) ? "html" : fileName.substring(dotIndex + 1); | ||
| if ("html".equalsIgnoreCase(extension)) { | ||
| invocation.executeSwitchable("report --silent " + yesFlag + "--destination " + output); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
master always passed -y here. Without it, an existing report (e.g. 0000.html in a reused -o <dir>) prompts, and with no TTY readLine() returns null, so the run fails with an NPE and nothing is written (exit code 0). Please keep -y for the paths the user typed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| extension = "csv"; | ||
| } else if ("csv".equalsIgnoreCase(extension)) { | ||
| // CSV export is actually a zip archive, save it with the correct extension. | ||
| destination = destination.substring(0, destination.length() - extension.length()) + "zip"; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this renamed path is the only one the user didn't type. If foo.zip already exists, I'd fail with a clear message (or require .zip) rather than prompt.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } else { | ||
| if (!vertx.isClustered()) { | ||
| return "Server is not started as clustered and does not accept benchmarks with agents defined."; | ||
| long currentTime = System.currentTimeMillis(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
still here. Please move it to the #991 PR with a test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -26,9 +26,11 @@ focus on their test scenarios. | |||
| * No CLI interactions: Running the script does not require any CLI interaction, making this scipt | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
not true at the moment: the script prompts when the output exists. It will be true again once -y is passed by default.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| @Test | ||
| public void testRunOutputDirectoryGeneratesHtmlReport(@TempDir Path tempDir) throws IOException { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
could you add a variant with an existing directory whose name has a dot? Removing the Files.isDirectory fallback doesn't fail any test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
9316c81 to
5e42eac
Compare
|
@franz1981 ready to review again |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks Diego. The ControllerVerticle change is out of the PR, #999 tracks the exit code, and the new dot-directory test does its job: if I remove the Files.isDirectory fallback, testRunOutputDirectoryWithDotInNameGeneratesHtmlReport fails. The NPE is gone too.
The main point from last round is still open, though. The NPE was a symptom; the problem is that an existing output file is no longer overwritten in non-interactive runs. With 9675c3a, readYes treats EOF as "no", so the run prints Cancelled., keeps the old file and exits 0. A script or CI job then reads the previous run's results without noticing, which I think is worse than the NPE. I built the distribution for head and master and ran each case in a fresh container with stdin from /dev/null (I put MARKER in the target file before each run):
| case | master | this PR |
|---|---|---|
run.sh -o <dir> in two fresh containers sharing <dir> (run id 0000 both times) |
2nd run overwrites 0000.html |
File .../0000.html already exists, overwrite? [y/N]: Cancelled., rc=0, old file kept |
run.sh -o r.html with an existing r.html |
overwritten | Cancelled., rc=0 |
run.sh -o x.json / -o x.csv with an existing x.json / x.zip |
(HTML) | Export cancelled., rc=0 |
printf 'y\n' | run.sh -o r.html ... |
overwritten | Cancelled. (the piped y is ignored) |
wrk.sh -o w.html / wrk2.sh -o w.html, existing file |
overwritten | Cancelled., rc=0 |
wrk.sh -o <dir> twice, fresh containers |
overwritten | Cancelled. |
any of the above with -y |
(no -y option) |
written |
run_scripts.md:26 still says the script "does not require any CLI interaction". The new ExportTest.promptingWithoutATerminalDoesNotCrash asserts the cancel-and-keep behaviour, so it locks the regression in.
Could you go back to master's behaviour for the paths the user typed, i.e. always pass -y from OutputCommandUtil? Overwrite prompts for run/wrk are a separate feature. If we want them, I'd do them in their own PR, after #999, so that a refusal exits non-zero. If the renamed foo.csv -> foo.zip must not overwrite silently, fail there with a clear message instead of prompting. Also please add a test that runs twice against the same -o file and checks that the second run wrote it. Right now nothing covers this: making OutputCommandUtil ignore -y (yesFlag = "") or always pass it (yesFlag = "-y ") leaves ExportTest, RunTest and WrkTest all green (29/29).
Smaller things:
run.sh -o /tmp/hf-0.29.1 ... gives ERROR: Unknown format '1', please use JSON or CSV with rc=0, and -o r.txt gives Unknown format 'txt'. Master writes the HTML report in both cases. Since directories and extensionless names already fall back to HTML, I'd fall back to HTML for anything other than .json/.csv/.zip too. Otherwise the message should at least mention .html.-o / still gives NullPointerException ... Path.getFileName() is null (OutputCommandUtil.java:17). It's an edge case, so up to you.-y; the actual help prints -y, --assumeYes.To reproduce the tests: mvn test -Pbenchmark -pl cli,test-suite -am -Dtest=ExportTest,RunTest,WrkTest -Dsurefire.failIfNoSpecifiedTests=false. Without -Pbenchmark, RunTest/WrkTest are skipped.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public static void executeOutputCommand(HyperfoilCommandInvocation invocation, String output, boolean assumeYes) | ||
| throws CommandException { | ||
| if (output != null && !output.isBlank()) { | ||
| String yesFlag = assumeYes ? "-y " : ""; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
master always passed -y here. Without it, an existing output file in a non-interactive run is now silently kept (Cancelled., rc=0) and the new results are lost, for run, wrk and wrk2. Please pass -y unconditionally for the paths the user typed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| switch (invocation.getShell().readLine().trim().toLowerCase()) { | ||
| String line = invocation.getShell().readLine(); | ||
| // No input available (e.g. no TTY, stdin closed/EOF): treat as "no" instead of crashing. | ||
| if (line == null) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fixing the NPE here is right in itself (EOF shouldn't crash readYes), but for run.sh -o it turns a loud failure into a silent one. The fix for the run/wrk regression belongs in OutputCommandUtil.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| CommandResult result = export.execute(invocation); | ||
|
|
||
| assertEquals(CommandResult.SUCCESS, result); | ||
| assertArrayEquals(originalContent, Files.readAllBytes(existing), "Existing file must not be overwritten"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this asserts the behaviour I'm objecting to for run.sh -o. It's fine for the standalone export command, but please also add a RunTest/WrkTest that runs twice against the same -o file and asserts the second run wrote it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| String fileName = Path.of(output).getFileName().toString(); | ||
| int dotIndex = fileName.lastIndexOf('.'); | ||
| // A directory or an extensionless name falls back to an HTML report, like on master. | ||
| String extension = (dotIndex < 0 || Files.isDirectory(Path.of(output))) ? "html" : fileName.substring(dotIndex + 1); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
an unknown extension (-o hf-0.29.1, -o r.txt) now writes nothing, rc=0. Master wrote HTML. I'd fall back to HTML here too, like for directories and extensionless names.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -26,9 +26,11 @@ focus on their test scenarios. | |||
| * No CLI interactions: Running the script does not require any CLI interaction, making this scipt | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
not true on this branch: with an existing output file the script prompts on a TTY and cancels without one.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
5e42eac to
514a01a
Compare
|
@franz1981 ready to review again:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Useexport instead of report when passing -o to run command
There was an error while loading. Please reload this page.