Skip to content

Commit

Permalink
PYIC-7797 Fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe-Edwards-GDS committed Jan 10, 2025
1 parent c647fbf commit 1709467
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 10 deletions.
8 changes: 5 additions & 3 deletions deploy/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2937,9 +2937,7 @@ Resources:
- !ImportValue AuditEventQueueEncryptionKeyArn
- KMSDecryptPolicy:
KeyId: !Ref DynamoDBKmsKey
- DynamoDBReadPolicy:
TableName: !Ref SessionsTable
- DynamoDBWritePolicy:
- DynamoDBCrudPolicy:
TableName: !Ref SessionsTable
- DynamoDBReadPolicy:
TableName: !Ref SessionCredentialsTable
Expand All @@ -2951,8 +2949,12 @@ Resources:
QueueName: !ImportValue AuditEventQueueName
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Sub arn:aws:secretsmanager:eu-west-2:*:secret:/${Environment}/core/self/ciConfig-*
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Sub arn:aws:secretsmanager:eu-west-2:*:secret:/${Environment}/core/credentialIssuers/ticf/connections/*/apiKey-*
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Sub arn:aws:secretsmanager:eu-west-2:*:secret:/${Environment}/core/cimitApi/apiKey-*
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Sub arn:aws:secretsmanager:eu-west-2:*:secret:/${Environment}/core/evcs/apiKey-*
AutoPublishAlias: live

ProcessCandidateIdentityFunctionLogGroup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import static uk.gov.di.ipv.core.library.enums.CandidateIdentityType.PENDING;
import static uk.gov.di.ipv.core.library.enums.CandidateIdentityType.REVERIFICATION;
import static uk.gov.di.ipv.core.library.enums.CandidateIdentityType.UPDATE;
import static uk.gov.di.ipv.core.library.helpers.LogHelper.LogField.LOG_CHECK_TYPE;
import static uk.gov.di.ipv.core.library.journeys.JourneyUris.JOURNEY_COI_CHECK_FAILED_PATH;
import static uk.gov.di.ipv.core.library.journeys.JourneyUris.JOURNEY_ERROR_PATH;
import static uk.gov.di.ipv.core.library.journeys.JourneyUris.JOURNEY_NEXT_PATH;
Expand Down Expand Up @@ -295,6 +296,9 @@ private Map<String, Object> processCandidateThroughJourney(
CredentialParseException, ParseException {
if (COI_CHECK_TYPES.contains(processIdentityType)) {
var coiCheckType = getCoiCheckType(processIdentityType, clientOAuthSessionItem);
LOGGER.info(
LogHelper.buildLogMessage("Performing COI check")
.with(LOG_CHECK_TYPE.getFieldName(), coiCheckType.name()));
var isCoiCheckSuccessful =
checkCoiService.isCoiCheckSuccessful(
ipvSessionItem,
Expand All @@ -310,6 +314,7 @@ private Map<String, Object> processCandidateThroughJourney(
}

if (PROFILE_MATCHING_TYPES.contains(processIdentityType)) {
LOGGER.info(LogHelper.buildLogMessage("Performing profile evaluation"));
var journey =
getJourneyResponseForProfileMatching(
ipvSessionItem,
Expand All @@ -325,6 +330,7 @@ private Map<String, Object> processCandidateThroughJourney(
}

if (configService.getBooleanParameter(CREDENTIAL_ISSUER_ENABLED, Cri.TICF.getId())) {
LOGGER.info(LogHelper.buildLogMessage("Performing TICF CRI call"));
var journey =
getJourneyResponseFromTicfCall(
ipvSessionItem,
Expand All @@ -336,6 +342,7 @@ private Map<String, Object> processCandidateThroughJourney(
if (journey != null) {
// We still store a pending identity - it might be mitigating an existing CI
if (PENDING.equals(processIdentityType)) {
LOGGER.info(LogHelper.buildLogMessage("Storing identity"));
storeIdentityService.storeIdentity(
ipvSessionItem,
clientOAuthSessionItem,
Expand All @@ -350,6 +357,7 @@ private Map<String, Object> processCandidateThroughJourney(
}

if (STORE_IDENTITY_TYPES.contains(processIdentityType)) {
LOGGER.info(LogHelper.buildLogMessage("Storing identity"));
storeIdentityService.storeIdentity(
ipvSessionItem,
clientOAuthSessionItem,
Expand Down Expand Up @@ -398,15 +406,13 @@ private JourneyResponse getJourneyResponseForProfileMatching(
areVcsCorrelated);

if (votResult.isEmpty()) {
LOGGER.info(LogHelper.buildLogMessage("No GPG45 profiles have been met"));
return JOURNEY_PROFILE_UNMET;
}

ipvSessionItem.setVot(votResult.get().vot());
ipvSessionService.updateIpvSession(ipvSessionItem);

if (votResult.get().vot().getProfileType() == ProfileType.GPG45) {
LOGGER.info(LogHelper.buildLogMessage("A GPG45 profile has been met"));
sendProfileMatchedAuditEvent(
votResult.get(),
VcHelper.filterVCBasedOnProfileType(sessionVcs, ProfileType.GPG45),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"timestamp": {
"$resolver": "timestamp"
},
"instant": {
"epochSecond": {
"$resolver": "timestamp",
"epoch": {
"unit": "secs",
"rounded": true
}
},
"nanoOfSecond": {
"$resolver": "timestamp",
"epoch": {
"unit": "secs.nanos"
}
}
},
"thread": {
"$resolver": "thread",
"field": "name"
},
"level": {
"$resolver": "level",
"field": "name"
},
"loggerName": {
"$resolver": "logger",
"field": "name"
},
"message": {
"$resolver": "message"
},
"thrown": {
"message": {
"$resolver": "exception",
"field": "message"
},
"name": {
"$resolver": "exception",
"field": "className"
},
"extendedStackTrace": {
"$resolver": "exception",
"field": "stackTrace"
}
},
"contextStack": {
"$resolver": "ndc"
},
"endOfBatch": {
"$resolver": "endOfBatch"
},
"loggerFqcn": {
"$resolver": "logger",
"field": "fqcn"
},
"threadId": {
"$resolver": "thread",
"field": "id"
},
"threadPriority": {
"$resolver": "thread",
"field": "priority"
},
"source": {
"class": {
"$resolver": "source",
"field": "className"
},
"method": {
"$resolver": "source",
"field": "methodName"
},
"file": {
"$resolver": "source",
"field": "fileName"
},
"line": {
"$resolver": "source",
"field": "lineNumber"
}
},
"": {
"$resolver": "powertools"
}
}
22 changes: 22 additions & 0 deletions lambdas/process-candidate-identity/src/main/resources/log4j2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Configuration": {
"status": "warn",
"appenders": {
"Console": {
"name": "JsonAppender",
"target": "SYSTEM_OUT",
"JsonTemplateLayout": {
"eventTemplateUri": "classpath:IpvLambdaJsonLayout.json"
}
}
},
"Loggers": {
"Root": {
"level": "info",
"AppenderRef": {
"ref": "JsonAppender"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.StringMapMessage;
import uk.gov.di.ipv.core.library.annotations.ExcludeFromGeneratedCoverageReport;
import uk.gov.di.ipv.core.library.auditing.AuditEvent;
import uk.gov.di.ipv.core.library.auditing.AuditEventTypes;
Expand All @@ -22,6 +21,7 @@
import uk.gov.di.ipv.core.library.enums.CriResourceRetrievedType;
import uk.gov.di.ipv.core.library.exceptions.UnrecognisedVotException;
import uk.gov.di.ipv.core.library.exceptions.VerifiableCredentialException;
import uk.gov.di.ipv.core.library.helpers.LogHelper;
import uk.gov.di.ipv.core.library.persistence.item.ClientOAuthSessionItem;
import uk.gov.di.ipv.core.library.persistence.item.IpvSessionItem;
import uk.gov.di.ipv.core.library.service.AuditService;
Expand All @@ -40,7 +40,6 @@
import static uk.gov.di.ipv.core.library.domain.Cri.ADDRESS;
import static uk.gov.di.ipv.core.library.domain.Cri.TICF;
import static uk.gov.di.ipv.core.library.helpers.LogHelper.LogField.LOG_CRI_ID;
import static uk.gov.di.ipv.core.library.helpers.LogHelper.LogField.LOG_LAMBDA_RESULT;

public class CriStoringService {
private static final Logger LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -225,9 +224,7 @@ private void sendAuditEventForProcessedVcResponse(

var criId = cri.getId();
LOGGER.info(
new StringMapMessage()
.with(
LOG_LAMBDA_RESULT.getFieldName(),
LogHelper.buildLogMessage(
String.format(
"Successfully processed %s CRI credential.",
criResourceRetrievedType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Optional<VotMatchingResult> matchFirstVot(
return Optional.of(new VotMatchingResult(vot, null, null));
}
}
LOGGER.info(LogHelper.buildLogMessage("No profiles met"));
return Optional.empty();
}

Expand Down

0 comments on commit 1709467

Please sign in to comment.