You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "btlqql (via GitHub)" <gi...@apache.org> on 2026/09/21 07:00:01 UTC

[PR] fix(message): validate the time window of a unique-key lookup [rocketmq-dashboard]

btlqql opened a new pull request, #4695:
URL: https://github.com/apache/rocketmq-dashboard/pull/4695

   <!-- Base branch: `rocketmq-studio`, the RocketMQ Studio trunk. -->
   
   ### Brief Description
   
   `MessageService.queryMessageByUniqueKey` (the UNIQ_KEY lookup behind the `rmq.message.query` AI
   tool, `MessageQueryToolHandler`) forwarded `startTime`/`endTime` to the provider unvalidated. Every
   other message query rejects a broken window in the service - `queryMessages` via
   `validateTopicQueryWindow` ("message query timestamps must not be negative", "startTime must be
   before endTime"), and `RocketMQMessageProvider` re-checks `begin >= end` for the topic/key branches:
   
   ```java
   // MessageService.java:71 (before)
   if (!StringUtils.hasText(uniqueKey)) {
       throw new BusinessException(400, "uniqueKey is required");
   }
   log.info("Querying message by unique key: topic={}, uniqueKey={}", topic, uniqueKey);
   return messageProvider.queryMessageByUniqueKey(instanceId, topic, uniqueKey, startTime, endTime);
   ```
   
   The unique-key branch is the one path with no guard on either layer
   (`RocketMQMessageProvider.queryMessageByUniqueKey` only defaults a missing endpoint and then calls
   `adminExt.queryMessageByUniqKey(..., begin, end)`), so an inverted window was sent to the broker as
   an inverted range: the broker answers `NO_MESSAGE`, the provider maps that to an empty list and the
   caller is told "no messages found" for a request that was really malformed. A negative timestamp
   queried the store from epoch-1 in the same way.
   
   The window is now validated before the provider is called, reusing the messages the topic path
   already returns. The window itself stays optional: a UNIQ_KEY lookup without a window still
   delegates unchanged (the provider keeps its own default recent range), and a single-sided window is
   still accepted.
   
   ### How Did You Test This Change?
   
   New tests in `MessageServiceTest` (`uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest`,
   `uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest`, plus
   `uniqueKeyQueryKeepsTheTimeWindowOptionalTest` / `uniqueKeyQueryAcceptsASingleSidedTimeWindowTest` as
   guards that the window stays optional).
   
   Before the fix (red) - the service returned `null` from the mock provider instead of rejecting the
   window:
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MessageServiceTest
   [ERROR] Tests run: 23, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 2.178 s <<< FAILURE! -- in org.apache.rocketmq.studio.instance.message.MessageServiceTest
   [ERROR] org.apache.rocketmq.studio.instance.message.MessageServiceTest.uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest -- Time elapsed: 0.029 s <<< FAILURE!
   [ERROR] org.apache.rocketmq.studio.instance.message.MessageServiceTest.uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest -- Time elapsed: 0.005 s <<< FAILURE!
   [ERROR]   MessageServiceTest.uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest:364
   [ERROR]   MessageServiceTest.uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest:378
   Expecting code to raise a throwable.
   ```
   
   After the fix (green) - the whole class:
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MessageServiceTest
   [INFO] Tests run: 23, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   `mvn test` runs checkstyle in the `validate` phase: `You have 0 Checkstyle violations.`
   
   Note on the full suite: on a clean `rocketmq-studio` checkout `mvn -B -ntp test` already reports
   `Tests run: 3051, Failures: 6, Errors: 25, Skipped: 4`. The 11 red classes are the MySQL 8 backed
   Spring integration tests (`AuthServiceBootstrapIntegrationTest`,
   `AuthServiceConcurrencyIntegrationTest`, `AuthServiceSessionOverviewIntegrationTest`,
   `HealthProbeIntegrationTest`, `QueryHistoryServiceIntegrationTest`,
   `NativeAlertEvaluationTransactionTest`, `NotificationOutboxMapperIntegrationTest`,
   `RmqAlertStateMapperIntegrationTest`, `StudioApplicationTest`) plus the external-CLI ones
   (`CliAgentProviderTest`, `ClaudeCodeAgentProviderTest`). None of them are touched by this change.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`fix:`)
   - [x] Tests added or updated for non-trivial changes, test methods named `...Test`
   - [x] New UI text has both Chinese and English entries under `web/src/i18n/` (no UI text in this change)
   - [x] Architecture constraints stay green (`mvn test` runs the ArchUnit checks)
   - [x] New source files carry the ASF license header (no new files)
   - [x] Documentation touched where behaviour changed (no user-visible contract change: a malformed time window was never a supported request)
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(message): validate the time window of a unique-key lookup [rocketmq-dashboard]

Posted by "btlqql (via GitHub)" <gi...@apache.org>.
btlqql commented on PR #4695:
URL: https://github.com/apache/rocketmq-dashboard/pull/4695#issuecomment-5757218634

   Closing this as superseded by #4717, which now covers the same defect for both lookups in one place:
   
   - the key branch of `MessageService.queryMessages` (the `validateTopicQueryWindow` early bail-out), and
   - `MessageService.queryMessageByUniqueKey` (which does not call `validateTopicQueryWindow` at all - the reason this PR existed).
   
   Both callers now share a single private helper, `MessageService.validateProvidedTimeWindow`, so there is one implementation of the rule and one place to change it. This PR's tests were carried over to #4717 unchanged (`uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest`, `uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest`, plus `uniqueKeyQueryKeepsTheTimeWindowOptionalTest` / `uniqueKeyQueryAcceptsASingleSidedTimeWindowTest`), and the unique-key half was re-verified red on that branch with only that guard removed.
   
   The two PRs also could not both merge: each added its helper at `MessageService.java` line ~204 and inserted its test at the same `MessageServiceTest.java` anchor, so whichever landed second would have conflicted textually. Keeping one PR is the honest resolution.


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(message): validate the time window of a unique-key lookup [rocketmq-dashboard]

Posted by "btlqql (via GitHub)" <gi...@apache.org>.
btlqql commented on PR #4695:
URL: https://github.com/apache/rocketmq-dashboard/pull/4695#issuecomment-5756701812

   Neighbouring suites were run on the same commit as extra evidence:
   
   ```
   $ cd server && mvn -B -ntp test -Dtest='MessageControllerTest,QueryHistoryServiceTest,DLQServiceTest,DLQControllerTest'
   [INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 -- in org.apache.rocketmq.studio.instance.message.MessageControllerTest
   [INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0 -- in org.apache.rocketmq.studio.instance.message.QueryHistoryServiceTest
   [INFO] Tests run: 17, Failures: 0, Errors: 0, Skipped: 0 -- in org.apache.rocketmq.studio.instance.dlq.DLQServiceTest
   [INFO] Tests run: 24, Failures: 0, Errors: 0, Skipped: 0 -- in org.apache.rocketmq.studio.instance.dlq.DLQControllerTest
   [INFO] Tests run: 59, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(message): validate the time window of a unique-key lookup [rocketmq-dashboard]

Posted by "btlqql (via GitHub)" <gi...@apache.org>.
btlqql closed pull request #4695: fix(message): validate the time window of a unique-key lookup
URL: https://github.com/apache/rocketmq-dashboard/pull/4695


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org