Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add healthz check #286

Merged
merged 2 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gorush/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func rootHandler(c *gin.Context) {
})
}

func heartbeatHandler(c *gin.Context) {
c.AbortWithStatus(200)
}

func pushHandler(c *gin.Context) {
var form RequestPush
var msg string
Expand Down Expand Up @@ -107,6 +111,7 @@ func routerEngine() *gin.Engine {
r.GET(PushConf.API.SysStatURI, sysStatsHandler)
r.POST(PushConf.API.PushURI, pushHandler)
r.GET(PushConf.API.MetricURI, metricsHandler)
r.GET("/healthz", heartbeatHandler)
r.GET("/", rootHandler)

return r
Expand Down
10 changes: 10 additions & 0 deletions gorush/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
initTest()
PushConf.Core.Enabled = false
Expand Down
6 changes: 6 additions & 0 deletions k8s/gorush-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ spec:
args: ["-c", "config.yml", "-e", "redis", "--redis-addr", "redis:6379"]
ports:
- containerPort: 8088
livenessProbe:
httpGet:
path: /healthz
port: 8088
initialDelaySeconds: 3
periodSeconds: 3
10 changes: 6 additions & 4 deletions k8s/gorush-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ metadata:
app: gorush
tier: frontend
spec:
selector:
app: gorush
tier: frontend
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
type: LoadBalancer
# type: NodePort
ports:
- port: 8088
selector:
app: gorush
tier: frontend
- protocol: TCP
port: 80
targetPort: 8088