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

Spring Boot Properties Migrator - Detect properties of Map type that are marked as deprecated #28796

Closed
wants to merge 2 commits into from

Conversation

dominiccroce
Copy link

@dominiccroce dominiccroce commented Nov 24, 2021

Addresses #27854 with unit test demonstrating desired functionality

@pivotal-cla
Copy link

@dominiccroce Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@dominiccroce Thank you for signing the Contributor License Agreement!

@dominiccroce

This comment has been minimized.

Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks for the PR but it doesn't address the issue.

It looks like there is some confusion between MapPropertySource (an implementation detail, irrelevant to this issue) and a property that happens to be of type map.

I think one way of fixing this would be to patch getMatchingProperties. Right now, it looks for an exact match but we could also look for properties that would match the prefix if the property is deprecated.

Would you be willing to give it another try? No problem if you can't, I can take over.

}));
return result;
}

private void getMatchingPropertiesForMapEntries(String name, ConfigurationPropertySource source,
ConfigurationMetadataProperty metadata, MultiValueMap<String, PropertyMigration> result) {
if (source.getUnderlyingSource() instanceof MapPropertySource && name.equals(metadata.getName())) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what this is doing. MapPropertySource is an implementation detail and you shouldn't be looking at it. It has nothing to do with a deprecated property that is of type Map.

Copy link
Author

Choose a reason for hiding this comment

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

I see, I thought MapPropertySource indicated the Map deprecation. But if we don't have a way to filter for Map deprecations than agreed it must be done by prefix matching on the name itself.

content.put("status.http-mapping.down", 500);
content.put("status.http-mapping.out-of-service", 503);
content.put("status.http-mapping.warning", 500);
propertySources.addFirst(new MapPropertySource("status.http-mapping", content));
Copy link
Member

Choose a reason for hiding this comment

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

If I change the name of the property source to be something else than this, the test fails. The PropertySource implementation and its name are irrelevant for this, it could be anything.

Copy link
Author

Choose a reason for hiding this comment

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

Nothing is name specific, but yes it is specific to MapPropertySource

Copy link
Member

Choose a reason for hiding this comment

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

It is. Replace new MapPropertySource("status.http-mapping", content) by new MapPropertySource("test", content) and you'll see. The name of the property source has nothing to do whatsoever with the prefix used by the keys.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Dec 10, 2021
@dominiccroce
Copy link
Author

Thanks for the PR but it doesn't address the issue.

It looks like there is some confusion between MapPropertySource (an implementation detail, irrelevant to this issue) and a property that happens to be of type map.

I think one way of fixing this would be to patch getMatchingProperties. Right now, it looks for an exact match but we could also look for properties that would match the prefix if the property is deprecated.

Would you be willing to give it another try? No problem if you can't, I can take over.

I have pushed a new commit to address the issues. The main problem I am facing is for any PropertyResource, I want to be able to iterate through the ConfigurationPropertyNames. Once we have those, I rely on existing code to handle prefix matching. From there I handle prefix matching. I am lacking some context on PropertySource but feels like there should be a way to get all PropertyNames without casting to IterableConfigurationPropertySource.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 10, 2021
Comment on lines +117 to +119
if (source instanceof IterableConfigurationPropertySource)
((IterableConfigurationPropertySource) source).iterator().forEachRemaining(configurationPropertyName -> {
ConfigurationProperty configurationProperty = source.getConfigurationProperty(configurationPropertyName);
Copy link
Author

Choose a reason for hiding this comment

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

This should be easier, something like source.getConfigurationProperties() would be nice API to add. Not sure if it belongs on PropertySource though

Copy link
Member

Choose a reason for hiding this comment

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

How about using filter?

Copy link
Member

Choose a reason for hiding this comment

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

@dominiccroce do you want to get another look at it? filter takes a predicate and should lets you filter the propertysource with only the keys that are relevant. I haven't tried but I think it's worth exploring.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 15, 2021
@snicoll
Copy link
Member

snicoll commented Mar 21, 2022

@dominiccroce thanks but I think we will have to restart this one from scratch I am afraid. The last changes are breaking existing tests and we should really consider looking at filter.

@snicoll snicoll closed this Mar 21, 2022
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants