BuildSearchBlockRequest takes a tempopb.SearchBlockRequest and populates the passed http.Request with the appropriate params. If no http.Request is provided a new one is created. dedicatedColumnsJSON should be generated using the DedicatedColumnsToJSON struct which produces the expected string value
(req *http.Request, searchReq *tempopb.SearchBlockRequest, dedicatedColumnsJSON string)
| 735 | // dedicatedColumnsJSON should be generated using the DedicatedColumnsToJSON struct which produces the expected string |
| 736 | // value and memoizes results to prevent redundant marshaling. |
| 737 | func BuildSearchBlockRequest(req *http.Request, searchReq *tempopb.SearchBlockRequest, dedicatedColumnsJSON string) (*http.Request, error) { |
| 738 | if req == nil { |
| 739 | req = &http.Request{ |
| 740 | URL: &url.URL{}, |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | req, err := BuildSearchRequest(req, searchReq.SearchReq) |
| 745 | if err != nil { |
| 746 | return nil, err |
| 747 | } |
| 748 | |
| 749 | qb := newQueryBuilder(req.URL.RawQuery) |
| 750 | qb.addParam(urlParamBlockID, searchReq.BlockID) |
| 751 | qb.addParam(urlParamPagesToSearch, strconv.FormatUint(uint64(searchReq.PagesToSearch), 10)) |
| 752 | qb.addParam(urlParamSize, strconv.FormatUint(searchReq.Size_, 10)) |
| 753 | qb.addParam(urlParamStartPage, strconv.FormatUint(uint64(searchReq.StartPage), 10)) |
| 754 | qb.addParam("encoding", "none") // todo: remove. encoding was removed b/c its unused but we still add it here to make rollouts seamless |
| 755 | qb.addParam(urlParamIndexPageSize, strconv.FormatUint(uint64(searchReq.IndexPageSize), 10)) |
| 756 | qb.addParam(urlParamTotalRecords, strconv.FormatUint(uint64(searchReq.TotalRecords), 10)) |
| 757 | qb.addParam(urlParamVersion, searchReq.Version) |
| 758 | qb.addParam(urlParamFooterSize, strconv.FormatUint(uint64(searchReq.FooterSize), 10)) |
| 759 | if len(dedicatedColumnsJSON) > 0 && dedicatedColumnsJSON != "null" { // if a caller marshals a nil dedicated cols we will receive the string "null" |
| 760 | qb.addParam(urlParamDedicatedColumns, dedicatedColumnsJSON) |
| 761 | } |
| 762 | |
| 763 | req.URL.RawQuery = qb.query() |
| 764 | |
| 765 | return req, nil |
| 766 | } |
| 767 | |
| 768 | func extractQueryParam(v url.Values, param string) (string, bool) { |
| 769 | value := v.Get(param) |