BuildQueryRangeRequest takes a tempopb.QueryRangeRequest and populates the passed http.Request dedicatedColumnsJSON should be generated using the DedicatedColumnsToJSON struct which produces the expected string value and memoizes results to prevent redundant marshaling.
(req *http.Request, searchReq *tempopb.QueryRangeRequest, dedicatedColumnsJSON string)
| 433 | // dedicatedColumnsJSON should be generated using the DedicatedColumnsToJSON struct which produces the expected string |
| 434 | // value and memoizes results to prevent redundant marshaling. |
| 435 | func BuildQueryRangeRequest(req *http.Request, searchReq *tempopb.QueryRangeRequest, dedicatedColumnsJSON string) *http.Request { |
| 436 | if req == nil { |
| 437 | req = &http.Request{ |
| 438 | URL: &url.URL{}, |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | if searchReq == nil { |
| 443 | return req |
| 444 | } |
| 445 | |
| 446 | qb := newQueryBuilder("") |
| 447 | if searchReq.Start != 0 { |
| 448 | qb.addParam(urlParamStart, strconv.FormatUint(searchReq.Start, 10)) |
| 449 | } |
| 450 | if searchReq.End != 0 { |
| 451 | qb.addParam(urlParamEnd, strconv.FormatUint(searchReq.End, 10)) |
| 452 | } |
| 453 | if searchReq.Step != 0 { // if step != 0 leave the param out and Tempo will calculate it |
| 454 | qb.addParam(urlParamStep, time.Duration(searchReq.Step).String()) |
| 455 | } |
| 456 | qb.addParam(QueryModeKey, searchReq.QueryMode) |
| 457 | // New RF1 params |
| 458 | qb.addParam(urlParamBlockID, searchReq.BlockID) |
| 459 | qb.addParam(urlParamStartPage, strconv.Itoa(int(searchReq.StartPage))) |
| 460 | qb.addParam(urlParamPagesToSearch, strconv.Itoa(int(searchReq.PagesToSearch))) |
| 461 | qb.addParam(urlParamVersion, searchReq.Version) |
| 462 | qb.addParam("encoding", "none") |
| 463 | qb.addParam(urlParamSize, strconv.Itoa(int(searchReq.Size_))) |
| 464 | qb.addParam(urlParamFooterSize, strconv.Itoa(int(searchReq.FooterSize))) |
| 465 | |
| 466 | if len(dedicatedColumnsJSON) > 0 && dedicatedColumnsJSON != "null" { // if a caller marshals a nil dedicated cols we will receive the string "null" |
| 467 | qb.addParam(urlParamDedicatedColumns, dedicatedColumnsJSON) |
| 468 | } |
| 469 | |
| 470 | if len(searchReq.Query) > 0 { |
| 471 | qb.addParam(urlParamQuery, searchReq.Query) |
| 472 | } |
| 473 | |
| 474 | qb.addParam(urlParamExemplars, strconv.FormatUint(uint64(searchReq.Exemplars), 10)) |
| 475 | qb.addParam(urlMaxSeries, strconv.Itoa(int(searchReq.MaxSeries))) |
| 476 | if searchReq.HasInstant() { |
| 477 | qb.addParam(urlInstant, strconv.FormatBool(searchReq.GetInstant())) |
| 478 | } |
| 479 | |
| 480 | if len(searchReq.SkipASTTransformations) > 0 { |
| 481 | qb.addParam(urlParamSkipASTTransformations, strings.Join(searchReq.SkipASTTransformations, ",")) |
| 482 | } |
| 483 | |
| 484 | req.URL.RawQuery = qb.query() |
| 485 | |
| 486 | return req |
| 487 | } |
| 488 | |
| 489 | // Generic helper to append query parameters to an http request with less allocations |
| 490 | func BuildQueryRequest(req *http.Request, queryParams map[string]string) *http.Request { |