orangeCatDeveloper opened a new pull request, #4307: URL: https://github.com/apache/hertzbeat/pull/4307
## What's changed? Fixes #1562: threshold rules referencing a field that is sometimes empty (e.g. fullsite `errorMsg`) never fire. The JEXL engine runs with `strict(true)`, which throws on **undefined variables**. The calculator's row loop skipped empty strings (and unparseable number/time values) when building the expression variable map, so a rule like ``` !matches(statusCode,"^2[0-9]+") && !contains(errorMsg,"timed out") ``` aborted entirely on every healthy-page row where `errorMsg` is `""` — including the 404 rows it should have caught. The regression came in with #1478 (v1.4.4), which turned a logged-and-ignored evaluation error into a hard abort; the Aviator→JEXL swap (#1859) and the alarm refactor (#2902) both preserved the same semantics, only changing the error text (which is why the reporter saw different messages on v1.5.0 and v1.6.0). Fix: always define every field in the variable map — strings keep their value (including `""`), unparseable number/time values become `null`, matching the existing `NULL_VALUE` handling. The expression functions (`contains`/`matches`/`equals`/`exists`) are already null-safe, so no other change is needed. Unparseable numerics are normalized to `NULL_VALUE` by the collector before reaching the alerter, so the number/time branches are a consistency hardening rather than a behavior change. Not covered (separate concerns): the zero-row case when the sitemap endpoint returns an empty body (nothing to evaluate per-URL; needs a collector-side decision), and the Firefox threshold-editor freeze mentioned in the issue (frontend). Verified end-to-end with an nginx site whose sitemap contains one healthy page and one 404, using the issue's exact rule: **before** — no alert, every collect cycle logs: ``` ERROR JexlExprCalculator - Alarm Rule: ... !contains(errorMsg,"timed out") ... Run Error: ...JexlExpressionRunner.compile:84 variable 'errorMsg' is undefined. ``` **after** — no errors, the 404 page alerts precisely: ``` "content": "site page down: http://hb1562-target/missing.html status 404", "status": "firing" ``` ## 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]
