Skip to content

Commit

Permalink
[TS-1821] added details into error logs (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro authored Feb 12, 2024
1 parent 2f38f3b commit 25af198
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Overview (4.1.4)
# Overview (4.1.5)

Event store (estore) is an important th2 component responsible for storing events into Cradle. Please refer to [Cradle repository] (https://github.com/th2-net/cradleapi/blob/master/README.md) for more details. This component has a pin for listening events via MQ.

Expand Down Expand Up @@ -72,6 +72,10 @@ Please see more details about this feature via [link](https://github.com/th2-net

# Changes

## 4.1.5

+ Print information about event id into error logs

## 4.1.4

+ The cradle version update from `3.1.4` to `3.1.5`
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version=4.1.4
release_version=4.1.5
50 changes: 41 additions & 9 deletions src/main/java/com/exactpro/th2/estore/EventPersistor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.exactpro.cradle.CradleManager;
import com.exactpro.cradle.CradleStorage;
import com.exactpro.cradle.testevents.BatchedStoredTestEvent;
import com.exactpro.cradle.testevents.StoredTestEvent;
import com.exactpro.cradle.testevents.StoredTestEventBatch;
import com.exactpro.cradle.testevents.StoredTestEventSingle;
Expand Down Expand Up @@ -146,7 +147,8 @@ public void dispose() {
try {
samplerService.shutdown();
samplerService.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
} catch (InterruptedException ex) {
LOGGER.error("Cannot await all futures are finished", ex);
}
}

Expand Down Expand Up @@ -184,26 +186,56 @@ private void logAndRetry(ScheduledRetryableTask<PersistenceTask> task, Throwable

if (task.getRetriesLeft() > 0) {

LOGGER.error("Failed to store the event batch id '{}', {} retries left, rescheduling",
eventBatch.getId(),
task.getRetriesLeft(),
e);
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Failed to store the event '{}', {} retries left, rescheduling",
eventToString(eventBatch),
task.getRetriesLeft(),
e);
}
taskQueue.retry(task);
metrics.registerPersistenceRetry(retriesDone);

} else {

taskQueue.complete(task);
metrics.registerAbortedPersistence();
LOGGER.error("Failed to store the event batch id '{}', aborting after {} executions",
eventBatch.getId(),
retriesDone,
e);
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Failed to store the event '{}', aborting after {} executions",
eventToString(eventBatch),
retriesDone,
e);
}
persistenceTask.complete();
}
}

public static String eventToString(StoredTestEvent event) {
requireNonNull(event, "'stored test event' can't be null");

return eventToString(new StringBuilder(), event).toString();
}

private static StringBuilder eventToString(StringBuilder builder, StoredTestEvent event) {
if (StoredTestEventBatch.class.equals(event.getClass())) {
StoredTestEventBatch batch = (StoredTestEventBatch) event;
builder.append("id: ").append(batch.getId()).append(", ")
.append("parent: ").append(event.getParentId()).append(", ")
.append("children: [");
for (BatchedStoredTestEvent testEvent : batch.getTestEvents()) {
eventToString(builder, testEvent);
}
builder.append("]");
} else {
builder.append("(")
.append("id: ").append(event.getId()).append(", ")
.append("parent: ").append(event.getParentId()).append(", ")
.append("name: ").append(event.getName()).append(", ")
.append("type: ").append(event.getType()).append(", ")
.append("timestamp: ").append(event.getStartTimestamp())
.append(")");
}
return builder;
}
static class PersistenceTask {
final StoredTestEvent eventBatch;
final Consumer<StoredTestEvent> callback;
Expand Down

0 comments on commit 25af198

Please sign in to comment.