Skip to content

Commit

Permalink
DMP-4376 Add ARM RPO logs for Dynatrace
Browse files Browse the repository at this point in the history
Added dynatrace logging for ARM RPO Search and Polling
  • Loading branch information
karen-hedges committed Dec 3, 2024
1 parent 47c2459 commit 355249a
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
public class ArmLoggerServiceImpl implements ArmLoggerService {

private static final String ARM_PUSH_SUCCESSFUL = "Successfully pushed object to ARM dropzone: eod_id={}";

private static final String ARM_PUSHED_FAILED = "Failed to push object to ARM dropzone: eod_id={}";

private static final String ARCHIVE_TO_ARM_SUCCESSFUL = "Successfully archived object to ARM: eod_id={}";

private static final String ARCHIVE_TO_ARM_FAILED = "Failed to archive object to ARM: eod_id={}";


private static final String ARM_RPO_SEARCH_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID = "ARM RPO Search - Successfully completed for execution Id = {}";
private static final String ARM_RPO_SEARCH_FAILED_FOR_EXECUTION_ID = "ARM RPO Search - Failed for execution Id = {}";
private static final String ARM_RPO_POLLING_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID = "ARM RPO Polling - Successfully completed for execution Id = {}";
private static final String ARM_RPO_POLLING_FAILED_FOR_EXECUTION_ID = "ARM RPO Polling - Failed for execution Id = {}";

@Override
public void armPushSuccessful(Integer eodId) {
log.info(ARM_PUSH_SUCCESSFUL, eodId);
Expand All @@ -36,27 +36,27 @@ public void archiveToArmSuccessful(Integer eodId) {

@Override
public void archiveToArmFailed(Integer eodId) {
log.info(ARCHIVE_TO_ARM_FAILED, eodId);
log.error(ARCHIVE_TO_ARM_FAILED, eodId);
}

@Override
public void armRpoSearchSuccessful(Integer executionId) {
log.info("ARM RPO Search - Successfully completed for execution Id = {}");
log.info(ARM_RPO_SEARCH_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID, executionId);
}

@Override
public void armRpoSearchFailed(Integer executionId) {
log.error("ARM RPO Search - Failed for execution Id = {}");
log.error(ARM_RPO_SEARCH_FAILED_FOR_EXECUTION_ID, executionId);
}

@Override
public void armRpoPollingSuccessful(Integer executionId) {
log.info("ARM RPO Polling - Successfully completed for execution Id = {}");
log.info(ARM_RPO_POLLING_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID, executionId);
}

@Override
public void armRpoPollingFailed(Integer executionId) {
log.error("ARM RPO Polling - Failed for execution Id = {}");
log.error(ARM_RPO_POLLING_FAILED_FOR_EXECUTION_ID, executionId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package uk.gov.hmcts.darts.log.service.impl;

import nl.altindag.log.LogCaptor;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith({MockitoExtension.class})
class ArmLoggerServiceImplTest {

private static final Integer EOD_ID = 1;
private static final Integer EXECUTION_ID = 2;
private ArmLoggerServiceImpl armLoggerService;
private static LogCaptor logCaptor;

@BeforeAll
public static void setupLogCaptor() {
logCaptor = LogCaptor.forClass(ArmLoggerServiceImpl.class);
logCaptor.setLogLevelToInfo();
}

@AfterEach
public void clearLogs() {
logCaptor.clearLogs();
}

@AfterAll
public static void tearDown() {
logCaptor.close();
}

@BeforeEach
void setUp() {
armLoggerService = new ArmLoggerServiceImpl();
}

@Test
void armPushSuccessful_shouldLogInfoWithEodId_whenProvidedWithEodId() {
armLoggerService.armPushSuccessful(EOD_ID);

var logEntry = String.format("Successfully pushed object to ARM dropzone: eod_id=%s", EOD_ID);

List<String> infoLogs = logCaptor.getInfoLogs();
assertEquals(1, infoLogs.size());
assertEquals(logEntry, infoLogs.get(0));
}

@Test
void armPushFailed_shouldLogErrorWithEodId_whenProvidedWithEodId() {
armLoggerService.armPushFailed(EOD_ID);

var logEntry = String.format("Failed to push object to ARM dropzone: eod_id=%s", EOD_ID);

List<String> errorLogs = logCaptor.getErrorLogs();
assertEquals(1, errorLogs.size());
assertEquals(logEntry, errorLogs.get(0));
}

@Test
void archiveToArmSuccessful_shouldLogInfoWithEodId_whenProvidedWithEodId() {
armLoggerService.archiveToArmSuccessful(EOD_ID);

var logEntry = String.format("Successfully archived object to ARM: eod_id=%s", EOD_ID);

List<String> infoLogs = logCaptor.getInfoLogs();
assertEquals(1, infoLogs.size());
assertEquals(logEntry, infoLogs.get(0));
}

@Test
void archiveToArmFailed_shouldLogErrorWithEodId_whenProvidedWithEodId() {
armLoggerService.archiveToArmFailed(EOD_ID);

var logEntry = String.format("Failed to archive object to ARM: eod_id=%s", EOD_ID);

List<String> errorLogs = logCaptor.getErrorLogs();
assertEquals(1, errorLogs.size());
assertEquals(logEntry, errorLogs.get(0));
}

@Test
void armRpoSearchSuccessful_shouldLogInfoWithEodId_whenProvidedWithExecutionId() {
armLoggerService.armRpoSearchSuccessful(EXECUTION_ID);

var logEntry = String.format("ARM RPO Search - Successfully completed for execution Id = %s", EXECUTION_ID);

List<String> infoLogs = logCaptor.getInfoLogs();
assertEquals(1, infoLogs.size());
assertEquals(logEntry, infoLogs.get(0));
}

@Test
void armRpoSearchFailed_shouldLogErrorWithEodId_whenProvidedWithExecutionId() {
armLoggerService.armRpoSearchFailed(EXECUTION_ID);

var logEntry = String.format("ARM RPO Search - Failed for execution Id = %s", EXECUTION_ID);

List<String> errorLogs = logCaptor.getErrorLogs();
assertEquals(1, errorLogs.size());
assertEquals(logEntry, errorLogs.get(0));
}

@Test
void armRpoPollingSuccessful_shouldLogInfoWithEodId_whenProvidedWithExecutionId() {
armLoggerService.armRpoPollingSuccessful(EXECUTION_ID);

var logEntry = String.format("ARM RPO Polling - Successfully completed for execution Id = %s", EXECUTION_ID);

List<String> infoLogs = logCaptor.getInfoLogs();
assertEquals(1, infoLogs.size());
assertEquals(logEntry, infoLogs.get(0));
}

@Test
void armRpoPollingFailed_shouldLogErrorWithEodId_whenProvidedWithExecutionId() {
armLoggerService.armRpoPollingFailed(EXECUTION_ID);

var logEntry = String.format("ARM RPO Polling - Failed for execution Id = %s", EXECUTION_ID);

List<String> errorLogs = logCaptor.getErrorLogs();
assertEquals(1, errorLogs.size());
assertEquals(logEntry, errorLogs.get(0));
}
}

0 comments on commit 355249a

Please sign in to comment.