Frun1na opened a new issue, #6773:
URL: https://github.com/apache/rocketmq-dashboard/issues/6773

   ### Before Creating the Bug Report
   
   - [x] I have searched the [open 
issues](https://github.com/apache/rocketmq-dashboard/issues) of this repository 
and believe that this is not a duplicate.
   - [x] This is a defect in RocketMQ Studio, not a usage question and not a 
defect in another Apache RocketMQ repository.
   - [x] I can reproduce this on the current `rocketmq-studio` branch, or I 
have stated the exact version I am running below.
   
   ### Studio Version
   
   branch: rocketmq-studio
   git commit id: a92c2314
   deployed as: reproduced by a unit test against that commit
   
   ### Runtime Environment
   
   OS: not applicable — the defect is in the instance service and the view it 
serialises
   MySQL: not applicable — the defect reproduces without a database, with a 
stubbed repository
   browser (for UI issues): not required to observe it; the defect is in the 
endpoint response
   
   ### Connected RocketMQ Cluster
   
   not applicable — reproduced with a stubbed provider in a unit test
   
   ### Describe the Bug
   
   `POST /api/instances/create` and `POST /api/instances/update` answer with 
`topicCount: 0`, `consumerGroupCount: 0` and `resourceCountsAvailable: true`, 
i.e. they present counts that were never measured as trustworthy zeros.
   
   `docs/api-spec.md` §3.1 defines the field as "上面两个计数是否可信;`false` 
表示未请求或解析失败,此时不应把 `0` 当成真实数量", and §3.2 / §3.3 declare the same `Instance` 
object as their response `data`.
   
   The counts are not columns on the row. `MybatisPlusInstanceRepository.toVO` 
never populates them and `schema.sql` has no such field, so they are resolved 
per request and only by `InstanceService.listInstances`:
   
   ```java
   private static void applyCounts(InstanceVO instance, ResourceCounts counts) {
       instance.setTopicCount(counts.topicCount());
       instance.setConsumerGroupCount(counts.consumerGroupCount());
       instance.setResourceCountsAvailable(true);
   }
   
   private static void clearCounts(InstanceVO instance) {
       instance.setTopicCount(0);
       instance.setConsumerGroupCount(0);
       instance.setResourceCountsAvailable(false);
   }
   ```
   
   Neither write path goes through those. `createInstance` never resolves 
counts and returns what `save` produced; `updateInstance` builds its response 
with `copyOf(existing)`, whose `existing` came from `findById` and therefore 
also carries the read-back zeros. Both values are then serialised with 
`InstanceVO`'s builder default:
   
   ```java
   @Builder.Default
   private boolean resourceCountsAvailable = true;
   ```
   
   So the only claim the response makes about the two numbers is the one it 
cannot support. A client that follows the documented contract — trust the 
counts when the flag is `true` — reads "this instance has 0 topics and 0 
consumer groups" for an instance whose cluster may hold hundreds, including on 
a cloud instance where nothing was ever counted.
   
   `listInstances` itself is correct: it marks the counts unavailable both when 
`withCounts` was not requested and when resolution failed.
   
   ### Steps to Reproduce
   
   ```text
   POST /api/instances/update  {"id": "<an existing instance>", "name": "<same 
name>", "remark": "x"}
   ```
   
   or, as a unit test against `InstanceService`:
   
   ```java
   when(instanceRepository.findById(1L)).thenReturn(Optional.of(existing));
   when(instanceRepository.save(any(InstanceVO.class))).thenAnswer(inv -> 
inv.getArgument(0));
   
   InstanceVO updated = instanceService.updateInstance(request);
   assertThat(updated.isResourceCountsAvailable()).isFalse();   // fails: 
"Expecting value to be false but was true"
   ```
   
   Inspecting the JSON of `POST /api/instances/create` with a fresh name shows 
the same pair.
   
   ### What Did You Expect to See?
   
   `resourceCountsAvailable: false` on both write responses, the way `GET 
/api/instances` already answers when `withCounts` is not requested — the flag 
saying whether the two numbers can be trusted, and a zero that nobody measured 
not being presented as a measured count.
   
   ### What Did You See Instead?
   
   `resourceCountsAvailable: true` with `topicCount: 0` and 
`consumerGroupCount: 0`, so a caller that honours the documented contract reads 
a fabricated zero.
   
   ### Additional Context
   
   A fix with a regression test follows in a pull request.
   
   ### Are You Willing to Submit a Pull Request?
   
   - [x] Yes, I am willing to submit a pull 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to