MCPcopy Create free account
hub / github.com/cortexproject/cortex / doRequest

Function doRequest

pkg/configs/client/client.go:133–164  ·  view source on GitHub ↗
(endpoint string, timeout time.Duration, tlsConfig *tls.Config, since userconfig.ID)

Source from the content-addressed store, hash-verified

131}
132
133func doRequest(endpoint string, timeout time.Duration, tlsConfig *tls.Config, since userconfig.ID) (*ConfigsResponse, error) {
134 req, err := http.NewRequest("GET", endpoint, nil)
135 if err != nil {
136 return nil, err
137 }
138
139 client := &http.Client{Timeout: timeout}
140 if tlsConfig != nil {
141 client.Transport = &http.Transport{TLSClientConfig: tlsConfig}
142 }
143
144 req.Header.Set("User-Agent", fmt.Sprintf("Cortex/%s", version.Version))
145
146 resp, err := client.Do(req)
147 if err != nil {
148 return nil, err
149 }
150 defer resp.Body.Close()
151
152 if resp.StatusCode != http.StatusOK {
153 return nil, fmt.Errorf("invalid response from configs server: %v", resp.StatusCode)
154 }
155
156 var config ConfigsResponse
157 if err := json.NewDecoder(resp.Body).Decode(&config); err != nil {
158 level.Error(util_log.Logger).Log("msg", "configs: couldn't decode JSON body", "err", err)
159 return nil, err
160 }
161
162 config.since = since
163 return &config, nil
164}
165
166// ConfigsResponse is a response from server for Getuserconfig.
167type ConfigsResponse struct {

Callers 3

TestDoRequestFunction · 0.85
GetRulesMethod · 0.85
GetAlertsMethod · 0.85

Calls 6

SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
DecodeMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestDoRequestFunction · 0.68