MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / graphqlProbeHandler

Function graphqlProbeHandler

dgraph/cmd/alpha/http.go:702–729  ·  view source on GitHub ↗
(gqlHealthStore *admin.GraphQLHealthStore, globalEpoch map[uint64]*uint64)

Source from the content-addressed store, hash-verified

700}
701
702func graphqlProbeHandler(gqlHealthStore *admin.GraphQLHealthStore, globalEpoch map[uint64]*uint64) http.Handler {
703 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
704 x.AddCorsHeaders(w)
705 w.Header().Set("Content-Type", "application/json")
706 // lazy load the schema so that just by making a probe request,
707 // one can boot up GraphQL for their namespace
708 namespace := x.ExtractNamespaceHTTP(r)
709 if err := admin.LazyLoadSchema(namespace); err != nil {
710 w.WriteHeader(http.StatusInternalServerError)
711 x.Check2(w.Write([]byte(fmt.Sprintf(`{"error":"%s"}`, err))))
712 return
713 }
714
715 healthStatus := gqlHealthStore.GetHealth()
716 httpStatusCode := http.StatusOK
717 if !healthStatus.Healthy {
718 httpStatusCode = http.StatusServiceUnavailable
719 }
720 w.WriteHeader(httpStatusCode)
721 e := globalEpoch[namespace]
722 var counter uint64
723 if e != nil {
724 counter = atomic.LoadUint64(e)
725 }
726 x.Check2(w.Write([]byte(fmt.Sprintf(`{"status":"%s","schemaUpdateCounter":%d}`,
727 healthStatus.StatusMsg, counter))))
728 })
729}
730
731func resolveWithAdminServer(gqlReq *schema.Request, r *http.Request,
732 adminServer admin.IServeGraphQL) *schema.Response {

Callers 1

setupServerFunction · 0.85

Calls 8

AddCorsHeadersFunction · 0.92
ExtractNamespaceHTTPFunction · 0.92
LazyLoadSchemaFunction · 0.92
Check2Function · 0.92
GetHealthMethod · 0.80
SetMethod · 0.65
WriteHeaderMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…