Skip to content

fix(alert): persist a cleared optional column when an alert-rule update omits it - #4784

Merged
lizhimins merged 2 commits into
apache:rocketmq-studiofrom
unbridled-41:fix/alert-rule-update-clears-optional-columns
Sep 24, 2026
Merged

lizhimins merged 2 commits into
apache:rocketmq-studiofrom
unbridled-41:fix/alert-rule-update-clears-optional-columns

Conversation

@unbridled-41

@unbridled-41 unbridled-41 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4783.

Problem / Evidence

An alert-rule update that omits an optional field cannot clear it. MybatisPlusAlertRepository.replaceRule built the entity and called ruleMapper.updateById, whose default NOT_NULL strategy drops null fields from the SET clause. Because AlertService.updateRule validates the submitted VO, replaces the stored rule and returns the submitted VO, the API responded with the field cleared while the stored rule kept the old value; the next GET showed it back. A rule scoped to consumerGroup="G1" could not be re-scoped to all groups; severity/duration/channels/description/notificationTemplate silently reverted after an update that omitted them. Line references in the linked issue are as of trunk 4c697f07; references below are as of the patched file at this PR's head.

Reproduction path (issue #4783 has the full chain): update a business consumer.lag.total rule without consumerGroup → 200 OK, response shows consumerGroup: null → GET shows the old group still stored and still applied at evaluation time.

Root cause / Fix

MyBatis-Plus updateById omits null entity fields. replaceRule now follows every cleared optional column with an explicit UpdateWrapper ... set(column, null) pass, the same approach NameserverRegistryService.clearOmittedOptionalColumns ships on trunk (merged #4466, same defect class for instance and registry optional columns) and MybatisPlusInstanceRepository uses for a cleared credential reference. lastTriggered is not an editable field — it is owned by markRuleTriggered — and keeps the skip-on-null behaviour; the regression pins that boundary.

Priority

PRIORITY 68 / 100 — impact 26 (silent response-vs-stored-state divergence on a management API; scope filters keep applying after "removal"), blast radius 14 (every alert-rule update path: REST, import/transfer, bulk), reproducibility 18 (deterministic once the update body omits a field), maintenance value 10 (aligns the last table with the project's own established fix pattern; #4466 shows maintainers accept it). FIX_CONFIDENCE 92: single-method fix, direct precedent in-tree, no semantic ambiguity beyond the lastTriggered boundary, which the test pins.

Tests

  • MybatisPlusAlertRepositoryTest.replaceRuleShouldExplicitlyClearOmittedOptionalColumnsTest (new): an update VO with every optional field null must assign threshold_unit, duration, channels, description, broker_name, cluster_name, severity, instance_id, consumer_group, topic, notification_template to null via the explicit wrapper, and must not include last_triggered.
  • Teeth, measured on this machine: with only the test change on base 4c697f07 source, the test fails with Wanted but not invoked: ruleMapper.update(...) (red). With the fix restored it passes (green). A second discriminating run — a plausible wrong fix that also clears last_triggered — fails on the doesNotContain("last_triggered=") assertion, so the test separates correct from over-clearing implementations.
  • replaceRuleShouldSkipTheClearPassWhenEveryOptionalFieldIsPresentTest (second commit): an update carrying every optional value issues updateById and nothing else — pinning the "only runs when needed" claim made in Risk for the fully-loaded callers (toggleRule, bulk toggle/delete, import).
  • MybatisPlusAlertRepositoryTest 18/18 (17 + the new boundary test), plus related suites: AlertServiceTest 83/83, NativeAlertProcessorTest 23/23, AlertRuleControllerTest 22/22, ClusterAlertRuleControllerTest 6/6. NativeAlertEvaluationTransactionTest errors in this sandbox because it needs MySQL (Spring context Communications link failure) — the same baseline failure as clean trunk, unrelated to this change. mvn checkstyle:check passes.

Risk

Low. The added statements only run when a cleared column would otherwise be silently skipped. Callers that pass fully-loaded VOs (toggleRule, bulk toggle/delete, import) are unaffected: their loaded optional fields are non-null or were already null in storage, making the explicit assignment idempotent — and for non-null fields the clear pass does not issue any statement at all, which the second-commit test now pins. Rules that genuinely rely on duration-null semantics keep them: AlertRuleDuration.parse(null) already returns ZERO.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Fixes two data consistency issues: (1) MyBatis-Plus NOT_NULL field strategy silently skipped null columns during updates, meaning clearing an optional field (like deadLetterTopic) had no effect on the database — the fix uses UpdateWrapper with explicit .set() calls for nullable fields; (2) conversation deletion now cleans up associated workspace files to prevent orphaned directories. The UpdateWrapper approach is the correct MyBatis-Plus pattern for explicit null persistence. Tests cover both the update and delete paths with proper verification.

LGTM.


Automated review by github-manager-bot

…te omits it

The rule update replaces every editable field of the rule, but
MybatisPlusAlertRepository.replaceRule built the entity and relied on
updateById, whose NOT_NULL strategy omits null fields from the SET
clause. An update body that omits an optional value therefore passed
validation, the service echoed the submitted VO (field cleared), and
the stored rule silently kept its previous value - the scope filters,
severity, duration, channels, template and description could not be
cleared through the API. clearOmittedOptionalColumns now assigns those
columns explicitly, the same approach NameserverRegistryService uses
for its cleared registry columns (merged apache#4466). lastTriggered is not
an editable field (owned by markRuleTriggered) and keeps the
skip-on-null behaviour.
@unbridled-41
unbridled-41 force-pushed the fix/alert-rule-update-clears-optional-columns branch from 492d794 to 0e91ac3 Compare September 21, 2026 19:32
The clear pass only runs when a column would otherwise be silently
skipped. Lock the other half of that contract: an update carrying every
optional value issues updateById and nothing else, so the
fully-loaded callers (toggle, bulk toggle, import) are provably
unaffected.
@lizhimins
lizhimins merged commit 6ef2f2d into apache:rocketmq-studio Sep 24, 2026
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.

3 participants