StyleTang commented on a change in pull request #744:
URL: https://github.com/apache/rocketmq-externals/pull/744#discussion_r667088448
##########
File path:
rocketmq-console/src/main/java/org/apache/rocketmq/console/service/impl/MessageTraceServiceImpl.java
##########
@@ -51,4 +83,94 @@
throw Throwables.propagate(err);
}
}
+
+ @Override
+ public MessageTraceGraph queryMessageTraceGraph(String key) {
+ List<MessageTraceView> messageTraceViews = queryMessageTraceKey(key);
+ return buildMessageTraceGraph(messageTraceViews);
+ }
+
+ private MessageTraceGraph buildMessageTraceGraph(List<MessageTraceView>
messageTraceViews) {
+ MessageTraceGraph messageTraceGraph = new MessageTraceGraph();
+ messageTraceGraph.setMessageTraceViews(messageTraceViews);
+ if (CollectionUtils.isEmpty(messageTraceViews)) {
+ return messageTraceGraph;
+ }
+ ProducerNode producerNode = null;
+ Map<String, Map<String, Pair<MessageTraceView, MessageTraceView>>>
messageTraceViewGroupMap = Maps.newHashMap();
+ for (MessageTraceView messageTraceView : messageTraceViews) {
+ switch (TraceType.valueOf(messageTraceView.getMsgType())) {
+ case Pub:
+ producerNode = buildMessageRoot(messageTraceView);
+ break;
+ case SubBefore:
+ case SubAfter:
+ putIntoMessageTraceViewGroupMap(messageTraceView,
messageTraceViewGroupMap);
+ break;
+ default:
+ break;
+ }
+ }
+ messageTraceGraph.setProducerNode(producerNode);
+
messageTraceGraph.setSubscriptionNodeList(buildSubscriptionNodeList(messageTraceViewGroupMap));
+ return messageTraceGraph;
+ }
+
+ private List<SubscriptionNode> buildSubscriptionNodeList(
+ Map<String, Map<String, Pair<MessageTraceView, MessageTraceView>>>
messageTraceViewGroupMap) {
+ List<SubscriptionNode> subscriptionNodeList = new
ArrayList<>(messageTraceViewGroupMap.size());
+ for (Map.Entry<String, Map<String, Pair<MessageTraceView,
MessageTraceView>>> groupTraceView : messageTraceViewGroupMap
+ .entrySet()) {
+ SubscriptionNode subscriptionNode = new SubscriptionNode();
+ subscriptionNode.setSubscriptionGroup(groupTraceView.getKey());
+ List<TraceNode> consumeNodeList = Lists.newArrayList();
+ subscriptionNode.setConsumeNodeList(consumeNodeList);
+ subscriptionNodeList.add(subscriptionNode);
+ for (Map.Entry<String, Pair<MessageTraceView, MessageTraceView>>
requestIdTracePair : groupTraceView
+ .getValue().entrySet()) {
+ MessageTraceView subBeforeTrace =
requestIdTracePair.getValue().getObject1();
+ MessageTraceView subAfterTrace =
requestIdTracePair.getValue().getObject2();
+ TraceNode consumeNode = new TraceNode();
+ consumeNode.setRequestId(requestIdTracePair.getKey());
+ consumeNode.setStoreHost(subBeforeTrace.getStoreHost());
+ consumeNode.setClientHost(subBeforeTrace.getClientHost());
+ consumeNode.setRetryTimes(subBeforeTrace.getRetryTimes());
+ consumeNode.setBeginTimeStamp(subBeforeTrace.getTimeStamp());
+ consumeNode.setCostTime(subAfterTrace.getCostTime());
+ consumeNode.setEndTimeStamp(subAfterTrace.getTimeStamp());
+ consumeNode.setStatus(subAfterTrace.getStatus());
+ consumeNodeList.add(consumeNode);
+ }
+ }
+ return subscriptionNodeList;
+ }
+
+ private void putIntoMessageTraceViewGroupMap(MessageTraceView
messageTraceView,
+ Map<String, Map<String, Pair<MessageTraceView, MessageTraceView>>>
messageTraceViewGroupMap) {
+ Map<String, Pair<MessageTraceView, MessageTraceView>>
requestIdTraceMap = messageTraceViewGroupMap
+ .computeIfAbsent(messageTraceView.getGroupName(), (o) -> new
HashMap<>(2));
Review comment:
@yuz10 @vongosling
Sorry for late response, busy with other things recently.
As **[yuz10](https://github.com/yuz10)** mentioned, the **timeStamp** and
**consumeGroup** have been deleted by this commit.
It is fine for deleting SubAfter consumeGroup because we can find consume
group from **SubBefore traceContext** by **messageId** and **requestId**
SubAfter timestamp means when consumeMessage(final List<MessageExt> msgs,
final ConsumeConcurrentlyContext context) is end, this value not
equals to timestamp+costTime and we can't find it anywhere. What is the purpose
of deleting timestamp here, can we add it back?
In my CR I already fixed the consumeGroup issue, but the end timestamp is
calculate by timestamp+costTime, maybe it is not reasonable .
--
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]