mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 16:58:31 +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": {
|
"schema": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/github_com_yusing_goutils_events.Event"
|
"$ref": "#/definitions/Event"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1210,10 +1210,7 @@
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "Health info by route name",
|
"description": "Health info by route name",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"$ref": "#/definitions/HealthMap"
|
||||||
"additionalProperties": {
|
|
||||||
"$ref": "#/definitions/HealthStatusString"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"403": {
|
"403": {
|
||||||
@@ -3827,6 +3824,42 @@
|
|||||||
"x-nullable": false,
|
"x-nullable": false,
|
||||||
"x-omitempty": 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": {
|
"FileType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -3996,7 +4029,6 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"latency": {
|
"latency": {
|
||||||
"description": "latency in microseconds",
|
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"x-nullable": false,
|
"x-nullable": false,
|
||||||
"x-omitempty": false
|
"x-omitempty": false
|
||||||
@@ -4015,7 +4047,6 @@
|
|||||||
"x-omitempty": false
|
"x-omitempty": false
|
||||||
},
|
},
|
||||||
"uptime": {
|
"uptime": {
|
||||||
"description": "uptime in milliseconds",
|
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"x-nullable": false,
|
"x-nullable": false,
|
||||||
"x-omitempty": false
|
"x-omitempty": false
|
||||||
@@ -4088,6 +4119,14 @@
|
|||||||
"x-nullable": false,
|
"x-nullable": false,
|
||||||
"x-omitempty": false
|
"x-omitempty": false
|
||||||
},
|
},
|
||||||
|
"HealthMap": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"$ref": "#/definitions/HealthInfoWithoutDetail"
|
||||||
|
},
|
||||||
|
"x-nullable": false,
|
||||||
|
"x-omitempty": false
|
||||||
|
},
|
||||||
"HealthStatusString": {
|
"HealthStatusString": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -6718,37 +6757,6 @@
|
|||||||
"x-nullable": false,
|
"x-nullable": false,
|
||||||
"x-omitempty": 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": {
|
"icons.Source": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
|||||||
@@ -295,6 +295,20 @@ definitions:
|
|||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
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:
|
FileType:
|
||||||
enum:
|
enum:
|
||||||
- config
|
- config
|
||||||
@@ -375,7 +389,6 @@ definitions:
|
|||||||
HealthInfoWithoutDetail:
|
HealthInfoWithoutDetail:
|
||||||
properties:
|
properties:
|
||||||
latency:
|
latency:
|
||||||
description: latency in microseconds
|
|
||||||
type: number
|
type: number
|
||||||
status:
|
status:
|
||||||
enum:
|
enum:
|
||||||
@@ -387,7 +400,6 @@ definitions:
|
|||||||
- unknown
|
- unknown
|
||||||
type: string
|
type: string
|
||||||
uptime:
|
uptime:
|
||||||
description: uptime in milliseconds
|
|
||||||
type: number
|
type: number
|
||||||
type: object
|
type: object
|
||||||
HealthJSON:
|
HealthJSON:
|
||||||
@@ -419,6 +431,10 @@ definitions:
|
|||||||
url:
|
url:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
HealthMap:
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/definitions/HealthInfoWithoutDetail'
|
||||||
|
type: object
|
||||||
HealthStatusString:
|
HealthStatusString:
|
||||||
enum:
|
enum:
|
||||||
- unknown
|
- unknown
|
||||||
@@ -1755,18 +1771,6 @@ definitions:
|
|||||||
- LevelInfo
|
- LevelInfo
|
||||||
- LevelWarn
|
- LevelWarn
|
||||||
- LevelError
|
- 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:
|
icons.Source:
|
||||||
enum:
|
enum:
|
||||||
- https://
|
- https://
|
||||||
@@ -1828,12 +1832,12 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
kernel_version:
|
kernel_version:
|
||||||
type: string
|
type: string
|
||||||
|
load_avg_15m:
|
||||||
|
type: string
|
||||||
load_avg_1m:
|
load_avg_1m:
|
||||||
type: string
|
type: string
|
||||||
load_avg_5m:
|
load_avg_5m:
|
||||||
type: string
|
type: string
|
||||||
load_avg_15m:
|
|
||||||
type: string
|
|
||||||
mem_pct:
|
mem_pct:
|
||||||
type: string
|
type: string
|
||||||
mem_total:
|
mem_total:
|
||||||
@@ -2484,7 +2488,7 @@ paths:
|
|||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
items:
|
items:
|
||||||
$ref: '#/definitions/github_com_yusing_goutils_events.Event'
|
$ref: '#/definitions/Event'
|
||||||
type: array
|
type: array
|
||||||
"403":
|
"403":
|
||||||
description: 'Forbidden: unauthorized'
|
description: 'Forbidden: unauthorized'
|
||||||
@@ -2721,9 +2725,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: Health info by route name
|
description: Health info by route name
|
||||||
schema:
|
schema:
|
||||||
additionalProperties:
|
$ref: '#/definitions/HealthMap'
|
||||||
$ref: '#/definitions/HealthStatusString'
|
|
||||||
type: object
|
|
||||||
"403":
|
"403":
|
||||||
description: Forbidden
|
description: Forbidden
|
||||||
schema:
|
schema:
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
entrypoint "github.com/yusing/godoxy/internal/entrypoint/types"
|
entrypoint "github.com/yusing/godoxy/internal/entrypoint/types"
|
||||||
|
"github.com/yusing/godoxy/internal/types"
|
||||||
"github.com/yusing/goutils/apitypes"
|
"github.com/yusing/goutils/apitypes"
|
||||||
"github.com/yusing/goutils/http/httpheaders"
|
"github.com/yusing/goutils/http/httpheaders"
|
||||||
"github.com/yusing/goutils/http/websocket"
|
"github.com/yusing/goutils/http/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type HealthMap = map[string]types.HealthInfoWithoutDetail // @name HealthMap
|
||||||
|
|
||||||
// @x-id "health"
|
// @x-id "health"
|
||||||
// @BasePath /api/v1
|
// @BasePath /api/v1
|
||||||
// @Summary Get routes health info
|
// @Summary Get routes health info
|
||||||
@@ -18,7 +21,7 @@ import (
|
|||||||
// @Tags v1,websocket
|
// @Tags v1,websocket
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce 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 403 {object} apitypes.ErrorResponse
|
||||||
// @Failure 500 {object} apitypes.ErrorResponse
|
// @Failure 500 {object} apitypes.ErrorResponse
|
||||||
// @Router /health [get]
|
// @Router /health [get]
|
||||||
@@ -30,9 +33,9 @@ func Health(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
if httpheaders.IsWebsocket(c.Request.Header) {
|
if httpheaders.IsWebsocket(c.Request.Header) {
|
||||||
websocket.PeriodicWrite(c, 1*time.Second, func() (any, error) {
|
websocket.PeriodicWrite(c, 1*time.Second, func() (any, error) {
|
||||||
return ep.GetHealthInfoSimple(), nil
|
return ep.GetHealthInfoWithoutDetail(), nil
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, ep.GetHealthInfoSimple())
|
c.JSON(http.StatusOK, ep.GetHealthInfoWithoutDetail())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ type (
|
|||||||
HealthInfoWithoutDetail
|
HealthInfoWithoutDetail
|
||||||
Detail string `json:"detail"`
|
Detail string `json:"detail"`
|
||||||
} // @name HealthInfo
|
} // @name HealthInfo
|
||||||
|
|
||||||
HealthMap = map[string]HealthStatusString // @name HealthMap
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user