diff --git a/pkg/promclient/promclient.go b/pkg/promclient/promclient.go index 44695a20ce8..f06e9ce54e0 100644 --- a/pkg/promclient/promclient.go +++ b/pkg/promclient/promclient.go @@ -105,7 +105,7 @@ func NewWithTracingClient(logger log.Logger, httpClient *http.Client, userAgent // req2xx sends a request to the given url.URL. If method is http.MethodPost then // the raw query is encoded in the body and the appropriate Content-Type is set. -func (c *Client) req2xx(ctx context.Context, u *url.URL, method string, headers map[string]string) (_ []byte, _ int, err error) { +func (c *Client) req2xx(ctx context.Context, u *url.URL, method string, headers http.Header) (_ []byte, _ int, err error) { var b io.Reader if method == http.MethodPost { rq := u.RawQuery @@ -117,6 +117,10 @@ func (c *Client) req2xx(ctx context.Context, u *url.URL, method string, headers if err != nil { return nil, 0, errors.Wrapf(err, "create %s request", method) } + if headers != nil { + req.Header = headers + } + if c.userAgent != "" { req.Header.Set("User-Agent", c.userAgent) } @@ -124,10 +128,6 @@ func (c *Client) req2xx(ctx context.Context, u *url.URL, method string, headers req.Header.Set("Content-Type", "application/x-www-form-urlencoded") } - for header, value := range headers { - req.Header.Set(header, value) - } - resp, err := c.Do(req.WithContext(ctx)) if err != nil { return nil, 0, errors.Wrapf(err, "perform %s request against %s", method, u.String()) @@ -367,7 +367,7 @@ type QueryOptions struct { MaxSourceResolution string Engine string Explain bool - HTTPHeaders map[string]string + HTTPHeaders http.Header } func (p *QueryOptions) AddTo(values url.Values) error { diff --git a/test/e2e/store_gateway_test.go b/test/e2e/store_gateway_test.go index 8e90fe0370e..e7ac78f67ed 100644 --- a/test/e2e/store_gateway_test.go +++ b/test/e2e/store_gateway_test.go @@ -136,10 +136,13 @@ metafile_content_ttl: 0s`, memcached.InternalEndpoint("memcached")) testutil.Ok(t, s1.WaitSumMetrics(e2emon.Equals(0), "thanos_bucket_store_block_load_failures_total")) t.Run("query works", func(t *testing.T) { + tenant1Header := make(http.Header) + tenant1Header.Add("thanos-tenant", "test-tenant-1") queryAndAssertSeries(t, ctx, q.Endpoint("http"), func() string { return fmt.Sprintf("%s @ end()", testQuery) }, time.Now, promclient.QueryOptions{ Deduplicate: false, - HTTPHeaders: map[string]string{"thanos-tenant": "test-tenant-1"}, + HTTPHeaders: tenant1Header, + // map[string][]string{"thanos-tenant": "test-tenant-1"}, }, []model.Metric{ { @@ -173,10 +176,12 @@ metafile_content_ttl: 0s`, memcached.InternalEndpoint("memcached")) testutil.Ok(t, s1.WaitSumMetricsWithOptions(e2emon.Equals(9), []string{"thanos_bucket_store_series_data_fetched"}, e2emon.WithLabelMatchers(matchers.MustNewMatcher(matchers.MatchEqual, tenancy.MetricLabel, "test-tenant-1")))) testutil.Ok(t, s1.WaitSumMetricsWithOptions(e2emon.Equals(3), []string{"thanos_bucket_store_series_blocks_queried"}, e2emon.WithLabelMatchers(matchers.MustNewMatcher(matchers.MatchEqual, tenancy.MetricLabel, "test-tenant-1")))) + tenant2Header := make(http.Header) + tenant2Header.Add("thanos-tenant", "test-tenant-2") queryAndAssertSeries(t, ctx, q.Endpoint("http"), func() string { return testQuery }, time.Now, promclient.QueryOptions{ Deduplicate: true, - HTTPHeaders: map[string]string{"thanos-tenant": "test-tenant-2"}, + HTTPHeaders: tenant2Header, }, []model.Metric{ {