Skip to content

Commit

Permalink
contrib: update k8s liveness and readiness probes (#4405)
Browse files Browse the repository at this point in the history
* Fix liveness probe for dgraph alpha.
* Add liveness probe to dgraph zero.
* Update k8s manifests to include both liveness and readiness probes.


(cherry picked from commit ed072d0)
  • Loading branch information
Deepesh Pathak authored and danielmai committed Jan 12, 2020
1 parent 8fe6267 commit 6323029
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
36 changes: 36 additions & 0 deletions contrib/config/kubernetes/dgraph-ha/dgraph-ha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ spec:
else
exec dgraph zero --my=$(hostname -f):5080 --peer dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080 --idx $idx --replicas 3
fi
livenessProbe:
httpGet:
path: /health
port: 6080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
httpGet:
path: /state
port: 6080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
terminationGracePeriodSeconds: 60
volumes:
- name: datadir
Expand Down Expand Up @@ -286,6 +304,24 @@ spec:
- |
set -ex
dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080
livenessProbe:
httpGet:
path: /health?live=1
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
terminationGracePeriodSeconds: 600
volumes:
- name: datadir
Expand Down
4 changes: 2 additions & 2 deletions contrib/config/kubernetes/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ zero:
livenessProbe:
enabled: false
port: 6080
path: /state
path: /health
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
Expand Down Expand Up @@ -215,7 +215,7 @@ alpha:
livenessProbe:
enabled: false
port: 8080
path: /health
path: /health?live=1
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
Expand Down
16 changes: 10 additions & 6 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,17 @@ func grpcPort() int {

func healthCheck(w http.ResponseWriter, r *http.Request) {
x.AddCorsHeaders(w)
if err := x.HealthCheck(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
_, err = w.Write([]byte(err.Error()))
if err != nil {
glog.V(2).Infof("Error while writing health check response: %v", err)

_, ok := r.URL.Query()["live"]
if !ok {
if err := x.HealthCheck(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
_, err = w.Write([]byte(err.Error()))
if err != nil {
glog.V(2).Infof("Error while writing health check response: %v", err)
}
return
}
return
}

info := struct {
Expand Down
7 changes: 7 additions & 0 deletions dgraph/cmd/zero/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ func (st *state) getState(w http.ResponseWriter, r *http.Request) {
}
}

func (st *state) pingResponse(w http.ResponseWriter, r *http.Request) {
x.AddCorsHeaders(w)

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK"))
}

func (st *state) serveHTTP(l net.Listener) {
srv := &http.Server{
ReadTimeout: 10 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func run() {
st.serveGRPC(grpcListener, store)
st.serveHTTP(httpListener)

http.HandleFunc("/health", st.pingResponse)
http.HandleFunc("/state", st.getState)
http.HandleFunc("/removeNode", st.removeNode)
http.HandleFunc("/moveTablet", st.moveTablet)
Expand Down

0 comments on commit 6323029

Please sign in to comment.