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

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 19938437f1 Add readiness metric to pinot-server (#9168)
19938437f1 is described below

commit 19938437f11ba9590a739965a3c9883a064dea92
Author: Aidar Bariev <[email protected]>
AuthorDate: Mon Aug 8 14:43:04 2022 -0700

    Add readiness metric to pinot-server (#9168)
---
 .../java/org/apache/pinot/common/metrics/ServerMeter.java |  3 +++
 .../pinot/server/api/resources/HealthCheckResource.java   | 15 +++++++++++----
 .../pinot/server/starter/helix/AdminApiApplication.java   |  2 ++
 .../org/apache/pinot/server/api/AccessControlTest.java    |  3 +++
 .../org/apache/pinot/server/api/BaseResourceTest.java     |  1 +
 5 files changed, 20 insertions(+), 4 deletions(-)

diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/metrics/ServerMeter.java 
b/pinot-common/src/main/java/org/apache/pinot/common/metrics/ServerMeter.java
index c0d173fc76..f5cf9659dc 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/metrics/ServerMeter.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/metrics/ServerMeter.java
@@ -75,6 +75,9 @@ public enum ServerMeter implements AbstractMetrics.Meter {
   INDEXING_FAILURES("attributeValues", true),
   QUERY_HAS_MV_SELECTION_ORDER_BY("queryHasMVSelectionOrderBy", false),
 
+  READINESS_CHECK_OK_CALLS("readinessCheck", true),
+  READINESS_CHECK_BAD_CALLS("readinessCheck", true),
+
   // Netty connection metrics
   NETTY_CONNECTION_BYTES_RECEIVED("nettyConnection", true),
   NETTY_CONNECTION_RESPONSES_SENT("nettyConnection", true),
diff --git 
a/pinot-server/src/main/java/org/apache/pinot/server/api/resources/HealthCheckResource.java
 
b/pinot-server/src/main/java/org/apache/pinot/server/api/resources/HealthCheckResource.java
index 9f69e94675..f5bc5ec3ff 100644
--- 
a/pinot-server/src/main/java/org/apache/pinot/server/api/resources/HealthCheckResource.java
+++ 
b/pinot-server/src/main/java/org/apache/pinot/server/api/resources/HealthCheckResource.java
@@ -32,6 +32,8 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import org.apache.pinot.common.metrics.ServerMeter;
+import org.apache.pinot.common.metrics.ServerMetrics;
 import org.apache.pinot.common.utils.ServiceStatus;
 import org.apache.pinot.common.utils.ServiceStatus.Status;
 import org.apache.pinot.server.starter.helix.AdminApiApplication;
@@ -48,6 +50,9 @@ public class HealthCheckResource {
   @Named(AdminApiApplication.SERVER_INSTANCE_ID)
   private String _instanceId;
 
+  @Inject
+  private ServerMetrics _serverMetrics;
+
   @GET
   @Path("/health")
   @Produces(MediaType.TEXT_PLAIN)
@@ -61,7 +66,7 @@ public class HealthCheckResource {
     if ("liveness".equalsIgnoreCase(checkType)) {
       return "OK";
     } else {
-      return getReadinessStatus(_instanceId);
+      return getReadinessStatus();
     }
   }
 
@@ -87,14 +92,16 @@ public class HealthCheckResource {
       @ApiResponse(code = 503, message = "Server is not ready to serve 
queries")
   })
   public String checkReadiness() {
-    return getReadinessStatus(_instanceId);
+    return getReadinessStatus();
   }
 
-  private static String getReadinessStatus(String instanceId) throws 
WebApplicationException {
-    Status status = ServiceStatus.getServiceStatus(instanceId);
+  private String getReadinessStatus() throws WebApplicationException {
+    Status status = ServiceStatus.getServiceStatus(_instanceId);
     if (status == Status.GOOD) {
+      
_serverMetrics.addMeteredGlobalValue(ServerMeter.READINESS_CHECK_OK_CALLS, 1);
       return "OK";
     }
+    
_serverMetrics.addMeteredGlobalValue(ServerMeter.READINESS_CHECK_BAD_CALLS, 1);
     String errMessage = String.format("Pinot server status is %s", status);
     Response response =
         
Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(errMessage).build();
diff --git 
a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java
 
b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java
index dec6ca8085..48c07aeea1 100644
--- 
a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java
+++ 
b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java
@@ -28,6 +28,7 @@ import java.util.List;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
+import org.apache.pinot.common.metrics.ServerMetrics;
 import org.apache.pinot.core.transport.ListenerConfig;
 import org.apache.pinot.core.util.ListenerConfigUtil;
 import org.apache.pinot.server.access.AccessControlFactory;
@@ -66,6 +67,7 @@ public class AdminApiApplication extends ResourceConfig {
       @Override
       protected void configure() {
         bind(_serverInstance).to(ServerInstance.class);
+        bind(_serverInstance.getServerMetrics()).to(ServerMetrics.class);
         bind(accessControlFactory).to(AccessControlFactory.class);
         
bind(serverConf.getProperty(CommonConstants.Server.CONFIG_OF_INSTANCE_ID)).named(SERVER_INSTANCE_ID);
       }
diff --git 
a/pinot-server/src/test/java/org/apache/pinot/server/api/AccessControlTest.java 
b/pinot-server/src/test/java/org/apache/pinot/server/api/AccessControlTest.java
index 7546e70441..23e1678705 100644
--- 
a/pinot-server/src/test/java/org/apache/pinot/server/api/AccessControlTest.java
+++ 
b/pinot-server/src/test/java/org/apache/pinot/server/api/AccessControlTest.java
@@ -31,6 +31,7 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 import org.apache.commons.io.FileUtils;
 import org.apache.pinot.common.config.TlsConfig;
+import org.apache.pinot.common.metrics.ServerMetrics;
 import org.apache.pinot.core.auth.BasicAuthUtils;
 import org.apache.pinot.core.transport.ListenerConfig;
 import org.apache.pinot.server.access.AccessControl;
@@ -53,6 +54,7 @@ import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 
 public class AccessControlTest {
@@ -71,6 +73,7 @@ public class AccessControlTest {
     // Mock the instance data manager
     // Mock the server instance
     ServerInstance serverInstance = mock(ServerInstance.class);
+    
when(serverInstance.getServerMetrics()).thenReturn(mock(ServerMetrics.class));
 
     PinotConfiguration serverConf = 
DefaultHelixStarterServerConfig.loadDefaultServerConf();
     String hostname = 
serverConf.getProperty(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST,
diff --git 
a/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java 
b/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java
index c0ad22a2dc..7eba8b7f0d 100644
--- 
a/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java
+++ 
b/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java
@@ -107,6 +107,7 @@ public abstract class BaseResourceTest {
 
     // Mock the server instance
     ServerInstance serverInstance = mock(ServerInstance.class);
+    
when(serverInstance.getServerMetrics()).thenReturn(mock(ServerMetrics.class));
     
when(serverInstance.getInstanceDataManager()).thenReturn(instanceDataManager);
     when(serverInstance.getInstanceDataManager().getSegmentFileDirectory())
         .thenReturn(FileUtils.getTempDirectoryPath());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to