Skip to content

Allow the configprops endpoint to return properties with a particular prefix #24718

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

Closed
wants to merge 2 commits into from

Conversation

onobc
Copy link
Contributor

@onobc onobc commented Jan 10, 2021

Adds ability to filter by prefix for /actuator/configprops

Fixes gh-24714

No filter

Filter by prefix

(ℹ️ this was taken from v1 screenshot and url does not contain prefix param anymore)

beans.forEach((beanName, bean) -> descriptors.put(beanName, describeBean(mapper, bean)));

Map<String, ConfigurationPropertiesBeanDescriptor> descriptors = beans.values().stream()
.filter(beanFilterPredicate::test)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the approach of simply filtering out at the config props level and not returning a different payload for the individual api case. This differs form the /env endpoint as it returns an XYZEntry object instead of an XYZ. This provided the filtering and introduced less ripple.

import static org.hamcrest.Matchers.hasSize;

/**
* Integration tests for {@link ConfigurationPropertiesReportEndpoint} exposed by Jersey,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that we did not have @WebEndpointTest coverage for /actuator/configprops - this adds it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 10, 2021
@@ -26,3 +26,26 @@ The following table describes the structure of the response:

[cols="2,1,3"]
include::{snippets}/configprops/response-fields.adoc[]


[[configprops-retrieving-by-prefix]]
Copy link
Contributor Author

@onobc onobc Jan 13, 2021

Choose a reason for hiding this comment

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

@wilkinsona I absolutely ❤️ what you did here w/ the endpoint doc generation - clever. It provides a consistent and accurate set of docs as well as provides some test coverage. It took a second for me to put the pieces together - but once I did, its a breeze. Thank you.

Copy link
Member

Choose a reason for hiding this comment

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

That's lovely to hear. Thank you!

}

@WebEndpointTest
void filterByNonExistentPrefix() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we return 404 in case of no prefix match? If so I need to create a web endpoint extension. Just let me know what the preference is here. Because the prefix can match multiple entries it feels more of a "List findByPrefix" than a "Object findByPrimaryKey" (if you will).

Copy link
Member

Choose a reason for hiding this comment

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

A 404 feels right to me. That's what we do in the env endpoint for a property that doesn't exist. It too can match multiple entries as the same property may be defined in multiple property sources.

@wilkinsona wilkinsona changed the title Adds ability to filter by prefix or classname for /actuator/configprops Allow the configprops endpoint to return properties with a particular prefix Jan 15, 2021
@wilkinsona wilkinsona added the type: enhancement A general enhancement label Jan 15, 2021
@wilkinsona wilkinsona added this to the 2.5.x milestone Jan 15, 2021
@wilkinsona wilkinsona removed the status: waiting-for-triage An issue we've not yet triaged label Jan 15, 2021
@onobc onobc marked this pull request as ready for review January 15, 2021 16:33
@snicoll snicoll self-assigned this Feb 10, 2021
@snicoll snicoll modified the milestones: 2.5.x, 2.5.0-M2 Feb 10, 2021
snicoll pushed a commit that referenced this pull request Feb 10, 2021
This commit improves the configprops endpoint to allow filtering
properties based on a particular prefix

See gh-24718
snicoll added a commit that referenced this pull request Feb 10, 2021
@snicoll snicoll closed this in 78061f4 Feb 10, 2021
@snicoll
Copy link
Member

snicoll commented Feb 10, 2021

nicely done Chris. I've polished your contribution in b92bb93. The interesting bits is that we name the method differently when there is a selector so that the JMX operation (that uses the method name) can provide a bit more context as what it does compared to the general operation.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add @Selector support to the configprops actuator endpoint
4 participants