mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-29 21:31:48 +02:00
fix(api): update health endpoint to return detailed health info
- Changed the response type of the health endpoint to use a new HealthMap type for better clarity. - Updated the health information retrieval method to GetHealthInfoWithoutDetail for improved accuracy in the response. - Adjusted Swagger documentation to reflect the new response structure.
This commit is contained in:
@@ -855,7 +855,7 @@
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/github_com_yusing_goutils_events.Event"
|
||||
"$ref": "#/definitions/Event"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1210,10 +1210,7 @@
|
||||
"200": {
|
||||
"description": "Health info by route name",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/HealthStatusString"
|
||||
}
|
||||
"$ref": "#/definitions/HealthMap"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
@@ -3827,6 +3824,42 @@
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"Event": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"category": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"data": {
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"level": {
|
||||
"$ref": "#/definitions/events.Level",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"uuid": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
}
|
||||
},
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"FileType": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
@@ -3996,7 +4029,6 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"latency": {
|
||||
"description": "latency in microseconds",
|
||||
"type": "number",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
@@ -4015,7 +4047,6 @@
|
||||
"x-omitempty": false
|
||||
},
|
||||
"uptime": {
|
||||
"description": "uptime in milliseconds",
|
||||
"type": "number",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
@@ -4088,6 +4119,14 @@
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"HealthMap": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/HealthInfoWithoutDetail"
|
||||
},
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"HealthStatusString": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
@@ -6718,37 +6757,6 @@
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"github_com_yusing_goutils_events.Event": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"category": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"data": {
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"level": {
|
||||
"$ref": "#/definitions/events.Level",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "string",
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
}
|
||||
},
|
||||
"x-nullable": false,
|
||||
"x-omitempty": false
|
||||
},
|
||||
"icons.Source": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
||||
@@ -295,6 +295,20 @@ definitions:
|
||||
message:
|
||||
type: string
|
||||
type: object
|
||||
Event:
|
||||
properties:
|
||||
action:
|
||||
type: string
|
||||
category:
|
||||
type: string
|
||||
data: {}
|
||||
level:
|
||||
$ref: '#/definitions/events.Level'
|
||||
timestamp:
|
||||
type: string
|
||||
uuid:
|
||||
type: string
|
||||
type: object
|
||||
FileType:
|
||||
enum:
|
||||
- config
|
||||
@@ -375,7 +389,6 @@ definitions:
|
||||
HealthInfoWithoutDetail:
|
||||
properties:
|
||||
latency:
|
||||
description: latency in microseconds
|
||||
type: number
|
||||
status:
|
||||
enum:
|
||||
@@ -387,7 +400,6 @@ definitions:
|
||||
- unknown
|
||||
type: string
|
||||
uptime:
|
||||
description: uptime in milliseconds
|
||||
type: number
|
||||
type: object
|
||||
HealthJSON:
|
||||
@@ -419,6 +431,10 @@ definitions:
|
||||
url:
|
||||
type: string
|
||||
type: object
|
||||
HealthMap:
|
||||
additionalProperties:
|
||||
$ref: '#/definitions/HealthInfoWithoutDetail'
|
||||
type: object
|
||||
HealthStatusString:
|
||||
enum:
|
||||
- unknown
|
||||
@@ -1755,18 +1771,6 @@ definitions:
|
||||
- LevelInfo
|
||||
- LevelWarn
|
||||
- LevelError
|
||||
github_com_yusing_goutils_events.Event:
|
||||
properties:
|
||||
action:
|
||||
type: string
|
||||
category:
|
||||
type: string
|
||||
data: {}
|
||||
level:
|
||||
$ref: '#/definitions/events.Level'
|
||||
timestamp:
|
||||
type: string
|
||||
type: object
|
||||
icons.Source:
|
||||
enum:
|
||||
- https://
|
||||
@@ -1828,12 +1832,12 @@ definitions:
|
||||
type: string
|
||||
kernel_version:
|
||||
type: string
|
||||
load_avg_15m:
|
||||
type: string
|
||||
load_avg_1m:
|
||||
type: string
|
||||
load_avg_5m:
|
||||
type: string
|
||||
load_avg_15m:
|
||||
type: string
|
||||
mem_pct:
|
||||
type: string
|
||||
mem_total:
|
||||
@@ -2484,7 +2488,7 @@ paths:
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/github_com_yusing_goutils_events.Event'
|
||||
$ref: '#/definitions/Event'
|
||||
type: array
|
||||
"403":
|
||||
description: 'Forbidden: unauthorized'
|
||||
@@ -2721,9 +2725,7 @@ paths:
|
||||
"200":
|
||||
description: Health info by route name
|
||||
schema:
|
||||
additionalProperties:
|
||||
$ref: '#/definitions/HealthStatusString'
|
||||
type: object
|
||||
$ref: '#/definitions/HealthMap'
|
||||
"403":
|
||||
description: Forbidden
|
||||
schema:
|
||||
|
||||
@@ -6,11 +6,14 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
entrypoint "github.com/yusing/godoxy/internal/entrypoint/types"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
"github.com/yusing/goutils/apitypes"
|
||||
"github.com/yusing/goutils/http/httpheaders"
|
||||
"github.com/yusing/goutils/http/websocket"
|
||||
)
|
||||
|
||||
type HealthMap = map[string]types.HealthInfoWithoutDetail // @name HealthMap
|
||||
|
||||
// @x-id "health"
|
||||
// @BasePath /api/v1
|
||||
// @Summary Get routes health info
|
||||
@@ -18,7 +21,7 @@ import (
|
||||
// @Tags v1,websocket
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]types.HealthStatusString "Health info by route name"
|
||||
// @Success 200 {object} HealthMap "Health info by route name"
|
||||
// @Failure 403 {object} apitypes.ErrorResponse
|
||||
// @Failure 500 {object} apitypes.ErrorResponse
|
||||
// @Router /health [get]
|
||||
@@ -30,9 +33,9 @@ func Health(c *gin.Context) {
|
||||
}
|
||||
if httpheaders.IsWebsocket(c.Request.Header) {
|
||||
websocket.PeriodicWrite(c, 1*time.Second, func() (any, error) {
|
||||
return ep.GetHealthInfoSimple(), nil
|
||||
return ep.GetHealthInfoWithoutDetail(), nil
|
||||
})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, ep.GetHealthInfoSimple())
|
||||
c.JSON(http.StatusOK, ep.GetHealthInfoWithoutDetail())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user