Skip to content

Commit

Permalink
Record expected task start time in telemetry (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamachor authored Oct 1, 2024
1 parent 8d531df commit 6b43c20
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private void handleTasksExecution(Connection connection, int maxConcurrentTasks)
List<Future<Boolean>> results = new ArrayList<>();
try {
for (TaskExec task : session.getTasks()) {
long delay = ObjectUtils.<Long>defaultIfNull(task.getStart(), 0L);
Instant expectedStartTime = Instant.now().plusMillis(delay);
Future<Boolean> result =
executor.schedule(
() -> {
Expand All @@ -115,13 +117,21 @@ private void handleTasksExecution(Connection connection, int maxConcurrentTasks)
taskExecutor.executeTask(connection, task, values);
} catch (Exception e) {
LOGGER.error("Exception executing task: {}", task.getId());
writeTaskEvent(taskStartTime, task.getId(), Status.FAILURE);
writeTaskEvent(
taskStartTime,
task.getId(),
Status.FAILURE,
"{expectedStartTime=" + expectedStartTime + "}");
throw e;
}
writeTaskEvent(taskStartTime, task.getId(), Status.SUCCESS);
writeTaskEvent(
taskStartTime,
task.getId(),
Status.SUCCESS,
"{expectedStartTime=" + expectedStartTime + "}");
return true;
},
ObjectUtils.<Long>defaultIfNull(task.getStart(), 0L),
delay,
TimeUnit.MILLISECONDS);
results.add(result);
}
Expand Down Expand Up @@ -192,10 +202,11 @@ private EventInfo writeSessionEvent(Instant startTime, String id, Status status)
return eventInfo;
}

private EventInfo writeTaskEvent(Instant startTime, String id, Status status) {
private EventInfo writeTaskEvent(Instant startTime, String id, Status status, String payload) {
EventInfo eventInfo =
ImmutableEventInfo.of(
experimentStartTime, startTime, Instant.now(), id, EventType.EXEC_TASK, status);
experimentStartTime, startTime, Instant.now(), id, EventType.EXEC_TASK, status)
.withPayload(payload);
telemetryRegistry.writeEvent(eventInfo);
return eventInfo;
}
Expand Down

0 comments on commit 6b43c20

Please sign in to comment.