Expose OS information as an InfoContributor

See gh-28907
This commit is contained in:
Jonatan Ivanov
2021-12-04 17:21:10 -08:00
committed by Stephane Nicoll
parent b9a7c2f179
commit c700f686c6
8 changed files with 210 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2012-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;
import org.springframework.boot.info.OsInfo;
/**
* An {@link InfoContributor} that exposes {@link OsInfo}.
*
* @author Jonatan Ivanov
* @since 2.7.0
*/
public class OsInfoContributor implements InfoContributor {
private final OsInfo osInfo;
public OsInfoContributor() {
this.osInfo = new OsInfo();
}
@Override
public void contribute(Info.Builder builder) {
builder.withDetail("os", this.osInfo);
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2012-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;
import org.junit.jupiter.api.Test;
import org.springframework.boot.info.JavaInfo;
import org.springframework.boot.info.OsInfo;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link OsInfoContributor}
*
* @author Jonatan Ivanov
*/
public class OsInfoContributorTests {
@Test
void osInfoShouldBeAdded() {
OsInfoContributor osInfoContributor = new OsInfoContributor();
Info.Builder builder = new Info.Builder();
osInfoContributor.contribute(builder);
Info info = builder.build();
assertThat(info.getDetails().get("os")).isInstanceOf(OsInfo.class);
}
}