Skip to content

Commit

Permalink
feat: add health check endpoint to rest api (#3168)
Browse files Browse the repository at this point in the history
* feat: add /health endpoint to rest api

* refactor: adjust to new dir structure

* fix: add new rest api dependency

* docs: add new openapi schema

* docs: manual black run

* refactor: remove some sys-wide details

* docs: minor description changes

* docs: minor description changes

* docs: generate openapi schemas

* tests: improved tests

* refactor: add cls method decorator
  • Loading branch information
danielbichuetti authored Sep 8, 2022
1 parent e0d73f3 commit 1a6cbca
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 2 deletions.
142 changes: 142 additions & 0 deletions docs/_src/api/openapi/openapi-1.8.1rc0.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,28 @@
}
}
}
},
"/health": {
"get": {
"tags": [
"health"
],
"summary": "Get Health Status",
"description": "This endpoint allows external systems to monitor the health of the Haystack REST API.",
"operationId": "get_health_status",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HealthResponse"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -511,6 +533,20 @@
}
}
},
"CPUUsage": {
"title": "CPUUsage",
"required": [
"used"
],
"type": "object",
"properties": {
"used": {
"title": "Used",
"type": "number",
"description": "REST API average CPU usage in percentage"
}
}
},
"CreateLabelSerialized": {
"title": "CreateLabelSerialized",
"required": [
Expand Down Expand Up @@ -693,6 +729,56 @@
},
"additionalProperties": false
},
"GPUInfo": {
"title": "GPUInfo",
"required": [
"index",
"usage"
],
"type": "object",
"properties": {
"index": {
"title": "Index",
"type": "integer",
"description": "GPU index"
},
"usage": {
"title": "Usage",
"allOf": [
{
"$ref": "#/components/schemas/GPUUsage"
}
],
"description": "GPU usage details"
}
}
},
"GPUUsage": {
"title": "GPUUsage",
"required": [
"kernel_usage",
"memory_total",
"memory_used"
],
"type": "object",
"properties": {
"kernel_usage": {
"title": "Kernel Usage",
"type": "number",
"description": "GPU kernel usage in percentage"
},
"memory_total": {
"title": "Memory Total",
"type": "integer",
"description": "Total GPU memory in megabytes"
},
"memory_used": {
"title": "Memory Used",
"type": "integer",
"description": "REST API used GPU memory in megabytes"
}
}
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
Expand All @@ -706,6 +792,48 @@
}
}
},
"HealthResponse": {
"title": "HealthResponse",
"required": [
"version",
"cpu",
"memory"
],
"type": "object",
"properties": {
"version": {
"title": "Version",
"type": "string",
"description": "Haystack version"
},
"cpu": {
"title": "Cpu",
"allOf": [
{
"$ref": "#/components/schemas/CPUUsage"
}
],
"description": "CPU usage details"
},
"memory": {
"title": "Memory",
"allOf": [
{
"$ref": "#/components/schemas/MemoryUsage"
}
],
"description": "Memory usage details"
},
"gpus": {
"title": "Gpus",
"type": "array",
"items": {
"$ref": "#/components/schemas/GPUInfo"
},
"description": "GPU usage details"
}
}
},
"Label": {
"title": "Label",
"required": [
Expand Down Expand Up @@ -774,6 +902,20 @@
}
}
},
"MemoryUsage": {
"title": "MemoryUsage",
"required": [
"used"
],
"type": "object",
"properties": {
"used": {
"title": "Used",
"type": "number",
"description": "REST API used memory in percentage"
}
}
},
"QueryRequest": {
"title": "QueryRequest",
"required": [
Expand Down
142 changes: 142 additions & 0 deletions docs/_src/api/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,28 @@
}
}
}
},
"/health": {
"get": {
"tags": [
"health"
],
"summary": "Get Health Status",
"description": "This endpoint allows external systems to monitor the health of the Haystack REST API.",
"operationId": "get_health_status",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HealthResponse"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -511,6 +533,20 @@
}
}
},
"CPUUsage": {
"title": "CPUUsage",
"required": [
"used"
],
"type": "object",
"properties": {
"used": {
"title": "Used",
"type": "number",
"description": "REST API average CPU usage in percentage"
}
}
},
"CreateLabelSerialized": {
"title": "CreateLabelSerialized",
"required": [
Expand Down Expand Up @@ -693,6 +729,56 @@
},
"additionalProperties": false
},
"GPUInfo": {
"title": "GPUInfo",
"required": [
"index",
"usage"
],
"type": "object",
"properties": {
"index": {
"title": "Index",
"type": "integer",
"description": "GPU index"
},
"usage": {
"title": "Usage",
"allOf": [
{
"$ref": "#/components/schemas/GPUUsage"
}
],
"description": "GPU usage details"
}
}
},
"GPUUsage": {
"title": "GPUUsage",
"required": [
"kernel_usage",
"memory_total",
"memory_used"
],
"type": "object",
"properties": {
"kernel_usage": {
"title": "Kernel Usage",
"type": "number",
"description": "GPU kernel usage in percentage"
},
"memory_total": {
"title": "Memory Total",
"type": "integer",
"description": "Total GPU memory in megabytes"
},
"memory_used": {
"title": "Memory Used",
"type": "integer",
"description": "REST API used GPU memory in megabytes"
}
}
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
Expand All @@ -706,6 +792,48 @@
}
}
},
"HealthResponse": {
"title": "HealthResponse",
"required": [
"version",
"cpu",
"memory"
],
"type": "object",
"properties": {
"version": {
"title": "Version",
"type": "string",
"description": "Haystack version"
},
"cpu": {
"title": "Cpu",
"allOf": [
{
"$ref": "#/components/schemas/CPUUsage"
}
],
"description": "CPU usage details"
},
"memory": {
"title": "Memory",
"allOf": [
{
"$ref": "#/components/schemas/MemoryUsage"
}
],
"description": "Memory usage details"
},
"gpus": {
"title": "Gpus",
"type": "array",
"items": {
"$ref": "#/components/schemas/GPUInfo"
},
"description": "GPU usage details"
}
}
},
"Label": {
"title": "Label",
"required": [
Expand Down Expand Up @@ -774,6 +902,20 @@
}
}
},
"MemoryUsage": {
"title": "MemoryUsage",
"required": [
"used"
],
"type": "object",
"properties": {
"used": {
"title": "Used",
"type": "number",
"description": "REST API used memory in percentage"
}
}
},
"QueryRequest": {
"title": "QueryRequest",
"required": [
Expand Down
6 changes: 6 additions & 0 deletions rest_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies = [
"uvicorn<1",
"gunicorn<21",
"python-multipart<1", # optional FastAPI dependency for form data
"pynvml",
"psutil"
]
dynamic = ["version"]

Expand Down Expand Up @@ -69,3 +71,7 @@ exclude_lines = [
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.black]
line-length = 120
skip_magic_trailing_comma = true # For compatibility with pydoc>=4.6, check if still needed.
Loading

0 comments on commit 1a6cbca

Please sign in to comment.