mirror of
https://github.com/prometheus/prometheus
synced 2024-12-24 23:42:32 +00:00
Send a HTTP Accept header when scraping
This commit is contained in:
parent
64c7932e85
commit
40c278ee2d
@ -397,7 +397,7 @@ type targetScraper struct {
|
||||
buf *bufio.Reader
|
||||
}
|
||||
|
||||
const acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3,*/*;q=0.1`
|
||||
const acceptHeader = `text/plain;version=0.0.4;q=1,*/*;q=0.1`
|
||||
|
||||
var userAgentHeader = fmt.Sprintf("Prometheus/%s", version.Version)
|
||||
|
||||
@ -407,8 +407,7 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Disable accept header to always negotiate for text format.
|
||||
// req.Header.Add("Accept", acceptHeader)
|
||||
req.Header.Add("Accept", acceptHeader)
|
||||
req.Header.Add("Accept-Encoding", "gzip")
|
||||
req.Header.Set("User-Agent", userAgentHeader)
|
||||
req.Header.Set("X-Prometheus-Scrape-Timeout-Seconds", fmt.Sprintf("%f", s.timeout.Seconds()))
|
||||
|
@ -895,11 +895,14 @@ func TestTargetScraperScrapeOK(t *testing.T) {
|
||||
|
||||
server := httptest.NewServer(
|
||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
accept := r.Header.Get("Accept")
|
||||
if !strings.HasPrefix(accept, "text/plain;") {
|
||||
t.Errorf("Expected Accept header to prefer text/plain, got %q", accept)
|
||||
}
|
||||
|
||||
timeout := r.Header.Get("X-Prometheus-Scrape-Timeout-Seconds")
|
||||
if timeout != expectedTimeout {
|
||||
t.Errorf("Scrape timeout did not match expected timeout")
|
||||
t.Errorf("Expected: %v", expectedTimeout)
|
||||
t.Fatalf("Got: %v", timeout)
|
||||
t.Errorf("Expected scrape timeout header %q, got %q", expectedTimeout, timeout)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", `text/plain; version=0.0.4`)
|
||||
|
Loading…
Reference in New Issue
Block a user