Skip to content

Commit dd0caf9

Browse files
committed
WIP adding additional logging
1 parent 3acaae4 commit dd0caf9

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

api/src/main/java/ca/bc/gov/educ/penreg/api/orchestrator/PenReqBatchStudentOrchestrator.java

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ protected void validateStudentDemographics(final Event event, final Saga saga, f
160160
protected void processPenMatchResults(final Event event, final Saga saga, final PenRequestBatchStudentSagaData penRequestBatchStudentSagaData) throws IOException, InterruptedException, TimeoutException {
161161
UUID sagaId = saga.getSagaId();
162162
Stopwatch processPenMatchResults = new Stopwatch("processPenMatchResults", sagaId);
163+
Stopwatch processPenMatchInner = new Stopwatch("processPenMatchInner", sagaId);
163164
Stopwatch updateAttachedSaga = new Stopwatch("updateAttachedSagaWithEvents", sagaId);
164165
Stopwatch updateAttachedEntityDuringSaga = new Stopwatch("updateAttachedEntityDuringSagaProcess", sagaId);
165166
processPenMatchResults.start();
@@ -177,7 +178,9 @@ protected void processPenMatchResults(final Event event, final Saga saga, final
177178
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
178179
updateAttachedSaga.stop();
179180

181+
processPenMatchInner.start();
180182
eventOptional = this.getPenRequestBatchStudentOrchestratorService().processPenMatchResult(saga, penRequestBatchStudentSagaData, penMatchResult);
183+
processPenMatchInner.stop();
181184

182185
penRequestBatchStudentSagaData.setIsPENMatchResultsProcessed(true);
183186
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchStudentSagaData)); // save the updated payload to DB...

api/src/main/java/ca/bc/gov/educ/penreg/api/orchestrator/base/BaseOrchestrator.java

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import ca.bc.gov.educ.penreg.api.struct.Event;
1919
import ca.bc.gov.educ.penreg.api.struct.NotificationEvent;
2020
import ca.bc.gov.educ.penreg.api.util.JsonUtil;
21+
import ca.bc.gov.educ.penreg.api.util.Stopwatch;
2122
import jakarta.validation.constraints.NotNull;
2223
import java.io.IOException;
2324
import java.time.LocalDateTime;
@@ -441,6 +442,10 @@ private void replayFromBeginning(final Saga saga, final T t) throws InterruptedE
441442
@Async("subscriberExecutor")
442443
@Transactional
443444
public void handleEvent(@NotNull final Event event) throws InterruptedException, IOException, TimeoutException {
445+
UUID sagaId = event.getSagaId();
446+
Stopwatch handleEvent = new Stopwatch("handleEvent", sagaId);
447+
Stopwatch processEvent = new Stopwatch("processEvent", sagaId);
448+
handleEvent.start();
444449
log.info("executing saga event {}", event.getEventType());
445450
log.trace("Full event :: {}", event);
446451
if (this.sagaEventExecutionNotRequired(event)) {
@@ -457,7 +462,9 @@ public void handleEvent(@NotNull final Event event) throws InterruptedException,
457462
final var sagaEventState = this.findNextSagaEventState(event.getEventType(), event.getEventOutcome(), sagaData);
458463
log.trace("found next event as {}", sagaEventState);
459464
if (sagaEventState.isPresent()) {
465+
processEvent.start();
460466
this.process(event, saga, sagaData, sagaEventState.get());
467+
processEvent.stop();
461468
} else {
462469
log.error("This should not have happened, please check that both the saga api and all the participating apis are in sync in terms of events and their outcomes. {}", event.toString()); // more explicit error message,
463470
}
@@ -467,6 +474,8 @@ public void handleEvent(@NotNull final Event event) throws InterruptedException,
467474
} else {
468475
log.error("Saga process without DB record is not expected. {}", event);
469476
}
477+
478+
handleEvent.stop();
470479
}
471480

472481
/**
@@ -576,14 +585,22 @@ protected Optional<SagaEventState<T>> findNextSagaEventState(final EventType cur
576585
* @throws IOException if there is connectivity problem
577586
*/
578587
protected void process(@NotNull final Event event, final Saga saga, final T sagaData, final SagaEventState<T> sagaEventState) throws InterruptedException, TimeoutException, IOException {
588+
UUID sagaId = saga.getSagaId();
589+
Stopwatch process = new Stopwatch("process", sagaId);
590+
Stopwatch invokeNextEvent = new Stopwatch("invokeNextEvent", sagaId);
591+
process.start();
579592
if (!saga.getSagaState().equalsIgnoreCase(COMPLETED.toString())
580593
&& this.isNotProcessedEvent(event.getEventType(), saga, this.nextStepsToExecute.keySet())) {
581594
log.info(SYSTEM_IS_GOING_TO_EXECUTE_NEXT_EVENT_FOR_CURRENT_EVENT, sagaEventState.getNextEventType(), event.getEventType(), saga.getSagaId());
582595
log.trace("Full event for SAGA_ID :: {} is :: {}", saga.getSagaId(), event.toString());
596+
597+
invokeNextEvent.start();
583598
this.invokeNextEvent(event, saga, sagaData, sagaEventState);
599+
invokeNextEvent.stop();
584600
} else {
585601
log.info("ignoring this message as we have already processed it or it is completed. {}", event.toString()); // it is expected to receive duplicate message in saga pattern, system should be designed to handle duplicates.
586602
}
603+
process.stop();
587604
}
588605

589606
/**

api/src/main/java/ca/bc/gov/educ/penreg/api/service/PenRequestBatchStudentService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public boolean isPenAlreadyAssigned(final PenRequestBatchEntity penRequestBatch,
397397
}
398398
semaphore.tryRelease(id);
399399
} catch (final Exception e) {
400-
log.error("PenMatchRecord in priority queue is empty for matched status, this should not have happened.");
400+
log.error("PenMatchRecord in priority queue is empty for matched status, this should not have happened. {}", e);
401401
throw new PenRegAPIRuntimeException("PenMatchRecord in priority queue is empty for matched status, this should not have happened.");
402402
}
403403
return penAlreadyAssigned;

0 commit comments

Comments
 (0)