-
Notifications
You must be signed in to change notification settings - Fork 90
feat(v2): Add GraalVM reachability metadata for core utilities #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @rr-on-gh, I tested the For reference, this is my test Lambda handler: @Named("test")
public class TestLambda implements RequestHandler<InputObject, OutputObject> {
@Inject
ProcessingService service;
private final static Logger logger = Logger.getLogger(TestLambda.class);
private final static MetricsLogger metricsLogger = MetricsUtils.metricsLogger();
@Override
@Metrics(namespace = "QuarkusApp", service = "powertools")
public OutputObject handleRequest(InputObject input, Context context) {
logger.info("Quarkus Jboss Log."); // Logging with Jboss is not yet supported by Powertools
long startTime = System.currentTimeMillis();
final OutputObject output = service.process(input).setRequestId(context.getAwsRequestId());
metricsLogger.putMetric("ExecutionTime", System.currentTimeMillis() - startTime, Unit.MILLISECONDS);
metricsLogger.putMetric("Invocation", 1, Unit.COUNT);
return output;
}
} When I compile this using
The CloudWatch EMF dependency seems to think we are running in an agent-based environment and tries to connect to a CloudWatch agent endpoint on localhost. If I instruct the --- a/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java
+++ b/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java
@@ -22,8 +22,10 @@ import static software.amazon.lambda.powertools.metrics.internal.LambdaMetricsAs
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;
+
import software.amazon.cloudwatchlogs.emf.config.SystemWrapper;
import software.amazon.cloudwatchlogs.emf.environment.EnvironmentProvider;
+import software.amazon.cloudwatchlogs.emf.environment.LambdaEnvironment;
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
import software.amazon.cloudwatchlogs.emf.model.MetricsContext;
@@ -37,7 +39,7 @@ import software.amazon.cloudwatchlogs.emf.model.Unit;
* {@see Metrics}
*/
public final class MetricsUtils {
- private static final MetricsLogger metricsLogger = new MetricsLogger();
+ private static final MetricsLogger metricsLogger = new MetricsLogger(new LambdaEnvironment());
private static DimensionSet[] defaultDimensions;
private MetricsUtils() { Output:
Note: This behavior does not occur when using JVM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rr-on-gh for updating the PR and providing the GraalVM.md
as documentation. It is clear now how you generated the GraalVM files. I only added a few minor comments regarding markdown issues.
I also tested the example you provided without problems.
```shell | ||
export JAVA_HOME=<path to GraalVM> | ||
```` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one backtick too much at the end. And can you remove the indentation inside the code block?
|
||
- Build the Docker image that will be used as the environment for SAM build: | ||
```shell | ||
docker build --platform linux/amd64 . -t powertools-examples-core-sam-graalvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove indentation.
|
||
- Build the SAM project using the docker image | ||
```shell | ||
sam build --use-container --build-image powertools-examples-core-sam-graalvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove indentation.
I also resolved the log4j version conflict with the |
…tEnvironmentVariable annotation to override env variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Removing the static mocks is a big improvement and allows us to avoid skipping the unit tests using static mock.
Next step is to update the GraalVM.md
documentation with the updated process of generating the metadata files.
@@ -62,6 +59,9 @@ | |||
import org.junit.jupiter.api.BeforeEach; | |||
import org.junit.jupiter.api.Test; | |||
import org.junit.jupiter.params.ParameterizedTest; | |||
import org.junitpioneer.jupiter.ClearEnvironmentVariable; | |||
import org.junitpioneer.jupiter.SetEnvironmentVariable; | |||
import org.junitpioneer.jupiter.SetSystemProperty; | |||
import org.mockito.Mock; | |||
import org.mockito.MockedStatic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is unused now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same for SystemWrapper
in line 73.
...n/src/main/java/software/amazon/lambda/powertools/common/internal/UserAgentConfigurator.java
Show resolved
Hide resolved
I pushed a small fix to this PR e879e06. This unit test was failing in native mode ( Now, all tests pass when I run mvn -Pgenerate-graalvm-files clean test && mvn -Pgraalvm-native clean test |
Next steps for this PR:
|
…x/improve typos/language in documentation.
|
I pushed some smaller cosmetic changes. This PR is ready to be merged as an initial version of GraalVM support for the core utilities. We need to iterate more on GraalVM, such as debugging support with Quarkus native images and adding GraalVM as additional tests in the GitHub workflows and end-to-end tests. I will create follow-up issues for these topics. |
Issue #, if available: #764
Description of changes:
Adding GraalVM reachability metadata files for
logging
,metrics
andtracing
modules. Also added a SAM based sample application to demonstrate the usage.Checklist
Breaking change checklist
RFC issue #:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.