Skip to content

Commit 628532b

Browse files
authored
Add details for 'coverage period missing or year,month query incorrect' log statements (#1418)
## 🎫 Ticket - https://jira.cms.gov/browse/AB2D-6418 - https://jira.cms.gov/browse/AB2D-6425 ## 🛠 Changes Add details to log message for `coverage period missing or year,month query incorrect` error messages. ## ℹ️ Context When we receive a Slack notification of a failed job, the relevant details (e.g. coverage month and year) are not present in Splunk. This PR adds those details for debugging purposes. ![image](https://github.com/user-attachments/assets/87cfcea5-c673-4198-a65d-fb6315cb5f9b) ## 🧪 Validation Added unit tests that verified additional statements were printed to the logs ![image](https://github.com/user-attachments/assets/b7b29df6-7cf8-46e7-8128-846537ed2a99)
1 parent 554c4ee commit 628532b

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

worker/src/main/java/gov/cms/ab2d/worker/processor/coverage/CoverageDriverImpl.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -562,22 +562,28 @@ public CoveragePagingResult pageCoverage(Job job, ContractDTO contract) {
562562
}
563563

564564
ZonedDateTime startDateTime = getStartDateTime(contract);
565-
565+
// Additional details to log in the event of exception
566+
Optional<String> additionalDetails = Optional.empty();
566567
try {
567568
// Check that all coverage periods necessary are present before beginning to page
568569
while (startDateTime.isBefore(now)) {
570+
additionalDetails = Optional.of(String.format("contract='%s' month='%s', year='%s'",
571+
contract.getContractNumber(),
572+
startDateTime.getMonthValue(),
573+
startDateTime.getYear()));
569574
// Will throw exception if it doesn't exist
570575
coverageService.getCoveragePeriod(mapping.map(contract), startDateTime.getMonthValue(), startDateTime.getYear());
571576
startDateTime = startDateTime.plusMonths(1);
572577
}
578+
additionalDetails = Optional.empty();
573579

574580
// Make initial request which returns a result and a request starting at the next cursor
575581
CoveragePagingRequest request = new CoveragePagingRequest(PAGING_SIZE, null, mapping.map(contract), job.getCreatedAt());
576-
582+
additionalDetails = Optional.of(request.toString());
577583
// Make request for coverage metadata
578584
return coverageService.pageCoverage(request);
579585
} catch (Exception exception) {
580-
log.error("coverage period missing or year,month query incorrect, driver should have resolved earlier");
586+
log.error("coverage period missing or year,month query incorrect, driver should have resolved earlier - {}", additionalDetails.orElse(""));
581587
throw new CoverageDriverException("coverage driver failing preconditions", exception);
582588
}
583589
}
@@ -632,7 +638,7 @@ public CoveragePagingResult pageCoverage(CoveragePagingRequest request) {
632638
try {
633639
return coverageService.pageCoverage(request);
634640
} catch (Exception exception) {
635-
log.error("coverage period missing or year,month query incorrect, driver should have resolved earlier");
641+
log.error("coverage period missing or year,month query incorrect, driver should have resolved earlier - {}", request.toString());
636642
throw new CoverageDriverException("coverage driver failing preconditions", exception);
637643
}
638644
}

worker/src/test/java/gov/cms/ab2d/worker/processor/coverage/CoverageDriverUnitTest.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.persistence.EntityNotFoundException;
2828

2929
import gov.cms.ab2d.worker.service.coveragesnapshot.CoverageSnapshotService;
30+
import lombok.val;
3031
import org.jetbrains.annotations.NotNull;
3132
import org.junit.jupiter.api.AfterEach;
3233
import org.junit.jupiter.api.BeforeEach;
@@ -36,6 +37,8 @@
3637
import org.mockito.Mock;
3738
import org.mockito.junit.jupiter.MockitoExtension;
3839
import org.springframework.beans.factory.annotation.Autowired;
40+
import org.springframework.boot.test.system.CapturedOutput;
41+
import org.springframework.boot.test.system.OutputCaptureExtension;
3942
import org.springframework.test.util.ReflectionTestUtils;
4043

4144

@@ -60,7 +63,7 @@
6063
/**
6164
* Tests for paging coverage which are much easier using mocked resources
6265
*/
63-
@ExtendWith(MockitoExtension.class)
66+
@ExtendWith({MockitoExtension.class, OutputCaptureExtension.class})
6467
class CoverageDriverUnitTest {
6568

6669
@Mock
@@ -229,9 +232,30 @@ void pageRequestWhenSinceDateAfterNow() {
229232
assertNotNull(result);
230233
}
231234

235+
@DisplayName("Paging coverage fails when all coverage periods are present but CoverageService#pageCoverage throws exception")
236+
@Test
237+
void failPagingWhenCoveragePeriodsPresentButUnderlyingMethodThrowsException(CapturedOutput output) {
238+
when(coverageService.getCoveragePeriod(any(ContractForCoverageDTO.class), anyInt(), anyInt())).thenAnswer((invocationOnMock) -> {
239+
CoveragePeriod period = new CoveragePeriod();
240+
period.setContractNumber((invocationOnMock.getArgument(0).toString()));
241+
period.setMonth(invocationOnMock.getArgument(1));
242+
period.setYear(invocationOnMock.getArgument(2));
243+
return period;
244+
});
245+
246+
when(coverageService.pageCoverage(any())).thenThrow(RuntimeException.class);
247+
248+
Job job = new Job();
249+
ContractDTO contract = new ContractDTO(null, "Contract-0", null, AB2D_EPOCH.toOffsetDateTime(), null, 0, 0);
250+
when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO("Contract-0", contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));
251+
252+
assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(job, contract));
253+
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - CoveragePagingRequest(jobStartTime=null, contract=ContractForCoverageDTO(contractNumber=Contract-0, attestedOn=2020-01-01T00:00-05:00, contractType=NORMAL), pageSize=10000, cursor=Optional.empty)"));
254+
}
255+
232256
@DisplayName("Paging coverage fails when coverage periods are missing")
233257
@Test
234-
void failPagingWhenCoveragePeriodMissing() {
258+
void failPagingWhenCoveragePeriodMissing(CapturedOutput output) {
235259

236260
when(coverageService.getCoveragePeriod(any(), anyInt(), anyInt())).thenThrow(new EntityNotFoundException());
237261

@@ -240,6 +264,7 @@ void failPagingWhenCoveragePeriodMissing() {
240264

241265
CoverageDriverException startDateInFuture = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(job, contract));
242266
assertEquals(EntityNotFoundException.class, startDateInFuture.getCause().getClass());
267+
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - contract='null' month='1', year='2020'"));
243268
}
244269

245270
@DisplayName("Paging coverage periods")
@@ -354,16 +379,18 @@ void failureToLockCoverageAvailableFailsQuietly() {
354379

355380
@DisplayName("When paging coverage fails throw coverage driver exception")
356381
@Test
357-
void failureToPageCausesExceptions() {
382+
void failureToPageCausesExceptions(CapturedOutput output) {
358383
when(coverageService.pageCoverage(any())).thenThrow(RuntimeException.class);
359384

360385
CoverageDriver driver = new CoverageDriverImpl(null, null, coverageService, null, null, null,null, snapshotService);
361386

362387
ContractForCoverageDTO contract = new ContractForCoverageDTO();
363388
contract.setContractNumber("contractNum");
364389

365-
CoverageDriverException exception = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(new CoveragePagingRequest( 1000, null, contract, OffsetDateTime.now())));
390+
val coveragePagingRequest = new CoveragePagingRequest( 1000, null, contract, AB2D_EPOCH.toOffsetDateTime());
391+
CoverageDriverException exception = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(coveragePagingRequest));
366392
assertTrue(exception.getMessage().contains("coverage driver failing preconditions"));
393+
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - CoveragePagingRequest(jobStartTime=2020-01-01T00:00-05:00, contract=ContractForCoverageDTO(contractNumber=contractNum, attestedOn=null, contractType=null), pageSize=1000, cursor=Optional.empty"));
367394
}
368395

369396
@DisplayName("When loading a mapping job exit early if conditions not met")

0 commit comments

Comments
 (0)