Commit 43fd1d1e authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'custom-readiness-check-api' into 'master'

customized readiness check to make sure cache layer is ready before serving traffic

See merge request !53
parents 009ea359 a605b2b4
Pipeline #43596 passed with stages
in 22 minutes and 12 seconds
......@@ -48,8 +48,14 @@ spec:
cpu: "300m"
readinessProbe:
httpGet:
path: /api/partition/v1/swagger-ui.html
port: 80
path: /actuator/health
port: 8081
livenessProbe:
httpGet:
path: /actuator/health
port: 8081
initialDelaySeconds: 250
periodSeconds: 10
volumeMounts:
- name: azure-keyvault
mountPath: "/mnt/azure-keyvault"
......
......@@ -74,8 +74,14 @@ spec:
- containerPort: 80
readinessProbe:
httpGet:
path: /api/partition/v1/swagger-ui.html
port: 80
path: /actuator/health
port: 8081
livenessProbe:
httpGet:
path: /actuator/health
port: 8081
initialDelaySeconds: 250
periodSeconds: 10
volumeMounts:
- name: azure-keyvault
mountPath: "/mnt/azure-keyvault"
......
......@@ -16,7 +16,7 @@ tags:
- name: health-check
description: Health Check
paths:
/_ah/liveness_check:
/actuator/health:
get:
tags:
- health-check
......@@ -40,7 +40,7 @@ paths:
security:
- JWT:
- global
/_ah/readiness_check:
/actuator/health:
get:
tags:
- health-check
......
......@@ -18,13 +18,13 @@ Partition service is responsible for creating and retrieving the partition speci
## Health Check <a name="checking-service-health"></a>
An endpoint to check if service is up and running.
```
GET api/partition/v1/_ah/liveness_check
GET api/partition/v1/actuator/health
```
<details><summary>curl</summary>
```
curl --request GET \
--url 'https://<base_url>/api/partition/v1/_ah/liveness_check'
--url 'https://<base_url>/api/partition/v1/actuator/health'
```
</details>
......
......@@ -56,6 +56,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
......
// Copyright 2017-2020, Schlumberger
//
// 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.opengroup.osdu.partition.api;
import java.util.Collections;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(path= "/_ah", produces = "application/json")
public class HealthCheck {
@Autowired
private AuditLogger auditLogger;
@GetMapping("/liveness_check")
public ResponseEntity<String> livenessCheck() {
ResponseEntity responseEntity = new ResponseEntity<>("Partition service is alive", HttpStatus.OK);
this.auditLogger.readServiceLivenessSuccess(Collections.singletonList(responseEntity.toString()));
return responseEntity;
}
@GetMapping("/readiness_check")
public ResponseEntity<String> readinessCheck() {
return new ResponseEntity<>("Partition service is ready", HttpStatus.OK);
}
}
// Copyright 2017-2020, Schlumberger
//
// 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.opengroup.osdu.partition.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.springframework.http.HttpStatus;
@RunWith(MockitoJUnitRunner.class)
public class HealthCheckTest {
@Mock
private AuditLogger auditLogger;
@InjectMocks
private HealthCheck sut;
@Test
public void should_returnHttp200_when_checkLiveness() {
assertEquals(HttpStatus.OK, this.sut.livenessCheck().getStatusCode());
}
@Test
public void should_returnHttp200_when_checkReadiness() {
assertEquals(HttpStatus.OK, this.sut.readinessCheck().getStatusCode());
}
}
\ No newline at end of file
......@@ -93,10 +93,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
......
......@@ -107,7 +107,7 @@ $ (cd testing/partition-test-core/ && mvn clean install)
$ (cd testing/partition-test-azure/ && mvn clean test)
```
A liveness check can also be performed at `http://localhost:8080/api/partition/v1/_ah/liveness_check`. Other apis can be found on the swagger page
A liveness check can also be performed at `http://localhost:8080/api/partition/v1/actuator/health`. Other apis can be found on the swagger page
## Debugging
......
......@@ -151,7 +151,7 @@ stages:
attempt_counter=0
max_attempts=60
# NOTE that the PARTITION_BASE_URL already has a '/' at the end of it
until [ $(curl -s -o /dev/null -w "%{http_code}" $(PARTITION_BASE_URL)api/partition/v1/_ah/liveness_check) -eq 200 ]; do
until [ $(curl -s -o /dev/null -w "%{http_code}" $(PARTITION_BASE_URL)api/partition/v1/actuator/health) -eq 200 ]; do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Service is not available, please check the deployment"
exit 1
......
......@@ -40,7 +40,7 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.authorizeRequests()
.antMatchers("/", "/index.html",
"/_ah/*",
"/actuator/*",
"/api-docs",
"/configuration/ui",
"/swagger-resources/**",
......
......@@ -36,6 +36,10 @@ redis.ssl.enabled=true
redis.connection.timeout=15
redis.database=${REDIS_DATABASE}
# health check
management.health.azure-key-vault.enabled=false
management.server.port=8081
azure.cryptography.enabled=false
azure.eventgrid.topic.enabled=false
azure.eventgrid.manager.enabled=false
......@@ -42,10 +42,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
......
......@@ -41,10 +41,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
......
......@@ -15,7 +15,7 @@ cache.provider=vm
cache.expiration=1
cache.maxSize=1000
ibm.health-check-uri=/api/partition/v1/_ah/liveness_check,/api/partition/v1/_ah/readiness_check
ibm.health-check-uri=/api/partition/v1/actuator/health,/api/partition/v1/actuator/health
excluded.uris.for.partition-filter=/api/partition/v1/partitions
#Database Configuration
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment