| 131 | } |
| 132 | |
| 133 | func 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. |
| 167 | type ConfigsResponse struct { |