(w http.ResponseWriter, r *http.Request)
| 326 | } |
| 327 | |
| 328 | func (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 | |
| 384 | func handleError(w http.ResponseWriter, err error) { |
| 385 | if err == nil { |
nothing calls this directly
no test coverage detected