Sitelet https://github.com/apache/hertzbeat/pull/4330
Skip to content

[fix] allow long threshold expr when binding many monitors - #4330

Open
orangeCatDeveloper wants to merge 8 commits into
apache:masterfrom
orangeCatDeveloper:fix/issue-4171-expr-length
Open

[fix] allow long threshold expr when binding many monitors#4330
orangeCatDeveloper wants to merge 8 commits into
apache:masterfrom
orangeCatDeveloper:fix/issue-4171-expr-length

Conversation

@orangeCatDeveloper

Copy link
Copy Markdown
Contributor

Fixes #4171

Binding more than ~30 monitors to one alert rule fails with a validation error, because each bound monitor appends an equals(__instance__, "...") clause (~65 chars) to the threshold expr, and the field was capped at 2048 characters — 2048 / 65 ≈ 30 bindings.

The fix widens AlertDefine.expr from @Size(2048)/@Column(2048) to @Lob with a @Size(65535) validation cap — the same pattern the codebase already uses for NoticeTemplate.content. Migration V182 alters the column on all three vendors (mysql longtext with an INFORMATION_SCHEMA idempotency guard matching V172/V180, postgresql TEXT, h2 CLOB); widening is lossless for existing rows. The custom validation message was deliberately dropped so the default hibernate-validator message stays localized.

Backward compatible: previously valid input remains valid, the new 65535 cap still rejects runaway payloads, and expr is admin-authored config so no new trust boundary.

Verified end-to-end against a real backend (fresh H2, Successfully applied 7 migrations ... now at version v182):

before (2048 cap):
  POST expr=1501 chars (35 bindings)  -> {"code":0,"msg":"Add success"}
  POST expr=2296 chars (50 bindings)  -> {"code":1,"msg":"Size.alertDefine.expr:size must be between 0 and 2048"}
                                          (verbatim the error reported in the issue)

after (lob + 65535 cap):
  POST the same 2296-char expr        -> {"code":0,"msg":"Add success"}
  read back                           -> expr length 2296, stored intact
  POST 65536 chars                    -> {"code":1,"msg":"Size.alertDefine.expr:size must be between 0 and 65535"}

@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/issue-4171-expr-length branch from a5a8100 to b31d988 Compare August 17, 2026 12:13
Binding monitors appends an equals(__instance__, ...) clause per monitor
to the threshold expr, so the 2048-char limit capped bindings at ~30.
Widen expr to a lob with a 65535 validation cap (V182).
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/issue-4171-expr-length branch from b31d988 to 69547ff Compare August 18, 2026 06:22

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: allow long threshold expr when binding many monitors

Clean, well-migrated fix for #4171 (binding >~30 monitors to one rule failed validation).

What's good

  • AlertDefine.expr is widened from @Size(max=2048) @Column(length=2048) to @Lob with a @Size(max=65535) validation cap — the same pattern the codebase already uses for NoticeTemplate.content. Previously valid input stays valid; the new 65535 cap still rejects runaway payloads. expr is admin-authored config, so this widens no new trust boundary.
  • Migrations V182 for all three vendors are correct and idempotent:
    • MySQL: a stored procedure guarded by INFORMATION_SCHEMA (table exists, column exists, and DATA_TYPE != 'longtext') then ALTER ... MODIFY COLUMN expr LONGTEXT — matching the existing V172/V180 style, so re-running is a no-op.
    • PostgreSQL: ALTER COLUMN expr TYPE TEXT — lossless widen.
    • H2: ALTER COLUMN expr CLOB.
  • Tests pin both directions: a 76-monitor-binding expr (>2048 chars) validates cleanly, and a 65536-char expr fails with exactly one violation on expr (the custom message was intentionally dropped so the default localized hibernate-validator message is used).
  • Backward compatible: existing rows are widened losslessly, and the PR's e2e trace confirms a 2296-char expr now persists intact.

Non-blocking note

  • MySQL longtext can hold far more than 65535 chars, but the @Size(65535) validation is the effective ceiling, so there's no practical over-allocation concern.

No blocking issues. Approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] <title>Association monitoring: Cannot add more than 30 monitoring items (Size.alertDefine.expr 0-2048)

2 participants