Skip to content

Commit

Permalink
PYIC-7746: Embedded metrics with powertools (#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wynndow authored Dec 17, 2024
2 parents ad6a779 + badf4e0 commit d977399
Show file tree
Hide file tree
Showing 48 changed files with 121 additions and 132 deletions.
23 changes: 2 additions & 21 deletions deploy/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Globals:
Runtime: java17
Environment:
Variables:
ENVIRONMENT: !Sub "${Environment}"
AWS_LAMBDA_EXEC_WRAPPER: !If
- IsDevelopment
- !Ref AWS::NoValue
Expand Down Expand Up @@ -51,6 +52,7 @@ Globals:
DT_OPEN_TELEMETRY_ENABLE_INTEGRATION: "true"
OTEL_INSTRUMENTATION_AWS_SDK_EXPERIMENTAL_USE_PROPAGATOR_FOR_MESSAGING: true
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
POWERTOOLS_METRICS_NAMESPACE: !Sub CoreBackEmbeddedMetrics-${Environment}
POWERTOOLS_TRACER_CAPTURE_RESPONSE: false
POWERTOOLS_TRACER_CAPTURE_ERROR: false
CONFIG_SERVICE_CACHE_DURATION_MINUTES: !If
Expand Down Expand Up @@ -665,7 +667,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub issue-client-access-token-${Environment}
CLIENT_AUTH_JWT_IDS_TABLE_NAME: !Ref ClientAuthJwtIdsTable
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
Expand Down Expand Up @@ -742,7 +743,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub build-client-oauth-response-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
SQS_AUDIT_EVENT_QUEUE_URL: !ImportValue AuditEventQueueUrl
Expand Down Expand Up @@ -825,7 +825,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub initialise-ipv-session-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
SQS_AUDIT_EVENT_QUEUE_URL: !ImportValue AuditEventQueueUrl
Expand Down Expand Up @@ -930,7 +929,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub build-cri-oauth-request-${Environment}
SQS_AUDIT_EVENT_QUEUE_URL: !ImportValue AuditEventQueueUrl
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
Expand Down Expand Up @@ -1029,7 +1027,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub process-cri-callback-${Environment}
SQS_AUDIT_EVENT_QUEUE_URL: !ImportValue AuditEventQueueUrl
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
Expand Down Expand Up @@ -1149,7 +1146,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub process-mobile-app-callback-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CRI_OAUTH_SESSIONS_TABLE_NAME: !Ref CriOAuthSessionsTable
Expand Down Expand Up @@ -1238,7 +1234,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub check-mobile-app-vc-receipt-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CRI_RESPONSE_TABLE_NAME: !Ref CRIResponseTable
Expand Down Expand Up @@ -1339,7 +1334,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub build-user-identity-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -1431,7 +1425,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub user-reverification-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -1659,7 +1652,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub process-journey-event-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CRI_OAUTH_SESSIONS_TABLE_NAME: !Ref CriOAuthSessionsTable
Expand Down Expand Up @@ -1741,7 +1733,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub evaluate-gpg45-scores-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -1830,7 +1821,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub build-proven-user-identity-details-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -1922,7 +1912,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub check-existing-identity-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
SESSION_CREDENTIALS_TABLE_NAME: !Ref SessionCredentialsTable
Expand Down Expand Up @@ -2016,7 +2005,6 @@ Resources:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
CRI_RESPONSE_TABLE_NAME: !Ref CRIResponseTable
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub process-async-cri-credential-${Environment}
SQS_AUDIT_EVENT_QUEUE_URL: !ImportValue AuditEventQueueUrl
VpcConfig:
Expand Down Expand Up @@ -2135,7 +2123,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub check-gpg45-score-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -2205,7 +2192,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub call-ticf-cri-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -2291,7 +2277,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub call-dcmaw-async-cri-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -2368,7 +2353,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub store-identity-${Environment}
SESSION_CREDENTIALS_TABLE_NAME: !Ref SessionCredentialsTable
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
Expand Down Expand Up @@ -2448,7 +2432,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub reset-session-identity-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
SESSION_CREDENTIALS_TABLE_NAME: !Ref SessionCredentialsTable
Expand Down Expand Up @@ -2530,7 +2513,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub check-coi-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down Expand Up @@ -2612,7 +2594,6 @@ Resources:
Environment:
# checkov:skip=CKV_AWS_173: These environment variables do not require encryption.
Variables:
ENVIRONMENT: !Sub "${Environment}"
POWERTOOLS_SERVICE_NAME: !Sub check-reverification-identity-${Environment}
IPV_SESSIONS_TABLE_NAME: !Ref SessionsTable
CLIENT_OAUTH_SESSIONS_TABLE_NAME: !Ref ClientOAuthSessionsTable
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ openTelemetryJavaHttpClient = { module = "io.opentelemetry.instrumentation:opent
pactConsumerJunit = { module = "au.com.dius.pact.consumer:junit5", version.ref = "pact" }
pactProviderJunit = { module = "au.com.dius.pact.provider:junit5", version.ref = "pact" }
powertoolsLogging = { module = "software.amazon.lambda:powertools-logging", version.ref = "powertools" }
powertoolsMetrics = { module = "software.amazon.lambda:powertools-metrics", version.ref = "powertools" }
powertoolsParameters = { module = "software.amazon.lambda:powertools-parameters", version.ref = "powertools" }
powertoolsTracing = { module = "software.amazon.lambda:powertools-tracing", version.ref = "powertools" }
systemStubs = "uk.org.webcompere:system-stubs-jupiter:2.1.3"
Expand Down
4 changes: 0 additions & 4 deletions lambdas/build-client-oauth-response/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ dependencies {
project(":libs:common-services"),
project(":libs:audit-service")

aspect libs.powertoolsLogging,
libs.powertoolsTracing,
libs.aspectj

testImplementation libs.junitJupiter,
libs.mockitoJunit,
libs.hamcrest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.StringMapMessage;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.Tracing;
import uk.gov.di.ipv.core.buildclientoauthresponse.domain.ClientDetails;
import uk.gov.di.ipv.core.buildclientoauthresponse.domain.ClientResponse;
Expand Down Expand Up @@ -96,6 +97,7 @@ public BuildClientOauthResponseHandler(
@Override
@Tracing
@Logging(clearState = true)
@Metrics(captureColdStart = true)
public Map<String, Object> handleRequest(JourneyRequest input, Context context) {

LogHelper.attachComponentId(configService);
Expand Down
4 changes: 0 additions & 4 deletions lambdas/build-cri-oauth-request/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ dependencies {
project(":libs:user-identity-service"),
project(":libs:oauth-key-service")

aspect libs.powertoolsLogging,
libs.powertoolsTracing,
libs.aspectj

compileOnly libs.lombok
annotationProcessor libs.lombok

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.StringMapMessage;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.Tracing;
import uk.gov.di.ipv.core.buildcrioauthrequest.domain.CriDetails;
import uk.gov.di.ipv.core.buildcrioauthrequest.domain.CriResponse;
Expand All @@ -38,6 +39,7 @@
import uk.gov.di.ipv.core.library.exceptions.VerifiableCredentialException;
import uk.gov.di.ipv.core.library.gpg45.Gpg45ProfileEvaluator;
import uk.gov.di.ipv.core.library.gpg45.Gpg45Scores;
import uk.gov.di.ipv.core.library.helpers.EmbeddedMetricHelper;
import uk.gov.di.ipv.core.library.helpers.LogHelper;
import uk.gov.di.ipv.core.library.helpers.SecureTokenHelper;
import uk.gov.di.ipv.core.library.oauthkeyservice.OAuthKeyService;
Expand Down Expand Up @@ -148,6 +150,7 @@ public BuildCriOauthRequestHandler(ConfigService configService) {
@Override
@Tracing
@Logging(clearState = true)
@Metrics(captureColdStart = true)
public Map<String, Object> handleRequest(CriJourneyRequest input, Context context) {
LogHelper.attachComponentId(configService);
try {
Expand Down Expand Up @@ -211,6 +214,8 @@ public Map<String, Object> handleRequest(CriJourneyRequest input, Context contex
auditEventUser,
new AuditRestrictedDeviceInformation(input.getDeviceInformation())));

EmbeddedMetricHelper.criRedirect(cri.getId());

var message =
new StringMapMessage()
.with(
Expand Down
4 changes: 0 additions & 4 deletions lambdas/build-proven-user-identity-details/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ dependencies {
project(":libs:verifiable-credentials"),
project(":libs:user-identity-service")

aspect libs.powertoolsLogging,
libs.powertoolsTracing,
libs.aspectj

compileOnly libs.lombok
annotationProcessor libs.lombok

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.Tracing;
import uk.gov.di.ipv.core.buildprovenuseridentitydetails.domain.ProvenUserIdentityDetails;
import uk.gov.di.ipv.core.buildprovenuseridentitydetails.exceptions.ProvenUserIdentityDetailsException;
Expand Down Expand Up @@ -74,6 +75,7 @@ public BuildProvenUserIdentityDetailsHandler() {
@Override
@Tracing
@Logging(clearState = true)
@Metrics(captureColdStart = true)
public APIGatewayProxyResponseEvent handleRequest(
APIGatewayProxyRequestEvent input, Context context) {
LogHelper.attachComponentId(configService);
Expand Down
4 changes: 0 additions & 4 deletions lambdas/build-user-identity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ dependencies {
project(":libs:user-identity-service"),
project(":libs:verifiable-credentials")

aspect libs.powertoolsLogging,
libs.powertoolsTracing,
libs.aspectj

testImplementation libs.hamcrest,
libs.junitJupiter,
libs.mockitoJunit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.nimbusds.oauth2.sdk.http.HTTPResponse;
import org.apache.logging.log4j.message.StringMapMessage;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.Tracing;
import uk.gov.di.ipv.core.library.annotations.ExcludeFromGeneratedCoverageReport;
import uk.gov.di.ipv.core.library.auditing.AuditEvent;
Expand Down Expand Up @@ -98,6 +99,7 @@ public BuildUserIdentityHandler() {
@Override
@Tracing
@Logging(clearState = true)
@Metrics(captureColdStart = true)
public APIGatewayProxyResponseEvent handleRequest(
APIGatewayProxyRequestEvent input, Context context) {

Expand Down
13 changes: 8 additions & 5 deletions lambdas/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ allprojects {

subprojects {
afterEvaluate { subproject ->
if (subproject.plugins.hasPlugin('java')) {
dependencies {
runtimeOnly platform(libs.openTelemetryBom),
libs.openTelemetryAwsSdkAutoConfigure
}
dependencies {
runtimeOnly platform(libs.openTelemetryBom),
libs.openTelemetryAwsSdkAutoConfigure

aspect libs.powertoolsLogging,
libs.powertoolsMetrics,
libs.powertoolsTracing,
libs.aspectj
}
}
}
4 changes: 0 additions & 4 deletions lambdas/call-dcmaw-async-cri/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ dependencies {
project(":libs:user-identity-service"),
project(":libs:verifiable-credentials")

aspect libs.powertoolsLogging,
libs.powertoolsTracing,
libs.aspectj

testImplementation libs.hamcrest,
libs.junitJupiter,
libs.mockitoJunit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.Tracing;
import uk.gov.di.ipv.core.calldcmawasynccri.exception.DcmawAsyncCriHttpResponseException;
import uk.gov.di.ipv.core.calldcmawasynccri.service.DcmawAsyncCriService;
Expand Down Expand Up @@ -94,6 +95,7 @@ public CallDcmawAsyncCriHandler(
@Override
@Tracing
@Logging(clearState = true)
@Metrics(captureColdStart = true)
public Map<String, Object> handleRequest(ProcessRequest request, Context context) {
LogHelper.attachComponentId(configService);
LogHelper.attachCriIdToLogs(DCMAW_ASYNC);
Expand Down
4 changes: 0 additions & 4 deletions lambdas/call-ticf-cri/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ dependencies {
project(":libs:user-identity-service"),
project(":libs:verifiable-credentials")

aspect libs.powertoolsLogging,
libs.powertoolsTracing,
libs.aspectj

testImplementation libs.hamcrest,
libs.junitJupiter,
libs.mockitoJunit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.lambda.powertools.tracing.Tracing;
import uk.gov.di.ipv.core.callticfcri.exception.TicfCriServiceException;
import uk.gov.di.ipv.core.callticfcri.service.TicfCriService;
Expand Down Expand Up @@ -107,6 +108,7 @@ public CallTicfCriHandler(
@Override
@Tracing
@Logging(clearState = true)
@Metrics(captureColdStart = true)
public Map<String, Object> handleRequest(ProcessRequest request, Context context) {
LogHelper.attachComponentId(configService);
LogHelper.attachCriIdToLogs(TICF);
Expand Down
Loading

0 comments on commit d977399

Please sign in to comment.