-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide component status next to details
Adjust the AxonServerHealthIndicator to share a status field as well. This status field should include the additional status "WARN" for when one of the contexts the app is connected with, is down. To support this thoroughly, a StatusAggregate should be included. #1964
- Loading branch information
Showing
7 changed files
with
259 additions
and
76 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
spring-boot-autoconfigure/src/main/java/org/axonframework/actuator/HealthStatus.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,34 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* 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 org.axonframework.actuator; | ||
|
||
import org.springframework.boot.actuate.health.Status; | ||
|
||
/** | ||
* Utility class holding additional {@link Status} instances. | ||
* | ||
* @author Steven van Beelen | ||
* @author Marc Gathier | ||
* @since 4.6.0 | ||
*/ | ||
public abstract class HealthStatus { | ||
|
||
/** | ||
* A {@link Status} suggesting the connection is still working but not at full capacity. | ||
*/ | ||
public static final Status WARN = new Status("WARN"); | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...igure/src/main/java/org/axonframework/actuator/axonserver/AxonServerStatusAggregator.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,40 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* 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 org.axonframework.actuator.axonserver; | ||
|
||
import org.axonframework.actuator.HealthStatus; | ||
import org.springframework.boot.actuate.health.SimpleStatusAggregator; | ||
import org.springframework.boot.actuate.health.Status; | ||
|
||
/** | ||
* A {@link SimpleStatusAggregator} implementation determining the overall health of an Axon Framework application using | ||
* Axon Server. Adds the {@link HealthStatus#WARN} status to the regular set of {@link Status statuses}. | ||
* | ||
* @author Steven van Beelen | ||
* @author Marc Gathier | ||
* @since 4.6.0 | ||
*/ | ||
public class AxonServerStatusAggregator extends SimpleStatusAggregator { | ||
|
||
/** | ||
* Constructs a default Axon Server specific {@link SimpleStatusAggregator}. Adds the {@link HealthStatus#WARN} | ||
* after {@link Status#OUT_OF_SERVICE} and before {@link Status#UP}. | ||
*/ | ||
public AxonServerStatusAggregator() { | ||
super(Status.DOWN, Status.OUT_OF_SERVICE, HealthStatus.WARN, Status.UP, Status.UNKNOWN); | ||
} | ||
} |
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
67 changes: 0 additions & 67 deletions
67
...autoconfigure/src/test/java/org/axonframework/actuator/AxonServerHealthIndicatorTest.java
This file was deleted.
Oops, something went wrong.
138 changes: 138 additions & 0 deletions
138
...re/src/test/java/org/axonframework/actuator/axonserver/AxonServerHealthIndicatorTest.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,138 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* 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 org.axonframework.actuator.axonserver; | ||
|
||
import org.axonframework.actuator.HealthStatus; | ||
import org.axonframework.axonserver.connector.AxonServerConnectionManager; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* Test class validating the {@link AxonServerHealthIndicator}. | ||
* | ||
* @author Steven van Beelen | ||
*/ | ||
class AxonServerHealthIndicatorTest { | ||
|
||
private AxonServerConnectionManager connectionManager; | ||
|
||
private AxonServerHealthIndicator testSubject; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
connectionManager = mock(AxonServerConnectionManager.class); | ||
testSubject = new AxonServerHealthIndicator(connectionManager); | ||
} | ||
|
||
@Test | ||
void testDoHealthCheckStatusReturnsUp() { | ||
String testContextOne = "context-one"; | ||
String testContextTwo = "context-two"; | ||
String expectedDetailsContextOne = testContextOne + ".connection.active"; | ||
String expectedDetailsContextTwo = testContextTwo + ".connection.active"; | ||
|
||
Map<String, Boolean> testConnections = new HashMap<>(); | ||
testConnections.put(testContextOne, true); | ||
testConnections.put(testContextTwo, true); | ||
when(connectionManager.connections()).thenReturn(testConnections); | ||
|
||
Health.Builder healthBuilder = new Health.Builder(); | ||
|
||
testSubject.doHealthCheck(healthBuilder); | ||
|
||
Health result = healthBuilder.build(); | ||
assertEquals(Status.UP.getCode(), result.getStatus().getCode()); | ||
|
||
Map<String, Object> resultDetails = result.getDetails(); | ||
assertFalse(resultDetails.isEmpty()); | ||
assertEquals(2, resultDetails.size()); | ||
String detailsContextOne = (String) resultDetails.get(expectedDetailsContextOne); | ||
assertNotNull(detailsContextOne); | ||
assertEquals(Status.UP.getCode(), detailsContextOne); | ||
String detailsContextTwo = (String) resultDetails.get(expectedDetailsContextTwo); | ||
assertNotNull(detailsContextTwo); | ||
assertEquals(Status.UP.getCode(), detailsContextTwo); | ||
} | ||
|
||
@Test | ||
void testDoHealthCheckStatusReturnsWarning() { | ||
String testContextOne = "context-one"; | ||
String testContextTwo = "context-two"; | ||
String expectedDetailsContextOne = testContextOne + ".connection.active"; | ||
String expectedDetailsContextTwo = testContextTwo + ".connection.active"; | ||
|
||
Map<String, Boolean> testConnections = new HashMap<>(); | ||
testConnections.put(testContextOne, true); | ||
testConnections.put(testContextTwo, false); | ||
when(connectionManager.connections()).thenReturn(testConnections); | ||
|
||
Health.Builder healthBuilder = new Health.Builder(); | ||
|
||
testSubject.doHealthCheck(healthBuilder); | ||
|
||
Health result = healthBuilder.build(); | ||
assertEquals(HealthStatus.WARN, result.getStatus()); | ||
|
||
Map<String, Object> resultDetails = result.getDetails(); | ||
assertFalse(resultDetails.isEmpty()); | ||
assertEquals(2, resultDetails.size()); | ||
String detailsContextOne = (String) resultDetails.get(expectedDetailsContextOne); | ||
assertNotNull(detailsContextOne); | ||
assertEquals(Status.UP.getCode(), detailsContextOne); | ||
String detailsContextTwo = (String) resultDetails.get(expectedDetailsContextTwo); | ||
assertNotNull(detailsContextTwo); | ||
assertEquals(Status.DOWN.getCode(), detailsContextTwo); | ||
} | ||
|
||
@Test | ||
void testDoHealthCheckStatusReturnsDown() { | ||
String testContextOne = "context-one"; | ||
String testContextTwo = "context-two"; | ||
String expectedDetailsContextOne = testContextOne + ".connection.active"; | ||
String expectedDetailsContextTwo = testContextTwo + ".connection.active"; | ||
|
||
Map<String, Boolean> testConnections = new HashMap<>(); | ||
testConnections.put(testContextOne, false); | ||
testConnections.put(testContextTwo, false); | ||
|
||
when(connectionManager.connections()).thenReturn(testConnections); | ||
|
||
Health.Builder healthBuilder = new Health.Builder(); | ||
|
||
testSubject.doHealthCheck(healthBuilder); | ||
|
||
Health result = healthBuilder.build(); | ||
assertEquals(Status.DOWN.getCode(), result.getStatus().getCode()); | ||
|
||
Map<String, Object> resultDetails = result.getDetails(); | ||
assertFalse(resultDetails.isEmpty()); | ||
assertEquals(2, resultDetails.size()); | ||
String detailsContextOne = (String) resultDetails.get(expectedDetailsContextOne); | ||
assertNotNull(detailsContextOne); | ||
assertEquals(Status.DOWN.getCode(), detailsContextOne); | ||
String detailsContextTwo = (String) resultDetails.get(expectedDetailsContextTwo); | ||
assertNotNull(detailsContextTwo); | ||
assertEquals(Status.DOWN.getCode(), detailsContextTwo); | ||
} | ||
} |
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