From cf5b9751cbef0aa00f417e17458f8f4fbd543702 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Oct 2022 10:50:24 +0400 Subject: [PATCH] [TH2-4342] Improve the information in events about the timeout --- .../th2/check1/rule/AbstractCheckTask.kt | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/exactpro/th2/check1/rule/AbstractCheckTask.kt b/src/main/kotlin/com/exactpro/th2/check1/rule/AbstractCheckTask.kt index d464ddf..8d25041 100644 --- a/src/main/kotlin/com/exactpro/th2/check1/rule/AbstractCheckTask.kt +++ b/src/main/kotlin/com/exactpro/th2/check1/rule/AbstractCheckTask.kt @@ -524,6 +524,11 @@ abstract class AbstractCheckTask( } private fun addTimeoutEvent(timeoutType: State) { + val timeoutValue: Long = when (timeoutType) { + State.TIMEOUT -> taskTimeout.timeout + State.MESSAGE_TIMEOUT -> taskTimeout.messageTimeout + else -> error("unexpected timeout state: $timeoutType") + } refs.rootEvent.addSubEventWithSamePeriod() .status(FAILED) .type( @@ -532,27 +537,34 @@ abstract class AbstractCheckTask( State.MESSAGE_TIMEOUT -> "CheckMessageTimeoutInterrupted" else -> error("unexpected timeout state: $timeoutType") } - ).name("Check task was interrupter because of ${timeoutType.name.lowercase()}") + ).name("Rule processed $handledMessageCounter message(s) and was interrupted due to $timeoutValue mls ${timeoutType.name.lowercase()}") .bodyData( createMessageBean( when (timeoutType) { - State.TIMEOUT -> - "Check task was interrupted because the task execution took longer than ${taskTimeout.timeout} mls. " + - "It might be caused by the lack of the memory or CPU resources. Check the component resources consumption" - State.MESSAGE_TIMEOUT -> - "Check task was interrupted because the timestamp on the last processed message exceeds the message timeout. " + - (checkpointTimeout - ?.toInstant() - ?.let { - "Rule expects messages between $it and ${it.plusMillis(taskTimeout.messageTimeout)} " + - "but processed one outside this range. Check the attached messages." - } ?: "But the message timeout is not specified. Contact the developers.") + State.TIMEOUT -> timeoutText() + State.MESSAGE_TIMEOUT -> messageTimeoutText() else -> error("unexpected timeout state: $timeoutType") } ) ) } + private fun messageTimeoutText(): String = "Check task was interrupted because the timestamp on the last processed message exceeds the message timeout. " + + (checkpointTimeout + ?.toInstant() + ?.let { + "Rule expects messages between $it and ${it.plusMillis(taskTimeout.messageTimeout)} " + + "but processed one outside this range. Check the messages attached to the root rule event to find all processed messages." + } ?: "But the message timeout is not specified. Contact the developers.") + + private fun timeoutText(): String = + """ + |Check task was interrupted because the task execution took longer than ${taskTimeout.timeout} mls. The possible reasons are: + |* incorrect message filter - rule didn't find a match for all requested messages and kept working until the timeout exceeded (check key fields) + |* incorrect point of start - some of the expected messages were behind the start point and rule couldn't find them (check the checkpoint) + |* lack of the resources - rule might perform slow and didn't get to the expected messages in specified timeout (check component resources) + """.trimMargin() + private fun configureRootEvent() { refs.rootEvent.name(name()).type(type()) setup(refs.rootEvent)