-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TH2-4316] Add additional events to the root event with information a… #173
Open
OptimumCode
wants to merge
3
commits into
dev
Choose a base branch
from
th2-4316
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -70,6 +70,9 @@ import java.util.concurrent.ForkJoinPool | |||||
import java.util.concurrent.TimeUnit.MILLISECONDS | ||||||
import java.util.concurrent.atomic.AtomicBoolean | ||||||
import java.util.concurrent.atomic.AtomicReference | ||||||
import com.exactpro.th2.check1.utils.toMessageID | ||||||
import com.exactpro.th2.common.event.EventUtils.createMessageBean | ||||||
import com.exactpro.th2.common.util.toInstant | ||||||
|
||||||
/** | ||||||
* Implements common logic for check task. | ||||||
|
@@ -152,7 +155,7 @@ abstract class AbstractCheckTask( | |||||
@Volatile | ||||||
protected var started = false | ||||||
|
||||||
protected fun createRootEvent() = Event.from(submitTime).description(description) | ||||||
protected fun createRootEvent(): Event = Event.from(submitTime).description(description) | ||||||
|
||||||
final override fun onStart() { | ||||||
super.onStart() | ||||||
|
@@ -170,7 +173,7 @@ abstract class AbstractCheckTask( | |||||
super.onError(e) | ||||||
|
||||||
refs.rootEvent.status(FAILED) | ||||||
.bodyData(EventUtils.createMessageBean(e.message)) | ||||||
.exception(e, true) | ||||||
end(State.ERROR, "Error ${e.message} received in message stream") | ||||||
} | ||||||
|
||||||
|
@@ -311,6 +314,7 @@ abstract class AbstractCheckTask( | |||||
this.checkpointTimeout = calculateCheckpointTimeout(checkpointTimestamp, taskTimeout.messageTimeout) | ||||||
this.isDefaultSequence = sequence == DEFAULT_SEQUENCE | ||||||
val scheduler = Schedulers.from(executorService) | ||||||
addStartInfo(refs.rootEvent.addSubEventWithSamePeriod(), sequence, checkpointTimestamp) | ||||||
|
||||||
endFuture = Single.timer(taskTimeout.timeout, MILLISECONDS, Schedulers.computation()) | ||||||
.subscribe { _ -> end(State.TIMEOUT, "Timeout is exited") } | ||||||
|
@@ -352,6 +356,30 @@ abstract class AbstractCheckTask( | |||||
} | ||||||
} | ||||||
|
||||||
private fun addStartInfo(event: Event, lastSequence: Long, checkpointTimestamp: Timestamp?) { | ||||||
with(event) { | ||||||
name( | ||||||
if (lastSequence == DEFAULT_SEQUENCE) { | ||||||
"Rule works from the beginning of the cache" | ||||||
} else { | ||||||
"Rule works from the $lastSequence sequence in session ${sessionKey.sessionAlias} and direction ${sessionKey.direction}" | ||||||
} | ||||||
) | ||||||
status(PASSED) | ||||||
type("ruleStartPoint") | ||||||
if (lastSequence != DEFAULT_SEQUENCE) { | ||||||
messageID(sessionKey.toMessageID(lastSequence)) | ||||||
} | ||||||
bodyData(createMessageBean("The rule starts working from " + | ||||||
(if (lastSequence == DEFAULT_SEQUENCE) "start of cache" else "sequence $lastSequence") + | ||||||
(checkpointTimestamp?.let { | ||||||
val instant = checkpointTimestamp.toInstant() | ||||||
" and expects messages between $instant and ${instant.plusMillis(taskTimeout.messageTimeout)}" | ||||||
} ?: ""))) | ||||||
bodyData(createMessageBean("Rule timeout is set to ${taskTimeout.timeout} mls")) | ||||||
} | ||||||
} | ||||||
|
||||||
private fun taskFinished() { | ||||||
var ruleEventStatus = EventStatus.FAILED | ||||||
try { | ||||||
|
@@ -371,8 +399,8 @@ abstract class AbstractCheckTask( | |||||
.name("Check rule $description problem") | ||||||
.type("Exception") | ||||||
.status(FAILED) | ||||||
.bodyData(EventUtils.createMessageBean(message)) | ||||||
.bodyData(EventUtils.createMessageBean(ex.message)) | ||||||
.bodyData(createMessageBean(message)) | ||||||
.bodyData(createMessageBean(ex.message)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.toProto(parentEventID)) | ||||||
.build()) | ||||||
} finally { | ||||||
|
@@ -424,6 +452,9 @@ abstract class AbstractCheckTask( | |||||
|
||||||
protected open val skipPublication: Boolean = false | ||||||
|
||||||
protected open val errorEventOnTimeout: Boolean | ||||||
get() = true | ||||||
|
||||||
protected fun isCheckpointLastReceivedMessage(): Boolean = bufferContainsStartMessage && !hasMessagesInTimeoutInterval | ||||||
|
||||||
/** | ||||||
|
@@ -466,6 +497,9 @@ abstract class AbstractCheckTask( | |||||
private fun completeEventOrReportError(prevState: State): Boolean { | ||||||
return try { | ||||||
if (started) { | ||||||
if (errorEventOnTimeout && prevState in TIMEOUT_STATES) { | ||||||
addTimeoutEvent(prevState) | ||||||
} | ||||||
completeEvent(prevState) | ||||||
doAfterCompleteEvent() | ||||||
false | ||||||
|
@@ -482,13 +516,55 @@ abstract class AbstractCheckTask( | |||||
refs.rootEvent.addSubEventWithSamePeriod() | ||||||
.name("Check result event cannot build completely") | ||||||
.type("eventNotComplete") | ||||||
.bodyData(EventUtils.createMessageBean("An unexpected exception has been thrown during result check build")) | ||||||
.bodyData(EventUtils.createMessageBean(e.message)) | ||||||
.bodyData(createMessageBean("An unexpected exception has been thrown during result check build")) | ||||||
.bodyData(createMessageBean(e.message)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.status(FAILED) | ||||||
true | ||||||
} | ||||||
} | ||||||
|
||||||
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( | ||||||
when (timeoutType) { | ||||||
State.TIMEOUT -> "CheckTimeoutInterrupted" | ||||||
State.MESSAGE_TIMEOUT -> "CheckMessageTimeoutInterrupted" | ||||||
else -> error("unexpected timeout state: $timeoutType") | ||||||
} | ||||||
).name("Rule processed $handledMessageCounter message(s) and was interrupted due to $timeoutValue mls ${timeoutType.name.lowercase()}") | ||||||
.bodyData( | ||||||
createMessageBean( | ||||||
when (timeoutType) { | ||||||
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) | ||||||
|
@@ -585,6 +661,7 @@ abstract class AbstractCheckTask( | |||||
private val RESPONSE_EXECUTOR = ForkJoinPool.commonPool() | ||||||
@JvmField | ||||||
val CONVERTER = ProtoToIMessageConverter(VerificationUtil.FACTORY_PROXY, null, null, createParameters().setUseMarkerForNullsInMessage(true)) | ||||||
private val TIMEOUT_STATES: Set<State> = setOf(State.TIMEOUT, State.MESSAGE_TIMEOUT) | ||||||
val EMPTY_STATUS_CONSUMER: (EventStatus) -> Unit = {} | ||||||
} | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/exactpro/th2/check1/utils/SessionUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2022 Exactpro (Exactpro Systems Limited) | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.exactpro.th2.check1.utils | ||
|
||
import com.exactpro.th2.check1.SessionKey | ||
import com.exactpro.th2.common.grpc.ConnectionID | ||
import com.exactpro.th2.common.grpc.MessageID | ||
|
||
fun SessionKey.toMessageID(sequence: Long): MessageID = MessageID.newBuilder() | ||
.setConnectionId( | ||
ConnectionID.newBuilder() | ||
.setSessionAlias(sessionAlias) | ||
.build()) | ||
.setSequence(sequence) | ||
.setDirection(direction) | ||
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.