MCPcopy
hub / github.com/dgraph-io/dgraph / healthCheck

Function healthCheck

dgraph/cmd/alpha/run.go:371–417  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

369}
370
371func healthCheck(w http.ResponseWriter, r *http.Request) {
372 x.AddCorsHeaders(w)
373 var err error
374
375 if _, ok := r.URL.Query()["all"]; ok {
376 w.Header().Set("Content-Type", "application/json")
377 w.WriteHeader(http.StatusOK)
378
379 ctx := x.AttachAccessJwt(context.Background(), r)
380 var resp *api.Response
381 if resp, err = (&edgraph.Server{}).Health(ctx, true); err != nil {
382 x.SetStatus(w, x.Error, err.Error())
383 return
384 }
385 if resp == nil {
386 x.SetStatus(w, x.ErrorNoData, "No health information available.")
387 return
388 }
389 _, _ = w.Write(resp.Json)
390 return
391 }
392
393 _, ok := r.URL.Query()["live"]
394 if !ok {
395 if err := x.HealthCheck(); err != nil {
396 w.WriteHeader(http.StatusServiceUnavailable)
397 _, err = w.Write([]byte(err.Error()))
398 if err != nil {
399 glog.V(2).Infof("Error while writing health check response: %v", err)
400 }
401 return
402 }
403 }
404
405 var resp *api.Response
406 if resp, err = (&edgraph.Server{}).Health(context.Background(), false); err != nil {
407 x.SetStatus(w, x.Error, err.Error())
408 return
409 }
410 if resp == nil {
411 x.SetStatus(w, x.ErrorNoData, "No health information available.")
412 return
413 }
414 w.Header().Set("Content-Type", "application/json")
415 w.WriteHeader(http.StatusOK)
416 _, _ = w.Write(resp.Json)
417}
418
419func stateHandler(w http.ResponseWriter, r *http.Request) {
420 var err error

Callers

nothing calls this directly

Calls 11

AddCorsHeadersFunction · 0.92
AttachAccessJwtFunction · 0.92
SetStatusFunction · 0.92
HealthCheckFunction · 0.92
HealthMethod · 0.80
InfofMethod · 0.80
SetMethod · 0.65
WriteHeaderMethod · 0.65
WriteMethod · 0.65
QueryMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected