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

Method searchHTTP

cmd/tempo-cli/cmd-query-search.go:106–150  ·  view source on GitHub ↗

nolint: goconst // goconst wants us to make http:// a const

(req *tempopb.SearchRequest)

Source from the content-addressed store, hash-verified

104
105// nolint: goconst // goconst wants us to make http:// a const
106func (cmd *querySearchCmd) searchHTTP(req *tempopb.SearchRequest) error {
107 httpReq, err := http.NewRequest("GET", httpScheme(cmd.Secure)+"://"+path.Join(cmd.HostPort, cmd.PathPrefix, api.PathSearch), nil)
108 if err != nil {
109 return err
110 }
111
112 httpReq, err = api.BuildSearchRequest(httpReq, req)
113 if err != nil {
114 return err
115 }
116
117 httpReq.Header = http.Header{}
118 err = user.InjectOrgIDIntoHTTPRequest(user.InjectOrgID(context.Background(), cmd.OrgID), httpReq)
119 if err != nil {
120 return err
121 }
122 applyHeadersHTTP(httpReq, cmd.Headers)
123
124 httpResp, err := http.DefaultClient.Do(httpReq)
125 if err != nil {
126 return err
127 }
128 defer httpResp.Body.Close()
129
130 body, err := io.ReadAll(httpResp.Body)
131 if err != nil {
132 return err
133 }
134
135 if httpResp.StatusCode != http.StatusOK {
136 return errors.New("failed to query. body: " + string(body) + " status: " + httpResp.Status)
137 }
138
139 resp := &tempopb.SearchResponse{}
140 err = jsonpb.Unmarshal(bytes.NewReader(body), resp)
141 if err != nil {
142 panic("failed to parse resp: " + err.Error())
143 }
144 err = printAsJSON(resp)
145 if err != nil {
146 return err
147 }
148
149 return nil
150}

Callers 1

RunMethod · 0.95

Calls 10

BuildSearchRequestFunction · 0.92
httpSchemeFunction · 0.85
applyHeadersHTTPFunction · 0.85
printAsJSONFunction · 0.85
JoinMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ReadAllMethod · 0.65
UnmarshalMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected