From 063b5913779ce0d18f62c6b72642d2fe9e709554 Mon Sep 17 00:00:00 2001 From: cmyui Date: Sat, 11 Nov 2023 07:39:07 -0500 Subject: [PATCH] readiness probe --- app/start.go | 2 ++ app/v1/health.go | 32 ++++++++++++++++++++++++++++++++ chart/values.yaml | 9 +++++++++ 3 files changed, 43 insertions(+) create mode 100644 app/v1/health.go diff --git a/app/start.go b/app/start.go index b6e229e..871b710 100644 --- a/app/start.go +++ b/app/start.go @@ -65,6 +65,8 @@ func Start(dbO *sqlx.DB) *fhr.Router { // v1 API { + r.Method("_health", v1.HealthGET) + r.POSTMethod("/api/v1/tokens/self/delete", v1.TokenSelfDeletePOST) // Auth-free API endpoints (public data) diff --git a/app/v1/health.go b/app/v1/health.go new file mode 100644 index 0000000..7e29b34 --- /dev/null +++ b/app/v1/health.go @@ -0,0 +1,32 @@ +package v1 + +import ( + "github.com/osuAkatsuki/akatsuki-api/app/peppy" + "github.com/osuAkatsuki/akatsuki-api/common" +) + +type healthResponse struct { + common.ResponseBase +} + +func HealthGET(md common.MethodData) common.CodeMessager { + var r healthResponse + + err := peppy.R.Ping().Err() + if err != nil { + r.Code = 500 + r.Message = "redis error" + return r + } + + err = md.DB.Ping() + if err != nil { + r.Code = 500 + r.Message = "database error" + return r + } + + r.Code = 200 + r.Message = "healthy" + return r +} diff --git a/chart/values.yaml b/chart/values.yaml index 9dc50e5..3dac094 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -11,6 +11,15 @@ apps: env: - name: APP_COMPONENT value: api + readinessProbe: + httpGet: + path: /_health + port: 80 + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 1 + successThreshold: 1 + failureThreshold: 3 resources: limits: cpu: 500m