You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/07/03 23:24:51 UTC

[incubator-openwhisk] branch master updated: add /invokers/healthy/count route to controller (#3838)

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

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d40ca9  add /invokers/healthy/count route to controller (#3838)
5d40ca9 is described below

commit 5d40ca9848ff09e016e1a1701c4f0545dbd49fae
Author: David Grove <dg...@users.noreply.github.com>
AuthorDate: Tue Jul 3 19:24:47 2018 -0400

    add /invokers/healthy/count route to controller (#3838)
    
    * add /numHealthyInvokers route to controller
    
    Add a route to easily get a count of healthy invokers. This route can
    be used to as a check for the system being ready to actually execute
    actions (for example as a readiness probe in a Helm chart or a
    TravisCI built script). Although this information could be extracted by
    client-side processing of the result of the /invokers route, it is
    convenient to do the math on the server side and simply return the count.
---
 .../scala/whisk/core/controller/Controller.scala   | 27 ++++++++++++++--------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/core/controller/src/main/scala/whisk/core/controller/Controller.scala b/core/controller/src/main/scala/whisk/core/controller/Controller.scala
index 04dddcf..e53936b 100644
--- a/core/controller/src/main/scala/whisk/core/controller/Controller.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/Controller.scala
@@ -43,7 +43,7 @@ import whisk.core.entitlement._
 import whisk.core.entity._
 import whisk.core.entity.ActivationId.ActivationIdGenerator
 import whisk.core.entity.ExecManifest.Runtimes
-import whisk.core.loadBalancer.LoadBalancerProvider
+import whisk.core.loadBalancer.{Healthy, LoadBalancerProvider}
 import whisk.http.BasicHttpService
 import whisk.http.BasicRasService
 import whisk.spi.SpiLoader
@@ -134,19 +134,26 @@ class Controller(val instance: ControllerInstanceId,
   private val swagger = new SwaggerDocs(Uri.Path.Empty, "infoswagger.json")
 
   /**
-   * Handles GET /invokers URI.
+   * Handles GET /invokers
+   *             /invokers/healthy/count
    *
-   * @return JSON of invoker health
+   * @return JSON with details of invoker health or count of healthy invokers respectively.
    */
   private val internalInvokerHealth = {
     implicit val executionContext = actorSystem.dispatcher
-    (path("invokers") & get) {
-      complete {
-        loadBalancer
-          .invokerHealth()
-          .map(_.map {
-            case i => s"invoker${i.id.toInt}" -> i.status.asString
-          }.toMap.toJson.asJsObject)
+    (pathPrefix("invokers") & get) {
+      pathEndOrSingleSlash {
+        complete {
+          loadBalancer
+            .invokerHealth()
+            .map(_.map(i => s"invoker${i.id.toInt}" -> i.status.asString).toMap.toJson.asJsObject)
+        }
+      } ~ path("healthy" / "count") {
+        complete {
+          loadBalancer
+            .invokerHealth()
+            .map(_.count(_.status == Healthy).toJson)
+        }
       }
     }
   }