-
Notifications
You must be signed in to change notification settings - Fork 91
adding the jmx endpoint exposure related files . #473
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
fabapp2
merged 5 commits into
spring-projects-experimental:main
from
ishu-thakur:jmx_endpoints_exposure
Nov 3, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cbbaf42
adding the jmx endpoint exposure realated files .
ishu-thakur 6c2d400
minor changes
ishu-thakur 178250a
Adding TestProjectContext for the JmxEndpointExposure.
ishu-thakur 3897206
merging changes from main
fabapp2 4a54c44
Add missing copyright license
fabapp2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../springframework/sbm/boot/upgrade_27_30/actions/Boot_27_30_JmxEndpointExposureAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm.boot.upgrade_27_30.actions; | ||
|
||
import org.springframework.sbm.boot.properties.finder.SpringBootDefaultPropertiesFinder; | ||
import org.springframework.sbm.engine.context.ProjectContext; | ||
import org.springframework.sbm.engine.recipe.AbstractAction; | ||
|
||
import java.util.Optional; | ||
|
||
public class Boot_27_30_JmxEndpointExposureAction extends AbstractAction { | ||
|
||
public static final String JMX_ENDPOINT = "management.endpoints.jmx.exposure.include"; | ||
|
||
@Override | ||
public void apply(ProjectContext context) { | ||
SpringBootDefaultPropertiesFinder springBootDefaultPropertiesFinder = new SpringBootDefaultPropertiesFinder(); | ||
|
||
context.getApplicationModules() | ||
.getTopmostApplicationModules() | ||
.stream() | ||
.map(m -> m.searchMainResources(springBootDefaultPropertiesFinder)) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.forEach(p -> { | ||
if (!p.getProperty(JMX_ENDPOINT).isPresent()) { | ||
p.setProperty(JMX_ENDPOINT, "*"); | ||
} | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...a/org/springframework/sbm/boot/upgrade_27_30/conditions/JmxEndpointExposureCondition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm.boot.upgrade_27_30.conditions; | ||
|
||
import org.springframework.sbm.boot.upgrade_27_30.filter.JmxEndpointExposureFinder; | ||
import org.springframework.sbm.engine.context.ProjectContext; | ||
import org.springframework.sbm.engine.recipe.Condition; | ||
|
||
public class JmxEndpointExposureCondition implements Condition { | ||
@Override | ||
public String getDescription() { | ||
return "Check if 'management.endpoints.jmx.exposure.include' is declared."; | ||
} | ||
|
||
@Override | ||
public boolean evaluate(ProjectContext context) { | ||
return context.search(new JmxEndpointExposureFinder()).isEmpty(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ain/java/org/springframework/sbm/boot/upgrade_27_30/filter/JmxEndpointExposureFinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm.boot.upgrade_27_30.filter; | ||
|
||
import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties; | ||
import org.springframework.sbm.boot.properties.search.SpringBootApplicationPropertiesResourceListFilter; | ||
import org.springframework.sbm.project.resource.ProjectResourceSet; | ||
import org.springframework.sbm.project.resource.filter.ProjectResourceFinder; | ||
import org.springframework.sbm.properties.api.PropertiesSource; | ||
|
||
import java.util.List; | ||
|
||
public class JmxEndpointExposureFinder implements ProjectResourceFinder<List<? extends PropertiesSource>> { | ||
public static final String JMX_ENDPOINT_KEY = "management.endpoints.jmx.exposure.include"; | ||
|
||
@Override | ||
public List<? extends PropertiesSource> apply(ProjectResourceSet projectResourceSet) { | ||
List<SpringBootApplicationProperties> springBootApplicationProperties = new SpringBootApplicationPropertiesResourceListFilter().apply(projectResourceSet); | ||
return springBootApplicationProperties.stream() | ||
.filter(find -> find.getProperty(JMX_ENDPOINT_KEY).isPresent()) | ||
.toList(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ingframework/sbm/boot/upgrade_27_30/actions/Boot_27_30_JmxEndpointExposureActionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm.boot.upgrade_27_30.actions; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.sbm.boot.properties.SpringApplicationPropertiesPathMatcher; | ||
import org.springframework.sbm.boot.properties.SpringBootApplicationPropertiesRegistrar; | ||
import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties; | ||
import org.springframework.sbm.boot.properties.search.SpringBootApplicationPropertiesResourceListFilter; | ||
import org.springframework.sbm.engine.context.ProjectContext; | ||
import org.springframework.sbm.project.resource.TestProjectContext; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class Boot_27_30_JmxEndpointExposureActionTest { | ||
private final String DUMMY_PROPERTY_FILE = "foo=bar\n" + | ||
"defaultBasePackage=org.springframework.sbm"; | ||
|
||
@Test | ||
public void givenAProjectWithoutJmxEndpointExposureOverride_andSpringBootProperties_applyAction_expectPropertyAdded() { | ||
ProjectContext projectContext = TestProjectContext.buildProjectContext() | ||
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) | ||
.addProjectResource("src/main/resources/application.properties", DUMMY_PROPERTY_FILE) | ||
.build(); | ||
|
||
Boot_27_30_JmxEndpointExposureAction boot_27_30_jmxEndpointExposureAction = new Boot_27_30_JmxEndpointExposureAction(); | ||
boot_27_30_jmxEndpointExposureAction.apply(projectContext); | ||
|
||
List<SpringBootApplicationProperties> bootApplicationProperties = new SpringBootApplicationPropertiesResourceListFilter().apply(projectContext.getProjectResources()); | ||
assertThat(bootApplicationProperties.size()).isEqualTo(1); | ||
assertThat(bootApplicationProperties.get(0).getProperty("management.endpoints.jmx.exposure.include").isPresent()).isTrue(); | ||
|
||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...g/springframework/sbm/boot/upgrade_27_30/conditions/JmxEndpointExposureConditionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm.boot.upgrade_27_30.conditions; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.sbm.boot.properties.SpringApplicationPropertiesPathMatcher; | ||
import org.springframework.sbm.boot.properties.SpringBootApplicationPropertiesRegistrar; | ||
import org.springframework.sbm.engine.context.ProjectContext; | ||
import org.springframework.sbm.project.resource.TestProjectContext; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class JmxEndpointExposureConditionTest { | ||
|
||
private static final String APPLICATION_PROPERTIES_WITH_JMX_ENDPOINT_EXPOSED = "foo=bar\n" + | ||
"migrate=true\n" + | ||
"management.endpoints.jmx.exposure.include=*\n"; | ||
|
||
private static final String APPLICATION_PROPERTIES_WITHOUT_JMX_ENDPOINT_EXPOSED = "foo=bar\n" + | ||
"migrate=true\n"; | ||
|
||
@Test | ||
public void givenProjectWithJmxEndpointExposureCustomization_evaluateCondition_expectFalse() { | ||
ProjectContext projectContext = TestProjectContext.buildProjectContext() | ||
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) | ||
.addProjectResource(Path.of("src", "main", "resources", "application.properties"), APPLICATION_PROPERTIES_WITH_JMX_ENDPOINT_EXPOSED) | ||
.build(); | ||
|
||
JmxEndpointExposureCondition jmxEndpointExposureCondition = new JmxEndpointExposureCondition(); | ||
assertThat(jmxEndpointExposureCondition.evaluate(projectContext)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void givenProjectWithJmxEndpointExposureCustomization_evaluateCondition_expectTrue() { | ||
ProjectContext projectContext = TestProjectContext.buildProjectContext() | ||
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) | ||
.addProjectResource(Path.of("src", "main", "resources", "application.properties"), APPLICATION_PROPERTIES_WITHOUT_JMX_ENDPOINT_EXPOSED) | ||
.build(); | ||
|
||
JmxEndpointExposureCondition jmxEndpointExposureCondition = new JmxEndpointExposureCondition(); | ||
assertThat(jmxEndpointExposureCondition.evaluate(projectContext)).isTrue(); | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...java/org/springframework/sbm/boot/upgrade_27_30/filter/JmxEndpointExposureFinderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm.boot.upgrade_27_30.filter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.sbm.boot.properties.SpringApplicationPropertiesPathMatcher; | ||
import org.springframework.sbm.boot.properties.SpringBootApplicationPropertiesRegistrar; | ||
import org.springframework.sbm.engine.context.ProjectContext; | ||
import org.springframework.sbm.project.resource.TestProjectContext; | ||
import org.springframework.sbm.properties.api.PropertiesSource; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class JmxEndpointExposureFinderTest { | ||
private static final String APPLICATION_PROPERTIES_WITH_JMX_ENDPOINT_EXPOSED = "foo=bar\n" + | ||
"migrate=true\n" + | ||
"management.endpoints.jmx.exposure.include=*\n"; | ||
|
||
private static final String MULTI_MODULE_POM_XML = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + | ||
"xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + | ||
" <modelVersion>4.0.0</modelVersion>\n" + | ||
"\n" + | ||
" <groupId>org.springframework.sbm</groupId>\n" + | ||
" <artifactId>spring-boot-migrator</artifactId>\n" + | ||
" <version>0.11.2-SNAPSHOT</version>\n" + | ||
" <packaging>pom</packaging>\n" + | ||
" <modules>\n" + | ||
" <module>module1</module>\n" + | ||
" <module>module2</module>\n" + | ||
" </modules>\n" + | ||
"</project>"; | ||
|
||
private static final String SUB_MODULE_POM_XML = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + | ||
"xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + | ||
" <parent>\n" + | ||
" <artifactId>spring-boot-migrator</artifactId>\n" + | ||
" <groupId>org.springframework.sbm</groupId>\n" + | ||
" <version>0.11.2-SNAPSHOT</version>\n" + | ||
" <relativePath>../../pom.xml</relativePath>\n" + | ||
" </parent>\n" + | ||
" <modelVersion>4.0.0</modelVersion>\n" + | ||
"\n" + | ||
" <artifactId>{{module}}</artifactId>\n" + | ||
"</project>"; | ||
@Test | ||
public void givenProjectWithJmxEndpointExposureCustomization_findResources_returnResource(){ | ||
ProjectContext projectContext = TestProjectContext.buildProjectContext() | ||
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) | ||
.addProjectResource(Path.of("src", "main", "resources", "application.properties"), APPLICATION_PROPERTIES_WITH_JMX_ENDPOINT_EXPOSED) | ||
.build(); | ||
|
||
JmxEndpointExposureFinder jmxEndpointExposureFinder = new JmxEndpointExposureFinder(); | ||
List<? extends PropertiesSource> propertiesSources = jmxEndpointExposureFinder.apply(projectContext.getProjectResources()); | ||
|
||
assertThat(propertiesSources.size()).isEqualTo(1); | ||
assertThat(propertiesSources.get(0).getProperty("management.endpoints.jmx.exposure.include").isPresent()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void givenMultiModuleProjectWithJmxEndpointExposureCustomization_findResources_returnResource(){ | ||
ProjectContext projectContext = TestProjectContext.buildProjectContext() | ||
.withMavenRootBuildFileSource(MULTI_MODULE_POM_XML) | ||
.addProjectResource(Path.of("module1","pom.xml"),SUB_MODULE_POM_XML.replace("{{module}}", "module1")) | ||
.addProjectResource(Path.of("module2","pom.xml"),SUB_MODULE_POM_XML.replace("{{module}}", "module2")) | ||
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) | ||
.addProjectResource(Path.of("module1","src", "main", "resources", "application.properties"), APPLICATION_PROPERTIES_WITH_JMX_ENDPOINT_EXPOSED) | ||
.addProjectResource(Path.of("module2","src", "main", "resources", "application.properties"), APPLICATION_PROPERTIES_WITH_JMX_ENDPOINT_EXPOSED) | ||
.build(); | ||
|
||
JmxEndpointExposureFinder jmxEndpointExposureFinder = new JmxEndpointExposureFinder(); | ||
List<? extends PropertiesSource> propertiesSources = jmxEndpointExposureFinder.apply(projectContext.getProjectResources()); | ||
|
||
assertThat(propertiesSources.size()).isEqualTo(2); | ||
assertThat(propertiesSources.get(0).getProperty("management.endpoints.jmx.exposure.include").isPresent()).isTrue(); | ||
assertThat(propertiesSources.get(1).getProperty("management.endpoints.jmx.exposure.include").isPresent()).isTrue(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.