added health check endpoint + fixed logging

* set go-gin to release mode
* added health check endpoint
* excluded endpoint from logger

see #63
This commit is contained in:
Bernhard B
2021-01-16 20:12:12 +01:00
parent 0ae4a5b0af
commit f5d3880c49
6 changed files with 78 additions and 4 deletions

View File

@@ -9,8 +9,6 @@ ARG SIGNAL_CLI_VERSION
ARG ZKGROUP_VERSION
ARG SWAG_VERSION
ENV GIN_MODE=release
COPY ext/libraries/zkgroup/v${ZKGROUP_VERSION} /tmp/zkgroup-libraries
RUN ls -la /tmp/zkgroup-libraries/x86-64
@@ -74,6 +72,8 @@ RUN cd /tmp/signal-cli-rest-api-src && swag init && go build
# Start a fresh container for release container
FROM adoptopenjdk:11-jre-hotspot-bionic
ENV GIN_MODE=release
ENV PORT=8080
ARG SIGNAL_CLI_VERSION
@@ -100,4 +100,4 @@ EXPOSE ${PORT}
ENTRYPOINT ["/entrypoint.sh"]
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
CMD curl -f http://localhost:${PORT}/v1/about || exit 1
CMD curl -f http://localhost:${PORT}/v1/health || exit 1

View File

@@ -850,3 +850,13 @@ func (a *Api) UpdateProfile(c *gin.Context) {
cleanupTmpFiles(avatarTmpPaths)
c.Status(http.StatusNoContent)
}
// @Summary API Health Check
// @Tags General
// @Description Internally used by the docker container to perform the health check.
// @Produce json
// @Success 204 {string} OK
// @Router /v1/health [get]
func (a *Api) Health(c *gin.Context) {
c.Status(http.StatusNoContent)
}

View File

@@ -264,6 +264,26 @@ var doc = `{
}
}
},
"/v1/health": {
"get": {
"description": "Internally used by the docker container to perform the health check.",
"produces": [
"application/json"
],
"tags": [
"General"
],
"summary": "API Health Check",
"responses": {
"204": {
"description": "No Content",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/profiles/{number}": {
"put": {
"description": "Set your name and optional an avatar.",

View File

@@ -249,6 +249,26 @@
}
}
},
"/v1/health": {
"get": {
"description": "Internally used by the docker container to perform the health check.",
"produces": [
"application/json"
],
"tags": [
"General"
],
"summary": "API Health Check",
"responses": {
"204": {
"description": "No Content",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/profiles/{number}": {
"put": {
"description": "Set your name and optional an avatar.",

View File

@@ -244,6 +244,19 @@ paths:
summary: Delete a Signal Group.
tags:
- Groups
/v1/health:
get:
description: Internally used by the docker container to perform the health check.
produces:
- application/json
responses:
"204":
description: No Content
schema:
type: string
summary: API Health Check
tags:
- General
/v1/profiles/{number}:
put:
description: Set your name and optional an avatar.

View File

@@ -45,7 +45,13 @@ func main() {
avatarTmpDir := flag.String("avatar-tmp-dir", "/tmp/", "Avatar tmp directory")
flag.Parse()
router := gin.Default()
router := gin.New()
router.Use(gin.LoggerWithConfig(gin.LoggerConfig{
SkipPaths: []string{"/v1/health"}, //do not log the health requests (to avoid spamming the log file)
}))
router.Use(gin.Recovery())
log.Info("Started Signal Messenger REST API")
api := api.NewApi(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir)
@@ -56,6 +62,11 @@ func main() {
about.GET("", api.About)
}
health := v1.Group("/health")
{
health.GET("", api.Health)
}
register := v1.Group("/register")
{
register.POST(":number", api.RegisterNumber)