orangeCatDeveloper opened a new pull request, #4311:
URL: https://github.com/apache/hertzbeat/pull/4311
## What's changed?
Fixes #1693: zookeeper monitors fail with "The cmd execution results do not
match the expected number of metrics", with no way to tell why. The issue
contains two distinct situations behind the same message: a 4lw whitelist that
blocks `conf` (reporter leim, bitnami defaults), and a healthy standalone
zookeeper 3.4.14 whose `conf` simply returns fewer keys than the template
defines (reporter ZachariahHu).
Root cause: `TelnetCollectImpl` fails the whole metrics group whenever
parsed entries < expected fields, and drops the raw telnet reply during parsing
— so valid partial data is discarded, and zookeeper's own refusal text never
reaches the user:
```java
if (resultMap.size() < aliasFields.size()) {
builder.setMsg("The cmd execution results do not match the expected
number of metrics.");
return;
}
```
The fix moves the failure criterion from "how many entries came back" to
"did any expected field come back". Parsing now returns the raw reply alongside
the parsed map (`CmdResult` record). If the reply contains at least one
expected field, the row is built as usual and missing fields fall through to
the existing null-padding path. Only when none of the expected fields are
present does the group fail — and the message now carries the sanitized raw
reply, so a whitelist refusal is shown verbatim. Matching by expected fields
(rather than "map is non-empty") keeps refusal text that happens to parse as
key/value, e.g. `error=conf disabled`, on the failure path.
Parsing is also hardened where the relaxed check would otherwise hide data:
values are split at the first separator only (`split(sep, 2)`), so
`dataDir=/data/zk=a` no longer loses the row; duplicate keys keep the first
value instead of throwing; header-only or newline-only replies no longer hit
`lines[0]` on an empty array.
### Whitelist refusal (reporter leim's case)
zookeeper with `4lw.commands.whitelist=srvr`, before:
```
ERROR TelnetCollectImpl - telnet response data not enough: {responseTime=18}
```
after — the reason is finally visible, in logs and in the UI popup:
```
WARN TelnetCollectImpl - telnet cmd [conf] returned no expected metrics:
conf is not executed because it is not in the whitelist.
```
### Partial reply (reporter ZachariahHu's case)
zookeeper 3.4.14 standalone — its `conf` returns 8 keys while the template
defines 10 (`dataDirSize`/`dataLogSize` only exist in newer versions). Before,
the whole group is discarded every cycle:
```
ERROR TelnetCollectImpl - telnet response data not enough:
{maxSessionTimeout=40000, dataDir=/data/version-2, responseTime=7,
clientPort=2181, tickTime=2000, minSessionTimeout=4000,
dataLogDir=/datalog/version-2, serverId=0, maxClientCnxns=60}
```
after, same server, collected without errors:
```json
{"clientPort": "2181", "dataDir": "/data/version-2", "dataDirSize": null,
"dataLogDir": "/datalog/version-2", "dataLogSize": null, "tickTime": "2000",
"maxClientCnxns": "60", "minSessionTimeout": "4000",
"maxSessionTimeout": "40000", "serverId": "0"}
```
A truncated reply that still contains some expected fields is now
indistinguishable from version variance and yields null cells instead of a hard
failure — the visible gaps (and thresholds on them) are the signal in that
case. zookeeper 3.9 with an open whitelist collects all 10 columns unchanged.
## Checklist
- [x] I have read the [Contributing
Guide](https://hertzbeat.apache.org/docs/community/code_style_and_quality_guide)
- [x] I have written the necessary doc or comment.
- [x] I have added the necessary unit tests and all cases have passed.
## Add or update API
- [ ] I have added the necessary [e2e
tests](https://github.com/apache/hertzbeat/tree/master/e2e) and all cases have
passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]