| 629 | } |
| 630 | |
| 631 | func (c *Client) query(addr string, headers map[string]string) (*http.Response, []byte, error) { |
| 632 | ctx, cancel := context.WithTimeout(context.Background(), c.timeout) |
| 633 | defer cancel() |
| 634 | |
| 635 | req, err := http.NewRequestWithContext(ctx, "GET", addr, nil) |
| 636 | if err != nil { |
| 637 | return nil, nil, err |
| 638 | } |
| 639 | |
| 640 | req.Header.Set("X-Scope-OrgID", c.orgID) |
| 641 | |
| 642 | for key, value := range headers { |
| 643 | req.Header.Set(key, value) |
| 644 | } |
| 645 | |
| 646 | retries := backoff.New(ctx, backoff.Config{ |
| 647 | MinBackoff: 1 * time.Second, |
| 648 | MaxBackoff: 2 * time.Second, |
| 649 | MaxRetries: 10, |
| 650 | }) |
| 651 | var ( |
| 652 | res *http.Response |
| 653 | ) |
| 654 | for retries.Ongoing() { |
| 655 | res, err = c.httpClient.Do(req) |
| 656 | if err == nil { |
| 657 | break |
| 658 | } |
| 659 | retries.Wait() |
| 660 | } |
| 661 | if err != nil { |
| 662 | return nil, nil, err |
| 663 | } |
| 664 | defer res.Body.Close() |
| 665 | |
| 666 | body, err := io.ReadAll(res.Body) |
| 667 | if err != nil { |
| 668 | return nil, nil, err |
| 669 | } |
| 670 | return res, body, nil |
| 671 | } |
| 672 | |
| 673 | // Series finds series by label matchers. |
| 674 | func (c *Client) Series(matches []string, start, end time.Time) ([]model.LabelSet, error) { |