You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/12/10 02:30:20 UTC

[james-project] 17/27: JAMES-2576 Rework HealthChecks routes status code

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit cdbc0ee65faa04a60c4de6fa8bbc65fd89a650be
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Dec 5 12:43:32 2019 +0700

    JAMES-2576 Rework HealthChecks routes status code
    
    Return 503 upon unhealthy checks.
    
    Return 200 upon degraded checks as service can still be used.
---
 CHANGELOG.md                                               |  3 ++-
 .../org/apache/james/GuiceLifecycleHeathCheckTest.java     |  2 +-
 .../apache/james/webadmin/routes/HealthCheckRoutes.java    | 14 ++++++++------
 .../james/webadmin/routes/HealthCheckRoutesTest.java       | 14 +++++++-------
 src/site/markdown/server/manage-webadmin.md                |  8 ++++----
 5 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8a9ed39..2860550 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,8 @@ of tasks being currently executed.
 - JAMES-2855 Multiple library/plugin/docker images/build tool upgrades
 - By default the cassandra keyspace creation by James is now disabled by default. This allow to have credentials limited to a keyspace. It can be enabled by setting cassandra.keyspace.create=true in the cassandra.properties file.
 - Usernames are assumed to be always lower cased. Many users recently complained about mails non received when sending to upper cased local recipients. We decided to simplify the handling of case for local recipients and users by always storing them lower cased.
-  
+- Unhealthy health checks now return HTTP 503 instead of 500, degraded now returns 200 instead of 500. See JAMES-2576.
+
 ### Fixed
 - JAMES-2828 & JAMES-2929 bugs affecting JDBCMailRepository usage with PostgresSQL thanks to Jörg Thomas & Sergey B
 - JAMES-2936 Creating a mailbox using consecutive delimiter character leads to creation of list of unnamed mailbox
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
index 785925f..d2af157 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
@@ -128,7 +128,7 @@ class GuiceLifecycleHeathCheckTest {
                 when()
                     .get("/healthcheck")
                     .then()
-                    .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+                    .statusCode(HttpStatus.SERVICE_UNAVAILABLE_503);
             } finally {
                 latch.countDown();
                 stopMono.block();
diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java
index 8d53407..45d9543 100644
--- a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java
+++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java
@@ -26,6 +26,7 @@ import javax.inject.Inject;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 
+import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.core.healthcheck.HealthCheck;
 import org.apache.james.core.healthcheck.Result;
 import org.apache.james.core.healthcheck.ResultStatus;
@@ -138,12 +139,13 @@ public class HealthCheckRoutes implements PublicRoutes {
     
     private int getCorrespondingStatusCode(ResultStatus resultStatus) {
         switch (resultStatus) {
-        case HEALTHY:
-            return HttpStatus.OK_200;
-        case DEGRADED:
-        case UNHEALTHY:
-        default:
-            return HttpStatus.INTERNAL_SERVER_ERROR_500;
+            case HEALTHY:
+            case DEGRADED:
+                return HttpStatus.OK_200;
+            case UNHEALTHY:
+                return HttpStatus.SERVICE_UNAVAILABLE_503;
+            default:
+                throw new NotImplementedException(resultStatus + " is not supported");
         }
     }
 
diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java
index 869a029..359724d 100644
--- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java
@@ -162,7 +162,7 @@ public class HealthCheckRoutesTest {
         String retrieveBody = when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .statusCode(HttpStatus.SERVICE_UNAVAILABLE_503)
                 .extract()
                 .body().asString();
 
@@ -194,7 +194,7 @@ public class HealthCheckRoutesTest {
         String retrieveBody = when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .statusCode(HttpStatus.SERVICE_UNAVAILABLE_503)
                 .extract()
                 .body().asString();
 
@@ -226,7 +226,7 @@ public class HealthCheckRoutesTest {
         String retrieveBody = when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .statusCode(HttpStatus.OK_200)
                 .extract()
                 .body().asString();
 
@@ -258,7 +258,7 @@ public class HealthCheckRoutesTest {
         String retrieveBody = when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .statusCode(HttpStatus.OK_200)
                 .extract()
                 .body().asString();
 
@@ -289,7 +289,7 @@ public class HealthCheckRoutesTest {
         String retrieveBody = when()
                 .get()
             .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                .statusCode(HttpStatus.SERVICE_UNAVAILABLE_503)
                 .extract()
                 .body().asString();
 
@@ -338,7 +338,7 @@ public class HealthCheckRoutesTest {
         .when()
             .get("/checks/{componentName}")
         .then()
-            .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+            .statusCode(HttpStatus.OK_200)
             .body("componentName", equalTo(NAME_1))
             .body("escapedComponentName", equalTo(NAME_1))
             .body("status", equalTo(ResultStatus.DEGRADED.getValue()))
@@ -354,7 +354,7 @@ public class HealthCheckRoutesTest {
         .when()
             .get("/checks/{componentName}")
         .then()
-            .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+            .statusCode(HttpStatus.SERVICE_UNAVAILABLE_503)
             .body("componentName", equalTo(NAME_1))
             .body("escapedComponentName", equalTo(NAME_1))
             .body("status", equalTo(ResultStatus.UNHEALTHY.getValue()))
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 746ba37..a4ad547 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -99,8 +99,8 @@ Supported health checks include:
 
 Response codes:
 
- - 200: All checks have answered with a Healthy status
- - 500: At least one check have answered with a Unhealthy or Degraded status
+ - 200: All checks have answered with a Healthy or Degraded status. James services can still be used.
+ - 503: At least one check have answered with a Unhealthy status
 
 ### Check single component
 
@@ -123,9 +123,9 @@ Will return the component's name, the component's escaped name, the health statu
 
 Response codes:
 
- - 200: The check has answered with a Healthy status.
+ - 200: The check has answered with a Healthy or Degraded status.
  - 404: A component with the given name was not found.
- - 500: The check has anwered with a Unhealthy or Degraded status.
+ - 503: The check has anwered with a Unhealthy status.
  
 ### List all health checks
  


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org