This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎏 introduce
/readyz
endpoint probe (#463)
* feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe * feat: introduce endpoint probe --------- Co-authored-by: Jakub Háva <jakub.hava@h2o.ai>
- Loading branch information
Showing
11 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ terraform.tfstate* | |
|
||
### | ||
.DS_Store | ||
|
||
# VSCode | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...t-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ReadyzApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ai.h2o.mojos.deploy.local.rest.controller; | ||
|
||
import ai.h2o.mojos.deploy.common.rest.api.ReadyzApi; | ||
import ai.h2o.mojos.deploy.common.rest.model.ModelSchema; | ||
import ai.h2o.mojos.deploy.common.transform.MojoScorer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class ReadyzApiController implements ReadyzApi { | ||
|
||
private final MojoScorer scorer; | ||
private static final Logger log = LoggerFactory.getLogger(ReadyzApiController.class); | ||
|
||
public ReadyzApiController(MojoScorer scorer) { | ||
this.scorer = scorer; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<String> getReadyz() { | ||
try { | ||
ModelSchema modelSchema = scorer.getModelInfo().getSchema(); | ||
log.trace("model is ready: {}", modelSchema); | ||
return ResponseEntity.ok("Ready"); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Not ready"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
logging.level.ai.h2o.mojos.deploy.common.transform.MojoScorer=${LOGLEVEL} | ||
logging.level.ai.h2o.mojos.deploy.local.rest.controller.ModelsApiController=${LOGLEVEL} | ||
logging.level.ai.h2o.mojos.deploy.local.rest.controller.ReadyzApiController=${LOGLEVEL} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...orer/src/test/java/ai/h2o/mojos/deploy/local/rest/controller/ReadyzApiControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ai.h2o.mojos.deploy.local.rest.controller; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import ai.h2o.mojos.deploy.common.rest.model.Model; | ||
import ai.h2o.mojos.deploy.common.rest.model.ModelSchema; | ||
import ai.h2o.mojos.deploy.common.transform.MojoScorer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ReadyzApiControllerTest { | ||
|
||
@Mock private MojoScorer scorer; | ||
|
||
@InjectMocks private ReadyzApiController controller; | ||
|
||
@Test | ||
void getReadyz_WhenModelSchemaSucceeds_ReturnsOk() { | ||
Model model = new Model(); | ||
model.setSchema(new ModelSchema()); | ||
when(scorer.getModelInfo()).thenReturn(model); | ||
|
||
ResponseEntity<String> response = controller.getReadyz(); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertEquals("Ready", response.getBody()); | ||
} | ||
|
||
@Test | ||
void getReadyz_WhenModelSchemaFails_ReturnsError() { | ||
when(scorer.getModelInfo()).thenThrow(new RuntimeException("Test error")); | ||
|
||
ResponseEntity<String> response = controller.getReadyz(); | ||
|
||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); | ||
assertEquals("Not ready", response.getBody()); | ||
} | ||
} |