MCPcopy
hub / github.com/grafana/tempo / QueryRangeHandler

Method QueryRangeHandler

modules/querier/http.go:328–382  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

326}
327
328func (q *Querier) QueryRangeHandler(w http.ResponseWriter, r *http.Request) {
329 var (
330 err error
331 resp *tempopb.QueryRangeResponse
332 )
333
334 // Enforce the query timeout while querying backends
335 ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(q.cfg.Search.QueryTimeout))
336 defer cancel()
337
338 ctx, span := tracer.Start(ctx, "Querier.QueryRangeHandler")
339 defer span.End()
340
341 // Special error handling to update the span.
342 defer func() {
343 if errors.Is(err, context.Canceled) {
344 // todo: context is also canceled when we hit the query timeout. research what the behavior is
345 // ignore this error. we regularly cancel context once queries are complete
346 span.RecordError(err)
347 return
348 }
349
350 if ctx.Err() != nil {
351 span.RecordError(ctx.Err())
352 return
353 }
354
355 if err != nil {
356 span.RecordError(err)
357 }
358 }()
359
360 req, err := api.ParseQueryRangeRequest(r)
361 if err != nil {
362 http.Error(w, err.Error(), http.StatusBadRequest)
363 return
364 }
365
366 span.SetAttributes(attribute.String("query", req.Query))
367 span.SetAttributes(attribute.Int64("step", time.Duration(req.Step).Nanoseconds()))
368 span.SetAttributes(attribute.Int64("interval", time.Unix(0, int64(req.End)).Sub(time.Unix(0, int64(req.Start))).Nanoseconds()))
369
370 resp, err = q.QueryRange(ctx, req)
371 if err != nil {
372 handleError(w, err)
373 return
374 }
375
376 if resp != nil && resp.Metrics != nil {
377 span.SetAttributes(attribute.Int64("inspectedBytes", int64(resp.Metrics.InspectedBytes)))
378 span.SetAttributes(attribute.Int64("inspectedSpans", int64(resp.Metrics.InspectedSpans)))
379 }
380
381 writeFormattedContentForRequest(w, r, resp, span)
382}
383
384func handleError(w http.ResponseWriter, err error) {
385 if err == nil {

Callers

nothing calls this directly

Calls 11

QueryRangeMethod · 0.95
ParseQueryRangeRequestFunction · 0.92
handleErrorFunction · 0.85
DurationMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65
StartMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected