You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2020/10/12 19:51:42 UTC

[incubator-pinot] 01/01: Adding a flag in PinotServiceManager to allow health check includes all components health check

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

xiangfu pushed a commit to branch pinotSM_flag_for_health_check
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit 01419655e077675768a9e641258a8313be767b13
Author: Xiang Fu <fx...@gmail.com>
AuthorDate: Mon Oct 12 12:51:04 2020 -0700

    Adding a flag in PinotServiceManager to allow health check includes all components health check
---
 .../tools/admin/command/StartServiceManagerCommand.java  | 12 +++++++++++-
 .../apache/pinot/tools/service/PinotServiceManager.java  | 16 +++++++++++-----
 .../api/resources/PinotServiceManagerHealthCheck.java    | 15 +++++++++++++++
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java
index caa1ca0..a470efd 100644
--- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java
+++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java
@@ -69,6 +69,8 @@ public class StartServiceManagerCommand extends AbstractBaseAdminCommand impleme
   private String _clusterName = DEFAULT_CLUSTER_NAME;
   @Option(name = "-port", required = true, metaVar = "<int>", usage = "Pinot service manager admin port, -1 means disable, 0 means a random available port.")
   private int _port;
+  @Option(name = "-healthCheckAllComponents", metaVar = "<boolean>", usage = "Pinot service manager health check returns the all components health check. The health check returns OK when all the components are returning OK.")
+  private boolean _healthCheckAllComponents;
   @Option(name = "-bootstrapConfigPaths", handler = StringArrayOptionHandler.class, required = false, usage = "A list of Pinot service config file paths. Each config file requires an extra config: 'pinot.service.role' to indicate which service to start.", forbids = {"-bootstrapServices"})
   private String[] _bootstrapConfigPaths;
   @Option(name = "-bootstrapServices", handler = StringArrayOptionHandler.class, required = false, usage = "A list of Pinot service roles to start with default config. E.g. CONTROLLER/BROKER/SERVER", forbids = {"-bootstrapConfigPaths"})
@@ -195,7 +197,7 @@ public class StartServiceManagerCommand extends AbstractBaseAdminCommand impleme
   }
 
   private String startServiceManager() {
-    _pinotServiceManager = new PinotServiceManager(_zkAddress, _clusterName, _port);
+    _pinotServiceManager = new PinotServiceManager(_zkAddress, _clusterName, _port, _healthCheckAllComponents);
     _pinotServiceManager.start();
     return _pinotServiceManager.getInstanceId();
   }
@@ -303,4 +305,12 @@ public class StartServiceManagerCommand extends AbstractBaseAdminCommand impleme
     _bootstrapConfigurations.add(new SimpleImmutableEntry<>(role, config));
     return this;
   }
+
+  public boolean isHealthCheckAllComponents() {
+    return _healthCheckAllComponents;
+  }
+
+  public void setHealthCheckAllComponents(boolean healthCheckAllComponents) {
+    _healthCheckAllComponents = healthCheckAllComponents;
+  }
 }
diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java b/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java
index 63fa3ea..ed8305f 100644
--- a/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java
+++ b/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java
@@ -54,18 +54,19 @@ public class PinotServiceManager {
   private final String _clusterName;
   private final int _port;
   private final String _instanceId;
+  private final boolean _healthCheckAllComponents;
   private PinotServiceManagerAdminApiApplication _pinotServiceManagerAdminApplication;
   private boolean _isStarted = false;
 
   public PinotServiceManager(String zkAddress, String clusterName) {
-    this(zkAddress, clusterName, 0);
+    this(zkAddress, clusterName, 0, false);
   }
 
-  public PinotServiceManager(String zkAddress, String clusterName, int port) {
-    this(zkAddress, clusterName, null, port);
+  public PinotServiceManager(String zkAddress, String clusterName, int port, boolean healthCheckAllComponents) {
+    this(zkAddress, clusterName, null, port, healthCheckAllComponents);
   }
 
-  public PinotServiceManager(String zkAddress, String clusterName, String hostname, int port) {
+  public PinotServiceManager(String zkAddress, String clusterName, String hostname, int port, boolean healthCheckAllComponents) {
     _zkAddress = zkAddress;
     _clusterName = clusterName;
     if (port == 0) {
@@ -76,10 +77,11 @@ public class PinotServiceManager {
       hostname = NetUtil.getHostnameOrAddress();
     }
     _instanceId = String.format("ServiceManager_%s_%d", hostname, port);
+    _healthCheckAllComponents = healthCheckAllComponents;
   }
 
   public static void main(String[] args) {
-    PinotServiceManager pinotServiceManager = new PinotServiceManager("localhost:2181", "pinot-demo", 8085);
+    PinotServiceManager pinotServiceManager = new PinotServiceManager("localhost:2181", "pinot-demo", 8085, false);
     pinotServiceManager.start();
   }
 
@@ -228,4 +230,8 @@ public class PinotServiceManager {
   public boolean stopPinotInstanceById(String instanceName) {
     return stopPinotInstance(_runningInstanceMap.get(instanceName));
   }
+
+  public boolean isHealthCheckAllComponents() {
+    return _healthCheckAllComponents;
+  }
 }
diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/service/api/resources/PinotServiceManagerHealthCheck.java b/pinot-tools/src/main/java/org/apache/pinot/tools/service/api/resources/PinotServiceManagerHealthCheck.java
index bd3ac36..bed4bc7 100644
--- a/pinot-tools/src/main/java/org/apache/pinot/tools/service/api/resources/PinotServiceManagerHealthCheck.java
+++ b/pinot-tools/src/main/java/org/apache/pinot/tools/service/api/resources/PinotServiceManagerHealthCheck.java
@@ -25,6 +25,7 @@ import io.swagger.annotations.ApiParam;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
 import java.util.Map;
+import javax.inject.Inject;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -33,18 +34,32 @@ import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.apache.pinot.common.utils.ServiceStatus;
+import org.apache.pinot.tools.service.PinotServiceManager;
 
 
 @Api(tags = "Health")
 @Path("/")
 public class PinotServiceManagerHealthCheck {
 
+  @Inject
+  private PinotServiceManager _pinotServiceManager;
+
   @GET
   @Produces(MediaType.TEXT_PLAIN)
   @Path("health")
   @ApiOperation(value = "Checking Pinot Service health")
   @ApiResponses(value = {@ApiResponse(code = 200, message = "Pinot Starter is healthy"), @ApiResponse(code = 503, message = "Pinot Starter is not healthy")})
   public String getStarterHealth() {
+    if (_pinotServiceManager.isHealthCheckAllComponents()) {
+      Map<String, Map<String, String>> serviceStatusMap = ServiceStatus.getServiceStatusMap();
+      for (String instanceName : serviceStatusMap.keySet()) {
+        ServiceStatus.Status status = ServiceStatus.getServiceStatus(instanceName);
+        if (status != ServiceStatus.Status.GOOD) {
+          throw new WebApplicationException(String.format("Pinot instance [ %s ] status is [ %s ]", instanceName, status),
+              Response.Status.SERVICE_UNAVAILABLE);
+        }
+      }
+    }
     ServiceStatus.Status status = ServiceStatus.getServiceStatus();
     if (status == ServiceStatus.Status.GOOD) {
       return "OK";


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org