Skip to content
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

Automatically populate PropertySource with instance metadata when running within an EC2-based environment #962

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kennyk65
Copy link

@kennyk65 kennyk65 commented Nov 16, 2023

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

A new package added to the autoconfigure project (with test classes) to populate a PropertySource whenever IMDS is present, which occurs on EC2, ElasticBeanstalk, ECS, EKS, etc. Auto configuration silently ignores the absence of IMDS. A starter pom is added, docs are updated.

💡 Motivation and Context

Issue addressed is: #954
There are various times when an application needs to know its IP address, availability zone, region, mac address, etc. All this is available via IMDS. This feature simply adds these properties to the Environment when available.

💚 How did you test it?

Three new classes, three new JUnit tests. Plus I created a sample application using the libraries for a sanity test.

📝 Checklist

  • [ x] I reviewed submitted code
  • [x ] I added tests to verify changes
  • [x ] I updated reference documentation to reflect the change
  • [ x] All tests passing
  • [x ] No breaking changes

🔮 Next steps

Others may wish to expand this to retrieve dynamic data, user data, set a common prefix, etc. May want to use a ConfigProperties only to cause the one and only property to be documented.

@github-actions github-actions bot added type: dependency-upgrade Dependency version bump type: documentation Documentation or Samples related issue labels Nov 16, 2023
@maciejwalkowiak
Copy link
Contributor

Thanks @kennyk65 for a PR! We need an integration test for that. Until Localstack supports metadata endpoint (localstack/localstack#8911) we would need to mock it - ideally with WireMock, to make sure whole flow works as expected.

Copy link
Contributor

@maciejwalkowiak maciejwalkowiak left a comment

Choose a reason for hiding this comment

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

Overall - great stuff! Thanks a lot! While most comments are details, an integration test is a must to merge it.

docs/src/main/asciidoc/imds.adoc Outdated Show resolved Hide resolved
public void init() {
if (!imdsUtils.isRunningOnCloudEnvironment())
return;
properties.putAll(imdsUtils.getEc2InstanceMetadata());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking if there should not be an option to add prefix for properties retrieved with Imds. For example, profile property can already come from another property source and in such case it would be overwritten.

Copy link
Author

Choose a reason for hiding this comment

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

I thought about that, but wanted to limit the scope for the initial commit. This is my first one and it was starting to get big.

ImdsPropertySource propertySource = new ImdsPropertySource("test", mockUtils);
propertySource.init();

assertTrue("Resulting PropertySource should contain the test data",
Copy link
Contributor

Choose a reason for hiding this comment

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

not a dealbreaker and i can fix it myself, but we use AssertJ assertions so would be nice if you change it too for sake of consistency.

@maciejwalkowiak maciejwalkowiak added this to the 3.2.0 M2 milestone Mar 10, 2024
@maciejwalkowiak maciejwalkowiak self-assigned this Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: dependency-upgrade Dependency version bump type: documentation Documentation or Samples related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants