Skip to content

Commit

Permalink
Use clap derive, fixing behavior of --include flag. (#121)
Browse files Browse the repository at this point in the history
* Add clap derive macros and attributes to structs

* restore default behavior of stats_file

* Use static Lazy for a Regex

* Use Tmp struct for try config, needed for results_dir

* comments

* fix typo in comment

* another typo

* Direct port of tests from builder to derive version.

Some tests now fail as a result of the new `-i` flag behavior.

* Fix broken tests to use new `-i` behavior.

* Add new test that uses built-in clap checker

* Add new test.

Verifies that the config file can come after an --include flag, and checks that a Ne filter can be properly parsed.

* Remove old code, update use paths.

* New test: checks that old `-i` behavior doesn't work

* Improve consistency between output depicted in book and actual output.

The text wrapping of the option descriptions depends on the size of the terminal window when the program is run. A wrapping length that is relatively short but leaves the descriptions in a fully separate column was chosen for the example in the book.
  • Loading branch information
OlsonZacheryFS authored May 17, 2023
1 parent 34cf53b commit fc94d5d
Show file tree
Hide file tree
Showing 5 changed files with 653 additions and 678 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ base64 = "0.21"
body_reader = { path = "./lib/body_reader" }
bytes = "1"
channel = { path = "./lib/channel" }
clap = { version = "4", features = ["cargo", "std", "help", "usage", "error-context", "wrap_help"], default-features = false }
clap = { version = "4", features = ["derive", "cargo", "std", "help", "usage", "error-context", "wrap_help"], default-features = false }
config = { path = "./lib/config" }
csv = "1"
ctrlc = "3"
Expand All @@ -39,6 +39,7 @@ hyper-tls = "0.5"
itertools = "0.10"
mod_interval = { path = "./lib/mod_interval" }
native-tls = "0.2"
once_cell = "1.17.1"
rand = "0.8"
regex = "1"
select_any = { path = "./lib/select_any" }
Expand Down
84 changes: 42 additions & 42 deletions guide/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ There are two ways that Pewpew can execute: either a full load test or a try run
<br/><br/>

```
USAGE:
pewpew <SUBCOMMAND>
The HTTP load test tool https://familysearch.github.io/pewpew
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
Usage: pewpew <COMMANND>
SUBCOMMANDS:
run Runs a full load test
try Runs the specified endpoint(s) a single time for testing purposes
Commands:
run Runs a full load test
try Runs the specified endpoint(s) a single time for testing purposes
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Prints help information
-V, --version Prints version information
```

As signified in the above help output, there are two subcommands `run` and `try`.
Expand All @@ -22,24 +24,22 @@ Here's the output of `pewpew run --help`:
<br/><br/>

```
USAGE:
pewpew run <CONFIG>
OPTIONS:
-h, --help Prints help information
-f, --output-format <FORMAT> Formatting for stats printed to stdout [default: human] [possible values:
human, json]
-d, --results-directory <DIRECTORY> Directory to store results and logs
-t, --start-at <START_AT> Specify the time the test should start at
-o, --stats-file <STATS_FILE> Specify the filename for the stats file
-s, --stats-file-format <FORMAT> Format for the stats file [default: json] [possible values: json]
-w, --watch Watch the config file for changes and update the test accordingly
ARGS:
<CONFIG> Load test config file to use
ARGS:
<CONFIG> Load test config file to use
Usage: pewpew run [OPTIONS] <CONFIG>
Arguments:
<CONFIG> Load test config file to use
Options:
-f, --output-format <FORMAT> Formatting for stats printed to stdout [default: human]
[possible values: human, json]
-d, --results-directory <DIRECTORY> Directory to store results and logs
-t, --start-at <START_AT> Specify the time the test should start at
-o, --stats-file <STATS_FILE> Specify the filename for the stats file
-s, --stats-file-format <FORMAT> Format for the stats file [default: json] [possible values:
json]
-w, --watch Watch the config file for changes and update the test
accordingly
-h, --help Prints help information
```

The `-f`, `--output-format` parameter allows changing the formatting of the stats which are printed to stdout.
Expand All @@ -54,22 +54,22 @@ Here's the output of `pewpew try --help`:
<br/><br/>

```
USAGE:
pewpew try [OPTIONS] <CONFIG>
OPTIONS:
-o, --file <FILE> Send results to the specified file instead of stdout
-f, --format <FORMAT> Specify the format for the try run output [default: human] [possible values:
human, json]
-h, --help Prints help information
-i, --include <INCLUDE>... Filter which endpoints are included in the try run. Filters work based on an
endpoint's tags. Filters are specified in the format "key=value" where "*" is
a wildcard. Any endpoint matching the filter is included in the test
-l, --loggers Enable loggers defined in the config file
-d, --results-directory <DIRECTORY> Directory to store logs (if enabled with --loggers)
ARGS:
<CONFIG> Load test config file to use
Usage: pewpew try [OPTIONS] <CONFIG>
Arguments:
<CONFIG> Load test config file to use
Options:
-o, --file <FILE> Send results to the specified file instead of stdout
-f, --format <FORMAT> Specify the format for the try run output [default: human]
[possible values: human, json]
-i, --include <INCLUDE> Filter which endpoints are included in the try run. Filters
work based on an endpoint's tags. Filters are specified in
the format "key=value" where "*" is a wildcard. Any
endpoint matching the filter is included in the test
-l, --loggers Enable loggers defined in the config file
-d, --results-directory <DIRECTORY> Directory to store logs (if enabled with --loggers)
-h, --help Prints help information
```

A try run will run one or more endpoints a single time and print out the raw HTTP requests and responses to stdout. By default all endpoints are included in the try run. This is useful for testing out a [config file](./config.md) before running a full load test. When the `--include` parameter is used, pewpew will automatically include any other endpoints needed to provide data for the explicitly included endpoints.
Expand Down
Loading

0 comments on commit fc94d5d

Please sign in to comment.