-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Kubernetes liveness and readiness probes customization docume…
…ntation Add tests for liveness and readiness probes
- Loading branch information
Showing
4 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
75 changes: 75 additions & 0 deletions
75
...uator/src/test/java/smoketest/actuator/AbstractManagementPortAvailabilityProbesTests.java
This file contains 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,75 @@ | ||
/* | ||
* Copyright 2012-2023 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 smoketest.actuator; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.boot.test.web.server.LocalManagementPort; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Base class for integration tests for adding Health probes additional paths. | ||
* | ||
* @author Ivo Smid | ||
*/ | ||
class AbstractManagementPortAvailabilityProbesTests { | ||
|
||
@LocalServerPort | ||
protected int port; | ||
|
||
@LocalManagementPort | ||
protected int managementPort; | ||
|
||
@Test | ||
void testLiveness() { | ||
ResponseEntity<String> entity = callHttpGetManagement("/actuator/health/liveness"); | ||
assertUp(entity); | ||
} | ||
|
||
@Test | ||
void testReadiness() { | ||
ResponseEntity<String> entity = callHttpGetManagement("/actuator/health/readiness"); | ||
assertUp(entity); | ||
} | ||
|
||
protected ResponseEntity<String> callHttpGetManagement(String urlPath) { | ||
return callHttpGet(urlPath, this.managementPort, Function.identity()); | ||
} | ||
|
||
protected ResponseEntity<String> callHttpGetServer(String urlPath) { | ||
return callHttpGet(urlPath, this.port, (it) -> it.withBasicAuth("user", "password")); | ||
} | ||
|
||
private ResponseEntity<String> callHttpGet(String urlPath, int port, | ||
Function<TestRestTemplate, TestRestTemplate> customizer) { | ||
var testRestTemplate = customizer.apply(new TestRestTemplate()); | ||
return testRestTemplate.getForEntity("http://localhost:" + port + urlPath, String.class); | ||
} | ||
|
||
protected static void assertUp(ResponseEntity<String> entity) { | ||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
assertThat(entity.getBody()).contains("\"status\":\"UP\""); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...tor/src/test/java/smoketest/actuator/ManagementPortAvailabilityProbesCustomPathTests.java
This file contains 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,64 @@ | ||
/* | ||
* Copyright 2012-2023 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 smoketest.actuator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Integration tests for adding Health probes additional paths. | ||
* | ||
* @author Ivo Smid | ||
*/ | ||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, | ||
properties = { "management.server.port=0", "management.endpoint.health.probes.enabled=true", | ||
"management.endpoint.health.probes.add-additional-paths=true", | ||
"management.endpoint.health.group.liveness.additional-path=server:/live-custom", | ||
"management.endpoint.health.group.readiness.additional-path=server:/ready-custom" }) | ||
class ManagementPortAvailabilityProbesCustomPathTests extends AbstractManagementPortAvailabilityProbesTests { | ||
|
||
@Test | ||
void testCustomLivez() { | ||
ResponseEntity<String> entity = callHttpGetServer("/live-custom"); | ||
assertUp(entity); | ||
} | ||
|
||
@Test | ||
void testDefaultLivezNotFound() { | ||
ResponseEntity<String> entity = callHttpGetServer("/livez"); | ||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@Test | ||
void testCustomReadyz() { | ||
ResponseEntity<String> entity = callHttpGetServer("/ready-custom"); | ||
assertUp(entity); | ||
} | ||
|
||
@Test | ||
void testDefaultReadyzNotFound() { | ||
ResponseEntity<String> entity = callHttpGetServer("/readyz"); | ||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...or/src/test/java/smoketest/actuator/ManagementPortAvailabilityProbesDefaultPathTests.java
This file contains 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 @@ | ||
/* | ||
* Copyright 2012-2023 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 smoketest.actuator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
/** | ||
* Integration tests for adding Health probes additional paths. | ||
* | ||
* @author Ivo Smid | ||
*/ | ||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, | ||
properties = { "management.server.port=0", "management.endpoint.health.probes.enabled=true", | ||
"management.endpoint.health.probes.add-additional-paths=true" }) | ||
class ManagementPortAvailabilityProbesDefaultPathTests extends AbstractManagementPortAvailabilityProbesTests { | ||
|
||
@Test | ||
void testLivez() { | ||
ResponseEntity<String> entity = callHttpGetServer("/livez"); | ||
assertUp(entity); | ||
} | ||
|
||
@Test | ||
void testReadyz() { | ||
ResponseEntity<String> entity = callHttpGetServer("/readyz"); | ||
assertUp(entity); | ||
} | ||
|
||
} |