Commit af1f6229bb15eb864830fbb60a5573560c1d299c

Authored by Andrii Shvaika
1 parent 8808c268

Improved logging of failed and timeout messages

... ... @@ -161,7 +161,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
161 161 private TbActorRef createRuleNodeActor(TbActorCtx ctx, RuleNode ruleNode) {
162 162 return ctx.getOrCreateChildActor(new TbEntityActorId(ruleNode.getId()),
163 163 () -> DefaultActorService.RULE_DISPATCHER_NAME,
164   - () -> new RuleNodeActor.ActorCreator(systemContext, tenantId, entityId, ruleNode.getName(), ruleNode.getId()));
  164 + () -> new RuleNodeActor.ActorCreator(systemContext, tenantId, entityId, ruleChainName, ruleNode.getId()));
165 165 }
166 166
167 167 private void initRoutes(RuleChain ruleChain, List<RuleNode> ruleNodeList) {
... ...
... ... @@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
27 27 import org.thingsboard.server.common.data.rule.RuleNode;
28 28 import org.thingsboard.server.common.msg.queue.PartitionChangeMsg;
29 29 import org.thingsboard.server.common.msg.queue.RuleNodeException;
  30 +import org.thingsboard.server.common.msg.queue.RuleNodeInfo;
30 31
31 32 /**
32 33 * @author Andrew Shvayka
... ... @@ -38,6 +39,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod
38 39 private RuleNode ruleNode;
39 40 private TbNode tbNode;
40 41 private DefaultTbContext defaultCtx;
  42 + private RuleNodeInfo info;
41 43
42 44 RuleNodeActorMessageProcessor(TenantId tenantId, String ruleChainName, RuleNodeId ruleNodeId, ActorSystemContext systemContext
43 45 , TbActorRef parent, TbActorRef self) {
... ... @@ -46,6 +48,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod
46 48 this.self = self;
47 49 this.ruleNode = systemContext.getRuleChainService().findRuleNodeById(tenantId, entityId);
48 50 this.defaultCtx = new DefaultTbContext(systemContext, new RuleNodeCtx(tenantId, parent, self, ruleNode));
  51 + this.info = new RuleNodeInfo(ruleNodeId, ruleChainName, ruleNode != null ? ruleNode.getName() : "Unknown");
49 52 }
50 53
51 54 @Override
... ... @@ -99,6 +102,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod
99 102 }
100 103
101 104 void onRuleChainToRuleNodeMsg(RuleChainToRuleNodeMsg msg) throws Exception {
  105 + msg.getMsg().getCallback().visit(info);
102 106 checkActive(msg.getMsg());
103 107 if (ruleNode.isDebugMode()) {
104 108 systemContext.persistDebugInput(tenantId, entityId, msg.getMsg(), msg.getFromRelationType());
... ...
... ... @@ -22,11 +22,13 @@ import org.springframework.scheduling.annotation.Scheduled;
22 22 import org.springframework.stereotype.Service;
23 23 import org.thingsboard.rule.engine.api.RpcError;
24 24 import org.thingsboard.server.actors.ActorSystemContext;
  25 +import org.thingsboard.server.common.data.id.RuleNodeId;
25 26 import org.thingsboard.server.common.data.id.TenantId;
26 27 import org.thingsboard.server.common.msg.TbActorMsg;
27 28 import org.thingsboard.server.common.msg.TbMsg;
28 29 import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg;
29 30 import org.thingsboard.server.common.msg.queue.RuleEngineException;
  31 +import org.thingsboard.server.common.msg.queue.RuleNodeInfo;
30 32 import org.thingsboard.server.common.msg.queue.ServiceQueue;
31 33 import org.thingsboard.server.common.msg.queue.ServiceType;
32 34 import org.thingsboard.server.common.msg.queue.TbCallback;
... ... @@ -59,6 +61,7 @@ import javax.annotation.PreDestroy;
59 61 import java.util.Collections;
60 62 import java.util.HashSet;
61 63 import java.util.List;
  64 +import java.util.Map;
62 65 import java.util.Optional;
63 66 import java.util.Set;
64 67 import java.util.UUID;
... ... @@ -185,6 +188,12 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
185 188 }
186 189
187 190 TbRuleEngineProcessingResult result = new TbRuleEngineProcessingResult(configuration.getName(), timeout, ctx);
  191 + if (timeout) {
  192 + printFirstOrAll(configuration, ctx, ctx.getPendingMap(), "Timeout");
  193 + }
  194 + if (!ctx.getFailedMap().isEmpty()) {
  195 + printFirstOrAll(configuration, ctx, ctx.getFailedMap(), "Failed");
  196 + }
188 197 TbRuleEngineProcessingDecision decision = ackStrategy.analyze(result);
189 198 if (statsEnabled) {
190 199 stats.log(result, decision.isCommit());
... ... @@ -212,6 +221,22 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
212 221 });
213 222 }
214 223
  224 + private void printFirstOrAll(TbRuleEngineQueueConfiguration configuration, TbMsgPackProcessingContext ctx, Map<UUID, TbProtoQueueMsg<ToRuleEngineMsg>> map, String prefix) {
  225 + boolean printAll = log.isTraceEnabled();
  226 + log.info("{} to process [{}] messages", prefix, map.size());
  227 + for (Map.Entry<UUID, TbProtoQueueMsg<ToRuleEngineMsg>> pending : map.entrySet()) {
  228 + ToRuleEngineMsg tmp = pending.getValue().getValue();
  229 + TbMsg tmpMsg = TbMsg.fromBytes(configuration.getName(), tmp.getTbMsg().toByteArray(), TbMsgCallback.EMPTY);
  230 + RuleNodeInfo ruleNodeInfo = ctx.getLastVisitedRuleNode(pending.getKey());
  231 + if (printAll) {
  232 + log.trace("[{}] {} to process message: {}, Last Rule Node: {}", new TenantId(new UUID(tmp.getTenantIdMSB(), tmp.getTenantIdLSB())), prefix, tmpMsg, ruleNodeInfo);
  233 + } else {
  234 + log.info("[{}] {} to process message: {}, Last Rule Node: {}", new TenantId(new UUID(tmp.getTenantIdMSB(), tmp.getTenantIdLSB())), prefix, tmpMsg, ruleNodeInfo);
  235 + break;
  236 + }
  237 + }
  238 + }
  239 +
215 240 @Override
216 241 protected ServiceType getServiceType() {
217 242 return ServiceType.TB_RULE_ENGINE;
... ...
... ... @@ -16,8 +16,10 @@
16 16 package org.thingsboard.server.service.queue;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
  19 +import org.thingsboard.server.common.data.id.RuleNodeId;
19 20 import org.thingsboard.server.common.data.id.TenantId;
20 21 import org.thingsboard.server.common.msg.queue.RuleEngineException;
  22 +import org.thingsboard.server.common.msg.queue.RuleNodeInfo;
21 23 import org.thingsboard.server.common.msg.queue.TbMsgCallback;
22 24
23 25 import java.util.UUID;
... ... @@ -45,4 +47,10 @@ public class TbMsgPackCallback implements TbMsgCallback {
45 47 log.trace("[{}] ON FAILURE", id, e);
46 48 ctx.onFailure(tenantId, id, e);
47 49 }
  50 +
  51 + @Override
  52 + public void visit(RuleNodeInfo ruleNodeInfo) {
  53 + log.trace("[{}] ON PROCESS: {}", id, ruleNodeInfo);
  54 + ctx.visit(id, ruleNodeInfo);
  55 + }
48 56 }
... ...
... ... @@ -16,8 +16,10 @@
16 16 package org.thingsboard.server.service.queue;
17 17
18 18 import lombok.Getter;
  19 +import org.thingsboard.server.common.data.id.RuleNodeId;
19 20 import org.thingsboard.server.common.data.id.TenantId;
20 21 import org.thingsboard.server.common.msg.queue.RuleEngineException;
  22 +import org.thingsboard.server.common.msg.queue.RuleNodeInfo;
21 23 import org.thingsboard.server.gen.transport.TransportProtos;
22 24 import org.thingsboard.server.queue.common.TbProtoQueueMsg;
23 25 import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy;
... ... @@ -32,7 +34,6 @@ import java.util.concurrent.atomic.AtomicInteger;
32 34 public class TbMsgPackProcessingContext {
33 35
34 36 private final TbRuleEngineSubmitStrategy submitStrategy;
35   -
36 37 private final AtomicInteger pendingCount;
37 38 private final CountDownLatch processingTimeoutLatch = new CountDownLatch(1);
38 39 @Getter
... ... @@ -44,6 +45,8 @@ public class TbMsgPackProcessingContext {
44 45 @Getter
45 46 private final ConcurrentMap<TenantId, RuleEngineException> exceptionsMap = new ConcurrentHashMap<>();
46 47
  48 + private final ConcurrentMap<UUID, RuleNodeInfo> lastRuleNodeMap = new ConcurrentHashMap<>();
  49 +
47 50 public TbMsgPackProcessingContext(TbRuleEngineSubmitStrategy submitStrategy) {
48 51 this.submitStrategy = submitStrategy;
49 52 this.pendingMap = submitStrategy.getPendingMap();
... ... @@ -81,4 +84,13 @@ public class TbMsgPackProcessingContext {
81 84 processingTimeoutLatch.countDown();
82 85 }
83 86 }
  87 +
  88 + public void visit(UUID id, RuleNodeInfo ruleNodeInfo) {
  89 + lastRuleNodeMap.put(id, ruleNodeInfo);
  90 + }
  91 +
  92 + public RuleNodeInfo getLastVisitedRuleNode(UUID id) {
  93 + return lastRuleNodeMap.get(id);
  94 + }
  95 +
84 96 }
... ...
... ... @@ -106,7 +106,6 @@ public final class TbMsg implements Serializable {
106 106 if (callback != null) {
107 107 this.callback = callback;
108 108 } else {
109   - log.warn("[{}] Created message with empty callback: {}", originator, type);
110 109 this.callback = TbMsgCallback.EMPTY;
111 110 }
112 111 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.common.msg.queue;
  17 +
  18 +import org.thingsboard.server.common.data.id.RuleNodeId;
  19 +
  20 +public class RuleNodeInfo {
  21 + private final String label;
  22 +
  23 + public RuleNodeInfo(RuleNodeId id, String ruleChainName, String ruleNodeName) {
  24 + this.label = "[RuleChain: " + ruleChainName + "|RuleNode: " + ruleNodeName + "(" + id + ")]";
  25 + }
  26 +
  27 + @Override
  28 + public String toString() {
  29 + return label;
  30 + }
  31 +}
\ No newline at end of file
... ...
... ... @@ -34,4 +34,7 @@ public interface TbMsgCallback {
34 34
35 35 void onFailure(RuleEngineException e);
36 36
  37 + default void visit(RuleNodeInfo ruleNodeInfo) {
  38 + }
  39 +
37 40 }
... ...