Skip to content

Commit

Permalink
More logging for datadog (#1241)
Browse files Browse the repository at this point in the history
Signed-off-by: Angelica Ochoa <[email protected]>
  • Loading branch information
ao508 authored Jul 29, 2024
1 parent 76d1391 commit b9df516
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.mskcc.smile.persistence.neo4j.SmileRequestRepository;
import org.mskcc.smile.service.SmileRequestService;
import org.mskcc.smile.service.SmileSampleService;
import org.mskcc.smile.service.util.RequestStatusLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -47,13 +46,7 @@ public class RequestServiceImpl implements SmileRequestService {
@Autowired
private SmileSampleService sampleService;

@Autowired
private RequestStatusLogger requestStatusLogger;

private final DateFormat IMPORT_DATE_FORMATTER = initDateFormatter();
// 24 hours in milliseconds
private final Integer TIME_ADJ_24HOURS_MS = 24 * 60 * 60 * 1000;
private Map<String, Date> loggedExistingRequests = new HashMap<>();
private static final Log LOG = LogFactory.getLog(RequestServiceImpl.class);
private final ObjectMapper mapper = new ObjectMapper();

Expand All @@ -79,7 +72,6 @@ public Boolean saveRequest(SmileRequest request) throws Exception {
requestRepository.save(request);
return Boolean.TRUE;
}
logDuplicateRequest(request);
return Boolean.FALSE;
}

Expand All @@ -99,46 +91,16 @@ public Boolean saveRequestMetadata(SmileRequest request) {
StringBuilder builder = new StringBuilder();
builder.append("Failed to update the Request-level metadata for request id: ")
.append(request.getIgoRequestId())
.append("\n\tTotal versions of request metadata -->\n\t\t - before save: ")
.append(" - Total versions of request metadata - before save: ")
.append(currentMetadataList.size())
.append("\n\t\t - after save: ")
.append(" - after save: ")
.append(updatedMetadataList.size());
LOG.error(builder.toString());
return Boolean.FALSE;
}
return Boolean.TRUE;
}

/**
* Logs duplicate requests.
* @param request
* @throws IOException
*/
private void logDuplicateRequest(SmileRequest request) throws IOException {
// if request has not been logged before then save request to request logger file
// otherwise check if new timestamp occurs within 24 hours since the last time
// the same request was seen. If it does not then save request to logger file
Date newTimestamp = new Date();
Boolean logRequest = Boolean.FALSE;
if (!loggedExistingRequests.containsKey(request.getIgoRequestId())) {
loggedExistingRequests.put(request.getIgoRequestId(), newTimestamp);
logRequest = Boolean.TRUE;
} else {
// check if new timestamp occurs within 24 hours of the reference timestamp
// if check does not pass then log the request to the logger file
Date referenceTimestamp = loggedExistingRequests.get(request.getIgoRequestId());
if (!timestampWithin24Hours(referenceTimestamp, newTimestamp)) {
logRequest = Boolean.TRUE;
loggedExistingRequests.put(request.getIgoRequestId(), newTimestamp);
}
}

if (logRequest) {
requestStatusLogger.logRequestStatus(request.getRequestJson(),
RequestStatusLogger.StatusType.DUPLICATE_REQUEST);
}
}

@Override
public SmileRequest getSmileRequestById(String requestId) throws Exception {
SmileRequest request = requestRepository.findRequestById(requestId);
Expand Down Expand Up @@ -198,20 +160,6 @@ public Boolean updateRequestMetadata(RequestMetadata requestMetadata, Boolean fr
return Boolean.FALSE;
}

/**
* Returns true if new timestamp occurs within 24 hours of the reference timestamp.
* @param referenceTimestamp
* @param newTimestamp
* @return Boolean
*/
private Boolean timestampWithin24Hours(Date referenceTimestamp, Date newTimestamp) {
// create reference timestamp shifted 24 hours in milliseconds
Calendar adjustedReferenceTimestamp = Calendar.getInstance();
adjustedReferenceTimestamp.setTime(referenceTimestamp);
adjustedReferenceTimestamp.add(Calendar.MILLISECOND, TIME_ADJ_24HOURS_MS);
return newTimestamp.before(adjustedReferenceTimestamp.getTime());
}

@Override
public Boolean requestHasUpdates(SmileRequest existingRequest, SmileRequest request,
Boolean fromLims) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public Boolean updateSampleMetadata(SampleMetadata sampleMetadata, Boolean fromL
SmileRequest request = requestService.getSmileRequestById(sampleMetadata.getIgoRequestId());
if (request == null) {
LOG.error("Failed to persist sample metadata updates, "
+ "request does not exist " + sampleMetadata.getIgoRequestId());
+ "request does not exist " + sampleMetadata.toString());
return Boolean.FALSE;
}
LOG.info("Persisting new sample to db: " + sampleMetadata.getPrimaryId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ public void run() {
tempoService.mergeBamCompleteEventBySamplePrimaryId(primaryId,
bamComplete);
} catch (IncorrectResultSizeDataAccessException e) {
LOG.error("Encountered error while persisting BAM complete "
+ "event to database: " + bcEvent.toString(), e);
LOG.error("[TEMPO BAM COMPLETE ERROR] Encountered error while "
+ "persisting BAM complete event to database: "
+ bcEvent.toString(), e);
}
}
} else {
LOG.error("Sample does not exist by id: " + sampleId);
LOG.error("[TEMPO BAM COMPLETE ERROR] Sample does not exist by id: " + sampleId);
}
}
} catch (InterruptedException e) {
Expand Down Expand Up @@ -169,12 +170,12 @@ public void run() {
tempoService.mergeQcCompleteEventBySamplePrimaryId(primaryId,
qcComplete);
} catch (IncorrectResultSizeDataAccessException e) {
LOG.error("Encountered error while persisting QC complete "
+ "event to database: " + qcEvent.toString(), e);
LOG.error("[TEMPO QC COMPLETE ERROR] Encountered error while persisting "
+ "QC complete event to database: " + qcEvent.toString(), e);
}
}
} else {
LOG.error("Sample does not exist by id: " + sampleId);
LOG.error("[TEMPO QC COMPLETE ERROR] Sample does not exist by id: " + sampleId);
}
}
} catch (InterruptedException e) {
Expand Down Expand Up @@ -225,12 +226,13 @@ public void run() {
tempoService.mergeMafCompleteEventBySamplePrimaryId(primaryId,
mafComplete);
} catch (IncorrectResultSizeDataAccessException e) {
LOG.error("Encountered error while persisting MAF complete "
+ "event to database: " + mcEvent.toString(), e);
LOG.error("[TEMPO MAF COMPLETE ERROR] Encountered error while "
+ "persisting MAF complete event to database: "
+ mcEvent.toString(), e);
}
}
} else {
LOG.error("Sample does not exist by id: " + sampleId);
LOG.error("[TEMPO MAF COMPLETE ERROR] Sample does not exist by id: " + sampleId);
}
}
} catch (InterruptedException e) {
Expand Down Expand Up @@ -327,8 +329,8 @@ public void run() {
LOG.info(builder.toString());
tempoService.updateSampleBilling(billing);
} else {
LOG.error("Cannot update billing information for sample that does not exist: "
+ billing.getPrimaryId());
LOG.error("[TEMPO SAMPLE BILLING ERROR] Cannot update billing information for "
+ "sample that does not exist: " + billing.getPrimaryId());
}
}
} catch (InterruptedException e) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.mskcc.smile.service.impl.SampleServiceImpl;
import org.mskcc.smile.service.impl.TempoMessageHandlingServiceImpl;
import org.mskcc.smile.service.impl.TempoServiceImpl;
import org.mskcc.smile.service.util.RequestStatusLogger;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand Down Expand Up @@ -68,9 +67,6 @@ public CohortCompleteService cohortCompleteService() {
@MockBean
public CrdbMappingServiceImpl crdbMappingService;

@MockBean
public RequestStatusLogger requestStatusLogger;

@MockBean
public Gateway messagingGateway;

Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/application.properties.EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ smile.correct_cmoptid_topic=
# messaging failures filepath
smile.publishing_failures_filepath=

# request handling failure filepath
smile.request_handling_failures_filepath=

# tempo topics
num.tempo_msg_handler_threads=
tempo.wes_bam_complete_topic=
Expand Down

0 comments on commit b9df516

Please sign in to comment.