-
Notifications
You must be signed in to change notification settings - Fork 53
feat(java): add shared GET /info REST controller to nv-boot-starter-core #1212
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
Open
shelleyshen-0
wants to merge
8
commits into
main
Choose a base branch
from
feat/shared-info-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c5afa35
feat(java): add shared GET /info REST controller to nv-boot-starter-core
shelleyshen-0 dcda9ab
fix(java): normalize blank git.commit.id.full to unknown in GitBuildInfo
shelleyshen-0 4e04d94
fix(java): log the caught exception when git.properties fails to load
shelleyshen-0 ea8b132
Merge branch 'main' into feat/shared-info-endpoint
shelleyshen-0 d29eca7
refactor(java): read /info version and commit from Environment
shelleyshen-0 cd5eefd
Merge branch 'main' into feat/shared-info-endpoint
shelleyshen-0 b09f8a3
refactor(java): nest InfoResponse inside InfoResponseService, drop ge…
shelleyshen-0 f17eb9e
Merge branch 'main' into feat/shared-info-endpoint
shelleyshen-0 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
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
39 changes: 39 additions & 0 deletions
39
...arent/nv-boot-starter-core/src/main/java/com/nvidia/boot/core/info/InfoConfiguration.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,39 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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 com.nvidia.boot.core.info; | ||
|
|
||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.env.Environment; | ||
|
|
||
| /** Auto-configuration for the shared {@code GET /info} endpoint and controller. */ | ||
| @Configuration | ||
| @ConditionalOnWebApplication | ||
| public class InfoConfiguration { | ||
|
|
||
| @Bean | ||
| public InfoResponseService infoResponseService(Environment environment) { | ||
| return new InfoResponseService(environment); | ||
| } | ||
|
|
||
| @Bean | ||
| public InfoController infoController(InfoResponseService infoResponseService) { | ||
| return new InfoController(infoResponseService); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...t-parent/nv-boot-starter-core/src/main/java/com/nvidia/boot/core/info/InfoController.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,41 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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 com.nvidia.boot.core.info; | ||
|
|
||
| import com.nvidia.boot.core.info.InfoResponseService.InfoResponse; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| /** | ||
| * Shared build-info controller for {@code GET /info}. Returns a flat {service, version, commit} | ||
| * body, matching the equivalent Go services' contract, so build identification is consistent | ||
| * across NVCF control plane services. | ||
| */ | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class InfoController { | ||
|
|
||
| private final InfoResponseService infoResponseService; | ||
|
|
||
| @GetMapping("/info") | ||
| public ResponseEntity<InfoResponse> getInfo() { | ||
| return ResponseEntity.ok(infoResponseService.getInfo()); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...ent/nv-boot-starter-core/src/main/java/com/nvidia/boot/core/info/InfoResponseService.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,39 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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 com.nvidia.boot.core.info; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.core.env.Environment; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class InfoResponseService { | ||
|
|
||
| private static final String UNKNOWN = "unknown"; | ||
|
|
||
| private final Environment environment; | ||
|
|
||
| public InfoResponse getInfo() { | ||
| return new InfoResponse( | ||
| environment.getProperty("spring.application.name", UNKNOWN), | ||
| environment.getProperty("spring.application.version", UNKNOWN), | ||
| environment.getProperty("app.git.commit.full", UNKNOWN)); | ||
| } | ||
|
|
||
| public record InfoResponse(String service, String version, String commit) { | ||
| } | ||
| } | ||
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
...rent/nv-boot-starter-core/src/test/java/com/nvidia/boot/core/info/InfoControllerTest.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 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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 com.nvidia.boot.core.info; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import com.nvidia.boot.core.info.InfoResponseService.InfoResponse; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class InfoControllerTest { | ||
|
|
||
| private InfoResponseService infoResponseService; | ||
| private InfoController controller; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| infoResponseService = mock(InfoResponseService.class); | ||
| controller = new InfoController(infoResponseService); | ||
| } | ||
|
|
||
| @Test | ||
| void getInfoReturnsOkWithResponseBody() { | ||
| var expected = new InfoResponse("nvcf-ess", "v1.2.3", "77c5d932abcdef1234567890abcdef1234567890"); | ||
| when(infoResponseService.getInfo()).thenReturn(expected); | ||
|
|
||
| var response = controller.getInfo(); | ||
|
|
||
| assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); | ||
| assertThat(response.getBody()).isEqualTo(expected); | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...nv-boot-starter-core/src/test/java/com/nvidia/boot/core/info/InfoResponseServiceTest.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,47 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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 com.nvidia.boot.core.info; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.nvidia.boot.core.info.InfoResponseService.InfoResponse; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.mock.env.MockEnvironment; | ||
|
|
||
| class InfoResponseServiceTest { | ||
|
|
||
| @Test | ||
| void buildsResponseFromEnvironmentProperties() { | ||
| var environment = new MockEnvironment() | ||
| .withProperty("spring.application.name", "nvcf-ess") | ||
| .withProperty("spring.application.version", "v1.2.3") | ||
| .withProperty("app.git.commit.full", "77c5d932abcdef1234567890abcdef1234567890"); | ||
|
|
||
| var service = new InfoResponseService(environment); | ||
|
|
||
| assertThat(service.getInfo()) | ||
| .isEqualTo(new InfoResponse("nvcf-ess", "v1.2.3", "77c5d932abcdef1234567890abcdef1234567890")); | ||
| } | ||
|
|
||
| @Test | ||
| void fallsBackToUnknownWhenPropertiesAbsent() { | ||
| var service = new InfoResponseService(new MockEnvironment()); | ||
|
|
||
| assertThat(service.getInfo()).isEqualTo(new InfoResponse("unknown", "unknown", "unknown")); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: NVIDIA/nvcf
Length of output: 149
🏁 Script executed:
Repository: NVIDIA/nvcf
Length of output: 16232
🏁 Script executed:
Repository: NVIDIA/nvcf
Length of output: 40632
🏁 Script executed:
Repository: NVIDIA/nvcf
Length of output: 26573
🌐 Web query:
Spring Framework Environment getProperty(String key, String defaultValue) Javadoc empty string default value💡 Result:
The Spring Framework's PropertyResolver interface (which the Environment interface extends) provides the getProperty(String key, String defaultValue) method [1][2][3]. According to the official Spring Framework Javadoc, this method is defined to return the property value associated with the given key if it can be resolved; otherwise, it returns the provided defaultValue [1][4][3]. There is no special logic or exception made for an empty string; if you pass an empty string ("") as the defaultValue, it will be returned exactly as provided when the property key cannot be resolved [1][5][3]. The method does not treat an empty string defaultValue as null or otherwise invalid [1][6]. It functions as a straightforward fallback mechanism where the defaultValue argument is returned if and only if the specified property key is not found in the environment's configured property sources [1][7][6].
Citations:
Normalize blank environment values before applying the fallback.
org.springframework.core.env.Environment#getProperty(String, String)applies"unknown"only when the property is unresolved. An empty configured value passes through toInfoResponse. Add blank-value handling for both properties and cover it inInfoResponseServiceTest.🤖 Prompt for AI Agents