Skip to content

feat(v2): GraalVM support for parameters module #1824

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

Merged
merged 13 commits into from
May 26, 2025

Conversation

jreijn
Copy link
Contributor

@jreijn jreijn commented May 2, 2025

Issue #, if available: #1833

Description of changes:

Introduced GraalVM metadata for all submodules of the parameters module:

  • powertools-parameters
  • powertools-parameters-ssm
  • powertools-parameters-secrets
  • powertools-parameters-appconfig
  • powertools-parameters-dynamodb

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jreijn
Copy link
Contributor Author

jreijn commented May 2, 2025

I tried to follow the guide as mentioned by https://github.com/aws-powertools/powertools-lambda-java/blob/v2/GraalVM.md which helped a lot with generating the meta data.

However I do wonder if we need all the metadata generated by the GraalVM agent. In on of my projects where I used v1 of Powertools I only needed the following snippet to get the SecretsProvider to work:

[
  {
    "name" : "software.amazon.lambda.powertools.parameters.SecretsProvider",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  }
]

Now we have all sorts of java internal classes or classes coming from other libraries or the JVM, which I don't think we need? Shouldn't they be handled by the corresponding projects? I'm by no means a GraalVM expert, but I always understood it in such a way that metadata in a provided library only contains metadata about its own classes and resources which otherwise can't be reached.

@phipag phipag self-requested a review May 5, 2025 09:47
@phipag phipag assigned phipag and jreijn and unassigned phipag May 5, 2025
@phipag phipag moved this to Pending review in Powertools for AWS Lambda (Java) May 5, 2025
@phipag phipag linked an issue May 5, 2025 that may be closed by this pull request
7 tasks
@phipag phipag linked an issue May 8, 2025 that may be closed by this pull request
@phipag phipag linked an issue May 8, 2025 that may be closed by this pull request
@phipag
Copy link
Contributor

phipag commented May 8, 2025

Hi @jreijn,

I just review your changes and you did an amazing job 🚀 – especially cleaning up the test scoped dependencies in the generated metadata files. This helped us a lot.

I just verified that unit tests against the native image pass, which they do ✅

Before we go ahead merging this PR, I would love to do two things:

  1. Update the roadmap documentation page with the sub-issues and the progress made in the parameters module thanks to you (I can take care of this).
  2. Test this at runtime using the Parameters example we have and update the example to also include GraalVM -> https://github.com/aws-powertools/powertools-lambda-java/tree/v2/examples/powertools-examples-parameters
    • For this I would take this graalvm example as inspiration and provide the user with a template-native.yaml using provided.al2023 as runtime for the Lambda.

I am happy to also update the example and don't want to cause more work on your end. But let me know if you like to do it.


Regarding your comment:

Now we have all sorts of java internal classes or classes coming from other libraries or the JVM, which I don't think we need? Shouldn't they be handled by the corresponding projects? I'm by no means a GraalVM expert, but I always understood it in such a way that metadata in a provided library only contains metadata about its own classes and resources which otherwise can't be reached.

You are absolutely right here. Since we run the metadata generation via unit tests (which is uncommon) there is a risk of including "too much" metadata and this is something we can optimize in the future. This is also why the manual cleanup is needed. The unit tests are good candidate for now since they have pretty good coverage.

One way to address this which I tested was including a filter on the GraalVM tracing agent to only generate metadata for the library itself and not dependencies. However, this led to two issues:

  1. It requires customers to include metadata files for transitive dependencies that do not support GraalVM. For example, for X-RAY in the case of the tracing utility. We felt that this is a bad customer experience because the customer did not explicitly choose to include that transitive dependency.
  2. In some edge cases when we access something reflectively ourselves that is outside of the filter it would not be included. Hence, a lot of manual fine-tuning on the filter is necessary which we didn't do (yet).

Having said that, there is a lot of potential on improving this and before going to production with v2 we will do some improvements (e.g. running integ tests for both JVM and GraalVM native images #1805).

It seems like in the parameters example that you also tested in v1 using GraalVM, we can definitely reduce the generated metadata files. For now, I would like to be consistent with the other modules and improve this consistently in the future. What are your thoughts on this? Happy to have a discussion, also in a short meeting if you like.

@jreijn
Copy link
Contributor Author

jreijn commented May 8, 2025

@phipag thanks for the feedback!

With regards to the two open items:

  1. it would be great if you can do that

  2. I will pick that up and update the example. I'll see if I can find some time over the next couple of days.

With regard to the reflection metadata I see your point. I'm fine with leaving it for now and improving it later. Once we get to that point I would love to brainstorm a bit about it and see how I can contribute.

@phipag
Copy link
Contributor

phipag commented May 9, 2025

Thanks @jreijn, this sounds like a good plan. Awesome that you would like to update the example as well! I'll be waiting for your update here and try to review it promptly.

Regarding the roadmap update, I will take care of this as part of a separate PR since I am already working on a different documentation update.


Next steps: Wait for powertools-examples-parameters update and review it to close this PR.

@phipag
Copy link
Contributor

phipag commented May 20, 2025

Hey @jreijn,
I would love to close this PR by the end of the week. Let me know if you are still working on this, otherwise I am happy to take over updating the example. Thanks again for your contributions so far!

@jreijn
Copy link
Contributor Author

jreijn commented May 20, 2025

@phipag I'm sorry for the delay. I will pick it up tomorrow! Sorry I had a busy couple of weeks!

@phipag
Copy link
Contributor

phipag commented May 21, 2025

@jreijn, no problem, we all know these busy weeks. Thanks for your quick reply. I'll be waiting for your updates.

@jreijn
Copy link
Contributor Author

jreijn commented May 23, 2025

@phipag I'm close to pushing my changes. Found some missing reflection config for the transformer that were not picked up by the tests. I'll try to push them tomorrow morning with working examples.

@jreijn
Copy link
Contributor Author

jreijn commented May 26, 2025

@phipag I've added the working example and tested it (it took me a bit longer then expected). I did find something in parameter module that wasn't obvious. If you have some more time before the release I was thinking of moving the powertools-parameters/src into powertools-parameters-core (as it's used by all parameters modules) and merge that with powertools-parameters/powertools-parameters-tests as those seem to be the tests for those classes as far as I can tell. That would allow for easy generation of graalvm metadata in the core module itself and. It also would make the maven structure a bit more standard. WDYT?

@phipag
Copy link
Contributor

phipag commented May 26, 2025

Thanks for your update @jreijn ! I will review it today.

Regarding your suggestion, this is an interesting point. Especially the fact that the tests have a dedicated package but not the core logic. I don't see a reason (right now) why not do it. I will test this and might update it before the final v2 release (target for end of Q2).

That would allow for easy generation of graalvm metadata in the core module itself

What do you mean by "easy generation". Is it easier to generate the GRM files with that new structure?

Edit: Ignore the failing workflows. It seems that GitHub is experiencing problems. https://www.githubstatus.com/

@jreijn
Copy link
Contributor Author

jreijn commented May 26, 2025

What do you mean by "easy generation". Is it easier to generate the GRM files with that new structure?

@phipag Right now I've added the graalvm maven profiles, to generate the metadata, to the powertools-parameters-test maven module and moved the generated metadata to the core sources META-INF folder. As the powertools-parameters/powertools-parameters-tests module is not used as a dependency (which they should not) for parameters-ssm, etc.

Merging tests and the src folder would allow for the same proces as in any other submodule of the project.

@phipag
Copy link
Contributor

phipag commented May 26, 2025

Hey @jreijn,

I sent a few very small commits addressing some typos and other cosmetic things. I tested your example and deployed it in my AWS account and it works perfectly. I tested it both from Mac using podman compilation and also natively from an Amazon Linux machine.

See my comment above regarding the SecretsParams file. Why did you create this file? I believe it was by accident but let me know if I missed something. Feel free to delete it otherwise and then we can merge this PR.

phipag and others added 3 commits May 26, 2025 16:26
@phipag phipag self-requested a review May 26, 2025 14:28
@@ -1,5 +1,5 @@
build-ParametersFunction:

Copy link
Contributor Author

@jreijn jreijn May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! It seems I forgot to add it back after my final tests.

Copy link

@phipag phipag moved this from Pending review to Coming soon in Powertools for AWS Lambda (Java) May 26, 2025
Copy link
Contributor

@phipag phipag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jreijn for your contribution. This looks very nice to me and your work is much appreciated.

This will be released as part of Powertools 2.0.0 becoming generally available in the upcoming few weeks.

@phipag phipag merged commit 00198dd into aws-powertools:v2 May 26, 2025
13 of 14 checks passed
@jreijn
Copy link
Contributor Author

jreijn commented May 26, 2025

@phipag that's awesome! Can't wait to try it out! Will start working on the next GraalVM module!

@phipag
Copy link
Contributor

phipag commented May 26, 2025

Looking forward to this! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Coming soon
Development

Successfully merging this pull request may close these issues.

feat(v2): GraalVM support for Parameters utility
2 participants