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

Method doQuery

edgraph/server.go:1396–1564  ·  view source on GitHub ↗
(ctx context.Context, req *Request)

Source from the content-addressed store, hash-verified

1394}
1395
1396func (s *Server) doQuery(ctx context.Context, req *Request) (resp *api.Response, rerr error) {
1397 if ctx.Err() != nil {
1398 return nil, ctx.Err()
1399 }
1400 defer atomic.AddInt64(&pendingQueries, -1)
1401 if val := atomic.AddInt64(&pendingQueries, 1); val > maxPendingQueries {
1402 return nil, serverOverloadErr
1403 }
1404
1405 isGraphQL, _ := ctx.Value(IsGraphql).(bool)
1406 if isGraphQL {
1407 atomic.AddUint64(&numGraphQL, 1)
1408 } else {
1409 atomic.AddUint64(&numDQL, 1)
1410 }
1411 l := &query.Latency{}
1412 l.Start = time.Now()
1413
1414 isMutation := len(req.req.Mutations) > 0
1415 methodRequest := methodQuery
1416 if isMutation {
1417 methodRequest = methodMutate
1418 }
1419
1420 var measurements []ostats.Measurement
1421 ctx, span := otel.Tracer("").Start(ctx, methodRequest)
1422 if ns, err := x.ExtractNamespace(ctx); err == nil {
1423 annotateNamespace(span, ns)
1424 }
1425
1426 if bool(glog.V(3)) || worker.LogDQLRequestEnabled() {
1427 traceID := ""
1428 if span.SpanContext().IsValid() {
1429 traceID = fmt.Sprintf(" [trace_id=%s]", span.SpanContext().TraceID().String())
1430 }
1431 glog.Infof("Got a query, DQL form: %+v %+v at %+v%s",
1432 req.req.Query, req.req.Mutations, l.Start.Format(time.RFC3339), traceID)
1433 }
1434
1435 ctx = x.WithMethod(ctx, methodRequest)
1436 defer func() {
1437 span.End()
1438 v := x.TagValueStatusOK
1439 if rerr != nil {
1440 v = x.TagValueStatusError
1441 }
1442 ctx, _ = tag.New(ctx, tag.Upsert(x.KeyStatus, v))
1443 timeSpentMs := x.SinceMs(l.Start)
1444 measurements = append(measurements, x.LatencyMs.M(timeSpentMs))
1445 ostats.Record(ctx, measurements...)
1446
1447 // Log slow queries with structured fields for observability
1448 if x.WorkerConfig.SlowQueryLogThreshold > 0 {
1449 x.LogSlowOperation(ctx, "query", "dql", req.req.Query, &x.SlowOperationLatency{
1450 Start: l.Start,
1451 Parsing: l.Parsing,
1452 Processing: l.Processing,
1453 Encoding: l.Json,

Callers 11

QueryGraphQLMethod · 0.95
QueryNoGrpcMethod · 0.95
QueryNoAuthMethod · 0.95
RunDQLMethod · 0.80
ProcessPersistedQueryFunction · 0.80
InsertDropRecordFunction · 0.80
ResetPasswordMethod · 0.80
authorizeUserFunction · 0.80
refreshAclCacheFunction · 0.80
upsertGuardianFunction · 0.80
upsertGrootFunction · 0.80

Calls 15

doMutateMethod · 0.95
ExtractNamespaceFunction · 0.92
LogDQLRequestEnabledFunction · 0.92
WithMethodFunction · 0.92
SinceMsFunction · 0.92
LogSlowOperationFunction · 0.92
HealthCheckFunction · 0.92
IsRootNsOperationFunction · 0.92
IsGqlErrorListFunction · 0.92
annotateNamespaceFunction · 0.85
AuthSuperAdminFunction · 0.85
parseRequestFunction · 0.85

Tested by

no test coverage detected