parent
0b58d4858d
commit
fc87da7ef3
|
|
@ -20,6 +20,7 @@ import org.springframework.boot.actuate.info.BuildInfoContributor;
|
|||
import org.springframework.boot.actuate.info.EnvironmentInfoContributor;
|
||||
import org.springframework.boot.actuate.info.GitInfoContributor;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
import org.springframework.boot.actuate.info.java.JavaInfoContributor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
|
|
@ -40,6 +41,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
|||
*
|
||||
* @author Meang Akira Tanaka
|
||||
* @author Stephane Nicoll
|
||||
* @author Jonatan Ivanov
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
|
@ -77,4 +79,11 @@ public class InfoContributorAutoConfiguration {
|
|||
return new BuildInfoContributor(buildProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnEnabledInfoContributor("java")
|
||||
@Order(DEFAULT_ORDER)
|
||||
public InfoContributor javaInfoContributor() {
|
||||
return new JavaInfoContributor();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,12 @@ import org.junit.jupiter.api.AfterEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.info.BuildInfoContributor;
|
||||
import org.springframework.boot.actuate.info.EnvironmentInfoContributor;
|
||||
import org.springframework.boot.actuate.info.GitInfoContributor;
|
||||
import org.springframework.boot.actuate.info.Info;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
import org.springframework.boot.actuate.info.java.JavaInfo;
|
||||
import org.springframework.boot.actuate.info.java.JavaInfoContributor;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.boot.info.GitProperties;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -39,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link InfoContributorAutoConfiguration}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Jonatan Ivanov
|
||||
*/
|
||||
class InfoContributorAutoConfigurationTests {
|
||||
|
||||
|
|
@ -55,7 +59,26 @@ class InfoContributorAutoConfigurationTests {
|
|||
void disableEnvContributor() {
|
||||
load("management.info.env.enabled:false");
|
||||
Map<String, InfoContributor> beans = this.context.getBeansOfType(InfoContributor.class);
|
||||
assertThat(beans).hasSize(0);
|
||||
assertThat(beans).extractingFromEntries(Map.Entry::getValue).allSatisfy(
|
||||
(infoContributor) -> assertThat(infoContributor).isNotInstanceOf(EnvironmentInfoContributor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void disableJavaContributor() {
|
||||
load("management.info.java.enabled:false");
|
||||
Map<String, InfoContributor> beans = this.context.getBeansOfType(InfoContributor.class);
|
||||
assertThat(beans).extractingFromEntries(Map.Entry::getValue).allSatisfy(
|
||||
(infoContributor) -> assertThat(infoContributor).isNotInstanceOf(JavaInfoContributor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultInfoContributorsEnabled() {
|
||||
load();
|
||||
Map<String, InfoContributor> beans = this.context.getBeansOfType(InfoContributor.class);
|
||||
assertThat(beans).hasSize(2).extractingFromEntries(Map.Entry::getValue)
|
||||
.anySatisfy(
|
||||
(infoContributor) -> assertThat(infoContributor).isInstanceOf(EnvironmentInfoContributor.class))
|
||||
.anySatisfy((infoContributor) -> assertThat(infoContributor).isInstanceOf(JavaInfoContributor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -129,6 +152,17 @@ class InfoContributorAutoConfigurationTests {
|
|||
.isSameAs(this.context.getBean("customBuildInfoContributor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void javaInfoContributor() {
|
||||
load();
|
||||
Map<String, InfoContributor> beans = this.context.getBeansOfType(InfoContributor.class);
|
||||
assertThat(beans).containsKeys("javaInfoContributor");
|
||||
Map<String, Object> content = invokeContributor(
|
||||
this.context.getBean("javaInfoContributor", InfoContributor.class));
|
||||
Object javaInfo = content.get("java");
|
||||
assertThat(javaInfo).isInstanceOf(JavaInfo.class);
|
||||
}
|
||||
|
||||
private Map<String, Object> invokeContributor(InfoContributor contributor) {
|
||||
Info.Builder builder = new Info.Builder();
|
||||
contributor.contribute(builder);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2021-2021 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.boot.actuate.info.java;
|
||||
|
||||
/**
|
||||
* A simple DTO that holds information about the Java environment the application is
|
||||
* running in.
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class JavaInfo {
|
||||
|
||||
private final String vendor;
|
||||
|
||||
private final String version;
|
||||
|
||||
private final JreInfo runtime;
|
||||
|
||||
private final VmInfo vm;
|
||||
|
||||
public JavaInfo() {
|
||||
this.vendor = System.getProperty("java.vendor");
|
||||
this.version = System.getProperty("java.version");
|
||||
this.runtime = new JreInfo();
|
||||
this.vm = new VmInfo();
|
||||
}
|
||||
|
||||
public String getVendor() {
|
||||
return this.vendor;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public JreInfo getRuntime() {
|
||||
return this.runtime;
|
||||
}
|
||||
|
||||
public VmInfo getVm() {
|
||||
return this.vm;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2021-2021 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.boot.actuate.info.java;
|
||||
|
||||
import org.springframework.boot.actuate.info.Info.Builder;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
|
||||
/**
|
||||
* An {@link InfoContributor} that exposes {@link JavaInfo}.
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class JavaInfoContributor implements InfoContributor {
|
||||
|
||||
private final JavaInfo javaInfo;
|
||||
|
||||
public JavaInfoContributor() {
|
||||
this.javaInfo = new JavaInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contribute(Builder builder) {
|
||||
builder.withDetail("java", this.javaInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright 2021-2021 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.boot.actuate.info.java;
|
||||
|
||||
/**
|
||||
* A simple DTO that holds information about the JRE (Java Runtime Environment) the
|
||||
* application is running in.
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class JreInfo {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String version;
|
||||
|
||||
public JreInfo() {
|
||||
this.name = System.getProperty("java.runtime.name");
|
||||
this.version = System.getProperty("java.runtime.version");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2021-2021 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.boot.actuate.info.java;
|
||||
|
||||
/**
|
||||
* A simple DTO that holds information about the JVM (Java Virtual Machine) the
|
||||
* application is running in.
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public class VmInfo {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String vendor;
|
||||
|
||||
private final String version;
|
||||
|
||||
public VmInfo() {
|
||||
this.name = System.getProperty("java.vm.name");
|
||||
this.vendor = System.getProperty("java.vm.vendor");
|
||||
this.version = System.getProperty("java.vm.version");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getVendor() {
|
||||
return this.vendor;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright 2021-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Classes for java info.
|
||||
*/
|
||||
package org.springframework.boot.actuate.info.java;
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2021-2021 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.boot.actuate.info.java;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.info.Info;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JavaInfoContributor}
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
*/
|
||||
class JavaInfoContributorTests {
|
||||
|
||||
@Test
|
||||
void javaInfoShouldBeAdded() {
|
||||
JavaInfoContributor javaInfoContributor = new JavaInfoContributor();
|
||||
Info.Builder builder = new Info.Builder();
|
||||
javaInfoContributor.contribute(builder);
|
||||
|
||||
assertThat(builder.build().getDetails().get("java")).isInstanceOf(JavaInfo.class);
|
||||
JavaInfo javaInfo = (JavaInfo) builder.build().getDetails().get("java");
|
||||
|
||||
assertThat(javaInfo.getVendor()).isEqualTo(System.getProperty("java.vendor"));
|
||||
assertThat(javaInfo.getVersion()).isEqualTo(System.getProperty("java.version"));
|
||||
assertThat(javaInfo.getRuntime().getName()).isEqualTo(System.getProperty("java.runtime.name"));
|
||||
assertThat(javaInfo.getRuntime().getVersion()).isEqualTo(System.getProperty("java.runtime.version"));
|
||||
assertThat(javaInfo.getVm().getName()).isEqualTo(System.getProperty("java.vm.name"));
|
||||
assertThat(javaInfo.getVm().getVendor()).isEqualTo(System.getProperty("java.vm.vendor"));
|
||||
assertThat(javaInfo.getVm().getVersion()).isEqualTo(System.getProperty("java.vm.version"));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue