add healthz check (#286)
* add healthz check Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * add testing Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
f0ca319da5
commit
ffd55152e5
|
@ -32,6 +32,10 @@ func rootHandler(c *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func heartbeatHandler(c *gin.Context) {
|
||||||
|
c.AbortWithStatus(200)
|
||||||
|
}
|
||||||
|
|
||||||
func pushHandler(c *gin.Context) {
|
func pushHandler(c *gin.Context) {
|
||||||
var form RequestPush
|
var form RequestPush
|
||||||
var msg string
|
var msg string
|
||||||
|
@ -107,6 +111,7 @@ func routerEngine() *gin.Engine {
|
||||||
r.GET(PushConf.API.SysStatURI, sysStatsHandler)
|
r.GET(PushConf.API.SysStatURI, sysStatsHandler)
|
||||||
r.POST(PushConf.API.PushURI, pushHandler)
|
r.POST(PushConf.API.PushURI, pushHandler)
|
||||||
r.GET(PushConf.API.MetricURI, metricsHandler)
|
r.GET(PushConf.API.MetricURI, metricsHandler)
|
||||||
|
r.GET("/healthz", heartbeatHandler)
|
||||||
r.GET("/", rootHandler)
|
r.GET("/", rootHandler)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -258,6 +258,16 @@ func TestMetricsHandler(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHeartbeatHandler(t *testing.T) {
|
||||||
|
initTest()
|
||||||
|
|
||||||
|
r := gofight.New()
|
||||||
|
|
||||||
|
r.GET("/healthz").
|
||||||
|
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
||||||
|
assert.Equal(t, http.StatusOK, r.Code)
|
||||||
|
})
|
||||||
|
}
|
||||||
func TestDisabledHTTPServer(t *testing.T) {
|
func TestDisabledHTTPServer(t *testing.T) {
|
||||||
initTest()
|
initTest()
|
||||||
PushConf.Core.Enabled = false
|
PushConf.Core.Enabled = false
|
||||||
|
|
|
@ -19,3 +19,9 @@ spec:
|
||||||
args: ["-c", "config.yml", "-e", "redis", "--redis-addr", "redis:6379"]
|
args: ["-c", "config.yml", "-e", "redis", "--redis-addr", "redis:6379"]
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8088
|
- containerPort: 8088
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /healthz
|
||||||
|
port: 8088
|
||||||
|
initialDelaySeconds: 3
|
||||||
|
periodSeconds: 3
|
||||||
|
|
|
@ -7,12 +7,14 @@ metadata:
|
||||||
app: gorush
|
app: gorush
|
||||||
tier: frontend
|
tier: frontend
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
app: gorush
|
||||||
|
tier: frontend
|
||||||
# if your cluster supports it, uncomment the following to automatically create
|
# if your cluster supports it, uncomment the following to automatically create
|
||||||
# an external load-balanced IP for the frontend service.
|
# an external load-balanced IP for the frontend service.
|
||||||
type: LoadBalancer
|
type: LoadBalancer
|
||||||
# type: NodePort
|
# type: NodePort
|
||||||
ports:
|
ports:
|
||||||
- port: 8088
|
- protocol: TCP
|
||||||
selector:
|
port: 80
|
||||||
app: gorush
|
targetPort: 8088
|
||||||
tier: frontend
|
|
||||||
|
|
Loading…
Reference in New Issue