Repository navigation
Description
bin/src/cli.rs:455 documents the values --load-balancing-policy accepts as:
#[clap(
long = "load-balancing-policy",
help = "Configures the load balancing policy. Possible values are 'roundrobin', 'random' or 'leastconnections'"
)]
load_balancing_policy: LoadBalancingAlgorithms,The parser that actually consumes the value is FromStr for LoadBalancingAlgorithms
(command/src/request.rs:299-309):
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"round_robin" => Ok(LoadBalancingAlgorithms::RoundRobin),
"random" => Ok(LoadBalancingAlgorithms::Random),
"power_of_two" => Ok(LoadBalancingAlgorithms::PowerOfTwo),
"least_loaded" => Ok(LoadBalancingAlgorithms::LeastLoaded),
"hrw" => Ok(LoadBalancingAlgorithms::Hrw),
"maglev" => Ok(LoadBalancingAlgorithms::Maglev),
_ => Err(ParseErrorLoadBalancing {}),
}
}Two of the three documented values — roundrobin and leastconnections — appear in no arm. The
accepted set is round_robin, random, power_of_two, least_loaded, hrw, maglev, matched
case-insensitively (s.to_lowercase()). So the help names one value that works, two that cannot,
and omits five of the six that do.
This is not a documentation bug — the flag is unusable as documented
The field is typed LoadBalancingAlgorithms, so clap's derive resolves a FromStr-backed value
parser and the rejection happens during argument parsing, before any I/O or command-socket
connection. Measured against target/debug/sozu built from 595920e9:
$ sozu cluster add --id demo --load-balancing-policy roundrobin
error: invalid value 'roundrobin' for '--load-balancing-policy <LOAD_BALANCING_POLICY>': Cannot find the load balancing policy asked
For more information, try '--help'.
$ echo $?
2
Not a silent fallback to a default, and not a warning — a hard exit 2. And the flag is required:
$ sozu cluster add --id demo
error: the following required arguments were not provided:
--load-balancing-policy <LOAD_BALANCING_POLICY>
So a user who follows the help text cannot create a cluster at all. Every value, verified by
running the binary (empty output = accepted by the parser, which then proceeds past parsing):
| value | source | result |
|---|---|---|
roundrobin |
named in the help | rejected, exit 2 |
leastconnections |
named in the help | rejected, exit 2 |
random |
named in the help | accepted |
round_robin |
not in the help | accepted |
power_of_two |
not in the help | accepted |
least_loaded |
not in the help | accepted |
hrw |
not in the help | accepted |
maglev |
not in the help | accepted |
ROUND_ROBIN |
not in the help | accepted (to_lowercase) |
--help offers no recovery either. A FromStr-backed parser carries no value enumeration, so clap
renders no [possible values: …] line — the help string is the only list the user gets, and it is
wrong.
doc/configure_cli.md repeats it in a copy-pasteable command
The same wrong value is the getting-started recipe (doc/configure_cli.md:14-23):
First you need to create a new cluster with an id and a load balancing policy (roundrobin or random):
sozu --config /etc/sozu/config.toml cluster add --id <my_cluster_id> --load-balancing-policy roundrobin
and again at line 23 for the --http2 variant. Both commands exit 2 as written. This is the first
command in the document, so a reader following it stops at step one.
Provenance: roundrobin was orphaned by a deliberate rename in 2022
7555d383acdee72e0224685d07a827faeb94217a (2022-12-17, Tim Bart) renamed the accepted value:
match s {
- "roundrobin" => Ok(LoadBalancingAlgorithms::RoundRobin),
+ "round_robin" => Ok(LoadBalancingAlgorithms::RoundRobin),
"random" => Ok(LoadBalancingAlgorithms::Random),
+ "power_of_two" => Ok(LoadBalancingAlgorithms::PowerOfTwo),
+ "least_loaded" => Ok(LoadBalancingAlgorithms::LeastLoaded),
_ => Err(ParseErrorLoadBalancing {}),
}Its own message states the intent — "Also adjusted roundrobin to round_robin as described in
bin/config.toml" — and git show --stat confirms it touched exactly one file,
command/src/proxy.rs. bin/src/cli.rs and doc/configure_cli.md were not swept, so the help
string and the tutorial have named a value the parser rejects for three years. Both were accurate
before that commit, which is worth noting: this is a missed reference sweep, not an error made on
the day it was written.
leastconnections is different — it matches no arm at that revision either, so it appears to have
been wrong from the start.
Scope: every variant, which is why it did not ride on #1411
The wrong list is not specific to one policy. Two named values are rejected, and power_of_two,
least_loaded, hrw and maglev are all absent. Fixing it touches the CLI surface for all six
variants and is independent of any one policy's behaviour, so it did not belong in #1411's
changeset.
Suggested resolution
Two options, and they are not equivalent:
- Correct the string. Smallest change, but it re-creates the same failure mode: the help text
and theFromStrarms are two lists with nothing tying them together, which is exactly how this
drifted at7555d38. - Derive the list from the type. Making
LoadBalancingAlgorithmsa clapValueEnum(or
attaching an explicitvalue_parserwithPossibleValues) makes clap render
[possible values: …]from the same source of truth the parser uses, so the two cannot diverge
again. It also has to keepFromStrworking for the config/ctlpaths that call it directly,
and it changes the rendered help for every one of these variants — a maintainer call.
Either way doc/configure_cli.md:14-23 needs the same correction in the same changeset.
What I verified, and what I did not
Verified at 595920e91c4528f0554410b904b45d543c88e467: the help string at bin/src/cli.rs:455, the
full FromStr match at command/src/request.rs:299-309, that --load-balancing-policy is a
required argument, and every row of the table above by invoking target/debug/sozu directly. A
repo-wide grep for roundrobin / leastconnections / least_connections with no file-type filter
returns hits only in bin/src/cli.rs:455 and doc/configure_cli.md:14/17/23; every other hit is a
Rust identifier (LoadBalancingAlgorithms::RoundRobin, the RoundRobin type, the accepted
"round_robin" literal, and three test function names in lib/src/load_balancing.rs). There are no
shell completions, no man pages, and no test that asserts the rendered help — nothing else pins the
wrong list.
Not verified: I did not walk bin/src/cli.rs's full history, so I cannot say whether the help
string was edited between the flag landing and 7555d38 — only that 7555d38 did not touch it and
that leastconnections matches no arm at that revision. I also did not check whether any downstream
packaging (distribution man pages, external completions) carries the same list; nothing in this
repository does.
How it was found
While sweeping the configuration surface for POWER_OF_TWO as part of #1411, which required
grepping every place the policy names appear. The flag's help text turned out to name none of the
values that reach it.
Activity
fix(cli): name the accepted values in --load-balancing-policy help
fix(cli): name the accepted values in --load-balancing-policy help
fix(cli): name the load-balancing values the parser actually accepts (s…