Skip to content

Commit a1651ae

Browse files
committed
Cleaned up documentation and fixed review comments
1 parent e879e06 commit a1651ae

File tree

3 files changed

+11
-143
lines changed

3 files changed

+11
-143
lines changed

GraalVM.md

Lines changed: 11 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
- [General Implementation Steps](#general-implementation-steps)
77
- [Known Issues and Solutions](#known-issues-and-solutions)
88
- [Reference Implementation](#reference-implementation)
9-
- [Module-Specific Implementation](#module-specific-implementation)
10-
- [1. Powertools Common](#1-powertools-common)
11-
- [2. Powertools Logging](#2-powertools-logging)
12-
- [2.1 Powertools Logging (log4j)](#21-powertools-logging-log4j)
13-
- [2.2 Powertools Logging (logback)](#22-powertools-logging-logback)
14-
- [3. Powertools Metrics](#3-powertools-metrics)
159

1610
## Overview
1711
This documentation provides guidance for adding GraalVM support for AWS Lambda Powertools Java modules and using the modules in Lambda functions.
@@ -31,13 +25,17 @@ In order to generate the metadata reachability files for Powertools for Lambda,
3125

3226
2. **Generate Reachability Metadata**
3327
- Set the `JAVA_HOME` environment variable to use GraalVM
34-
- Run tests with `-Pgenerate-graalvm-files` profile. You can find module specific commands in the [Module-Specific Implementation](#module-specific-implementation) section
35-
- Some tests may need to be skipped depending on the module
28+
- Run tests with `-Pgenerate-graalvm-files` profile.
29+
```shell
30+
mvn -Pgenerate-graalvm-files clean test
31+
```
3632

3733
3. **Validate Native Image Tests**
3834
- Set the `JAVA_HOME` environment variable to use GraalVM
39-
- Run tests with `-Pgraalvm-native` profile. This will build a GraalVM native image and run the JUnit tests. You can find module specific commands in the [Module-Specific Implementation](#module-specific-implementation) section
40-
- Verify test execution in native mode
35+
- Run tests with `-Pgraalvm-native` profile. This will build a GraalVM native image and run the JUnit tests.
36+
```shell
37+
mvn -Pgraalvm-native clean test
38+
```
4139

4240
4. **Clean Up Metadata**
4341
- GraalVM metadata reachability files generated in Step 2 contains references to the test scoped dependencies as well.
@@ -47,142 +45,16 @@ In order to generate the metadata reachability files for Powertools for Lambda,
4745
- ByteBuddy
4846

4947
## Known Issues and Solutions
50-
5148
1. **Mockito Compatibility**
52-
- Powertools uses Mockito 5.x which uses “inline mock maker” as the default. This mock maker does not play well with GraalVM. Mockito [recommends](https://github.com/mockito/mockito/releases/tag/v5.0.0) using subclass mock maker with GraalVM.
53-
- However, subclass mock maker does not support testing static methods. Some test cases in Powertools uses inline mock maker to mock static methods. These tests have to be skipped while generating the GraalVM reachability metadata files.
54-
- This obviously affects the coverage and possibility of missing a required entry in GRM files. At this point we are relying on community to report any missing entries and will update the GRM based on the reports.
55-
- This issue remains open until ability of test static methods in Mockito 5.x/inline mock maker is available.
49+
- Powertools uses Mockito 5.x which uses “inline mock maker” as the default. This mock maker does not play well with GraalVM. Mockito [recommends](https://github.com/mockito/mockito/releases/tag/v5.0.0) using subclass mock maker with GraalVM. Therefore `generate-graalvm-files` profile uses subclass mock maker instead of inline mock maker.
50+
- Subclass mock maker does not support testing static methods. Tests have therefore been modified to use [JUnit Pioneer](https://junit-pioneer.org/docs/environment-variables/) to inject the environment variables in the scope of the test's execution.
5651

5752
2. **Log4j Compatibility**
5853
- Version 2.22.1 fails with this error
5954
```
6055
java.lang.InternalError: com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining hidden classes at runtime is not supported.
6156
```
62-
- This has been [fixed](https://github.com/apache/logging-log4j2/discussions/2364#discussioncomment-8950077) in Log4j 2.24.0. PT has been updated to use this version of Log4j
63-
57+
- This has been [fixed](https://github.com/apache/logging-log4j2/discussions/2364#discussioncomment-8950077) in Log4j 2.24.x. PT has been updated to use this version of Log4j
6458

6559
## Reference Implementation
6660
Working example is available in the [examples](examples/powertools-examples-core-utilities/sam-graalvm).
67-
68-
## Module-Specific Implementation
69-
Due to the Mockito issues described in the [Known Issues and Solutions](#known-issues-and-solutions) section, some tests needs to be skipped when generating the GRM files. This section shows the commands that need to be used for the modules.
70-
71-
### 1. Powertools Common
72-
73-
Generate metadata files
74-
```shell
75-
76-
mvn \
77-
-Dtest=\
78-
\!UserAgentConfiguratorTest#testGetVersionFromProperties_InvalidFile,\
79-
\!UserAgentConfiguratorTest#testGetVersion,\
80-
\!UserAgentConfiguratorTest#testGetUserAgent_SetAWSExecutionEnv,\
81-
\!LambdaHandlerProcessorTest#serviceName_Undefined,\
82-
\!LambdaHandlerProcessorTest#serviceName,\
83-
\!LambdaHandlerProcessorTest#isSamLocal,\
84-
\!LambdaHandlerProcessorTest#getXrayTraceId_present,\
85-
\!LambdaHandlerProcessorTest#getXrayTraceId_notPresent \
86-
-Pgenerate-graalvm-files clean test
87-
```
88-
89-
Run native tests
90-
```shell
91-
92-
mvn \
93-
-Dtest=\
94-
\!UserAgentConfiguratorTest#testGetVersionFromProperties_InvalidFile,\
95-
\!UserAgentConfiguratorTest#testGetVersion,\
96-
\!UserAgentConfiguratorTest#testGetUserAgent_SetAWSExecutionEnv,\
97-
\!LambdaHandlerProcessorTest#serviceName_Undefined,\
98-
\!LambdaHandlerProcessorTest#serviceName,\
99-
\!LambdaHandlerProcessorTest#isSamLocal,\
100-
\!LambdaHandlerProcessorTest#getXrayTraceId_present,\
101-
\!LambdaHandlerProcessorTest#getXrayTraceId_notPresent \
102-
-Pgraalvm-native clean test
103-
104-
```
105-
106-
### 2. Powertools Logging
107-
108-
Generate metadata files
109-
```shell
110-
111-
mvn -Dtest=\!LambdaLoggingAspectTest#shouldLogxRayTraceIdEnvVarSet,\
112-
\!LambdaLoggingAspectTest#shouldLogxRayTraceIdSystemPropertySet \
113-
-Pgenerate-graalvm-files clean test
114-
115-
```
116-
117-
Run native tests
118-
```shell
119-
120-
mvn -Dtest=\!LambdaLoggingAspectTest#shouldLogxRayTraceIdEnvVarSet,\
121-
\!LambdaLoggingAspectTest#shouldLogxRayTraceIdSystemPropertySet \
122-
-Pgraalvm-native clean test
123-
124-
```
125-
#### 2.1 Powertools Logging (log4j)
126-
127-
Generate metadata files
128-
```shell
129-
130-
mvn -Dtest=\!PowertoolsResolverTest#shouldResolveRegion \
131-
-Pgenerate-graalvm-files clean test
132-
133-
```
134-
135-
Run native tests
136-
```shell
137-
138-
mvn -Dtest=\!PowertoolsResolverTest#shouldResolveRegion \
139-
-Pgraalvm-native clean test
140-
141-
```
142-
143-
#### 2.2 Powertools Logging (logback)
144-
145-
Generate metadata files
146-
```shell
147-
148-
mvn -Dtest=\!MetricsLoggerTest#shouldLogxRayTraceIdEnvVarSet,\
149-
\!MetricsLoggerTest#shouldLogxRayTraceIdSystemPropertySet \
150-
-Pgenerate-graalvm-files clean test
151-
152-
```
153-
154-
Run native tests
155-
```shell
156-
157-
mvn -Dtest=\!MetricsLoggerTest#shouldLogxRayTraceIdEnvVarSet,\
158-
\!MetricsLoggerTest#shouldLogxRayTraceIdSystemPropertySet \
159-
-Pgraalvm-native clean test
160-
```
161-
162-
### 3. Powertools Metrics
163-
* All tests need to mock static methods.
164-
* Comment out the references to `mockStatic` in the JUnits and set the env variables explicitly
165-
* Also pass the system property via mvn build cli
166-
167-
Generate metadata files
168-
```shell
169-
170-
export AWS_EMF_ENVIRONMENT="Lambda"
171-
export _X_AMZN_TRACE_ID="Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1"
172-
export POWERTOOLS_METRICS_NAMESPACE="GlobalName"
173-
174-
mvn -Dcom.amazonaws.xray.traceHeader="Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1" \
175-
-Pgenerate-graalvm-files clean test
176-
```
177-
178-
Run native tests
179-
```shell
180-
181-
export AWS_EMF_ENVIRONMENT="Lambda"
182-
export _X_AMZN_TRACE_ID="Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1"
183-
export POWERTOOLS_METRICS_NAMESPACE="GlobalName"
184-
185-
mvn -Dcom.amazonaws.xray.traceHeader="Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1" \
186-
-Pgraalvm-native clean test
187-
188-
```

powertools-common/src/test/resources/unreadable.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,12 @@
6363
import org.junitpioneer.jupiter.SetEnvironmentVariable;
6464
import org.junitpioneer.jupiter.SetSystemProperty;
6565
import org.mockito.Mock;
66-
import org.mockito.MockedStatic;
6766
import org.slf4j.Logger;
6867
import org.slf4j.LoggerFactory;
6968
import org.slf4j.MDC;
7069
import org.slf4j.event.Level;
7170
import org.slf4j.test.TestLogger;
7271
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
73-
import software.amazon.lambda.powertools.common.internal.SystemWrapper;
7472
import software.amazon.lambda.powertools.logging.argument.KeyValueArgument;
7573
import software.amazon.lambda.powertools.logging.handlers.PowertoolsLogAlbCorrelationId;
7674
import software.amazon.lambda.powertools.logging.handlers.PowertoolsLogApiGatewayHttpApiCorrelationId;

0 commit comments

Comments
 (0)