Skip to content

[Studio][Bug] An alert-rule update cannot clear an optional column: the response reports it cleared but the stored rule keeps the old value #4783

Closed

Description

@unbridled-41

Studio Version

Trunk rocketmq-studio @ 4c697f07 (line references are as of that commit).

Problem

POST /api/alert-rules/update and POST /api/cluster-alert-rules/update replace every editable field of a rule, but an update body that simply omits an optional field does not clear it. MybatisPlusAlertRepository.replaceRule (server/src/main/java/org/apache/rocketmq/studio/ops/alert/MybatisPlusAlertRepository.java:141-146) builds the entity with toRuleEntity and calls ruleMapper.updateById(entity). MyBatis-Plus's default NOT_NULL update strategy omits null entity fields from the UPDATE's SET clause, so the previous value silently survives.

The service path makes the mismatch worse: AlertService.updateRule (AlertService.java:190-223) validates the submitted VO, replaces the stored rule, and returns the submitted VO. So the API responds with the field cleared (consumerGroup: null, severity: null, ...), the UI renders the cleared value, and the next GET shows the old value back.

Fields affected (all nullable in rmq_alert_rule, all accepted-as-null by NativeAlertRulePolicy.validate and AlertRuleRequestDTO): thresholdUnit, duration, channels, description, brokerName, clusterName, severity, instanceId (for Prometheus-rule metrics only — native metrics require it), consumerGroup, topic, notificationTemplate.

A concrete failure: a business consumer.lag.total rule scoped to consumerGroup="G1" cannot be re-scoped to all groups through the update API. The stale filter keeps narrowing alert evaluation while the operator believes it was removed.

Evidence

  1. NativeAlertRulePolicy.validate only rejects a missing instanceId for native metrics (NativeAlertRulePolicy.java:66-71); a null consumerGroup/topic/severity/duration passes (AlertRuleDuration.parse(null) returns ZERO).
  2. replaceRule → ruleMapper.updateById(toRuleEntity(rule)) with the entity's optional fields null — MyBatis-Plus skips them in the SET clause (no global update-strategy override in application.yml, no @TableField(updateStrategy=...) on RmqAlertRule).
  3. The codebase already documents this exact behaviour for the sibling path and works around it: NameserverRegistryService.clearOmittedOptionalColumns (cluster/nameserver/NameserverRegistryService.java:147-172, merged PR fix(studio): persist cleared optional instance and registry fields #4466, "MyBatis-Plus updateById omits null entity fields... assign those columns explicitly"), and MybatisPlusInstanceRepository.java:128-131 does the same for a cleared credential reference. The alert-rule path is the one missing it.

Impact

  • Scope filters (instanceId/consumerGroup/topic/brokerName/clusterName) cannot be cleared, so alerts keep evaluating against a stale narrower scope than the UI shows.
  • severity/duration/channels/notificationTemplate/description silently revert to their previous values after an update that omitted them, contradicting the 200 response.
  • The silent divergence between the response and the stored row is undetectable from the client.

Expected behavior

An update that omits an optional field clears it, and the stored rule matches the response — the same contract the registry and instance paths already implement.

Related work

PR

Fix: #4784.

Activity

  1. RockteMQ-AI commented on Sep 21, 2026

    @RockteMQ-AI

    Evaluation

    Classification: Bug — MyBatis-Plus NOT_NULL update strategy prevents clearing optional fields
    Severity: MEDIUM-HIGH
    Status: ✅ Confirmed

    Verification

    Code references verified against rocketmq-studio @ 4c697f07:

    • MybatisPlusAlertRepository.replaceRule (lines 141-146): ruleMapper.updateById(toRuleEntity(rule)) — MyBatis-Plus default NOT_NULL strategy omits null fields from the UPDATE SET clause.
    • AlertService.updateRule (lines 190-223): validates, replaces, then returns the submitted VO — API response shows cleared fields, but the database retains stale values.
    • Precedent: NameserverRegistryService.clearOmittedOptionalColumns (fix(studio): persist cleared optional instance and registry fields #4466) and MybatisPlusInstanceRepository (lines 128-131) already work around this exact MyBatis-Plus behavior for other paths. The alert-rule path is the remaining gap.

    Impact

    • Scope filters (consumerGroup, topic, brokerName, clusterName, instanceId) cannot be cleared via the update API — alerts keep evaluating against a stale narrower scope.
    • severity/duration/channels/notificationTemplate/description also cannot be cleared.
    • The API response lies: it reports the field as cleared while the database retains the old value.

    Cluster Context

    This is the same MyBatis-Plus NOT_NULL defect class as #4272 (topic remark), #4273 (admin credential, HIGH security), #4274 (NameServer fields). The alert-rule path is another instance.

    Associated PR

    PR #4784 (by @unbridled-41) — fix: persist cleared optional columns when an alert-rule update omits them.


    Evaluated by github-manager bot

  2. lizhimins commented on Sep 24, 2026

    @lizhimins
    Member

    Fixed in 6ef2f2d (#4784) on the rocketmq-studio branch.

    Closing manually: GitHub only auto-closes an issue when the pull request is merged into the repository's default branch, and rocketmq-studio is not it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions