From 9d495afd2c031709baffbfb3f619bad8167023ab Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 18 Jun 2021 09:38:12 +0200 Subject: [PATCH] Remove trailing zeros in scrape timeout header See https://twitter.com/AviKivity/status/1405147699557638145 and https://twitter.com/juliusvolz/status/1405790211670515712 Signed-off-by: Julius Volz --- scrape/scrape.go | 3 ++- scrape/scrape_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scrape/scrape.go b/scrape/scrape.go index 215c63c04..d9ed8a02b 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -24,6 +24,7 @@ import ( "math" "net/http" "reflect" + "strconv" "sync" "time" "unsafe" @@ -718,7 +719,7 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) (string, error) 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())) + req.Header.Set("X-Prometheus-Scrape-Timeout-Seconds", strconv.FormatFloat(s.timeout.Seconds(), 'f', -1, 64)) s.req = req } diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index 5848c5cb1..56109d4e2 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -1825,7 +1825,7 @@ func TestScrapeLoopOutOfBoundsTimeError(t *testing.T) { func TestTargetScraperScrapeOK(t *testing.T) { const ( configTimeout = 1500 * time.Millisecond - expectedTimeout = "1.500000" + expectedTimeout = "1.5" ) server := httptest.NewServer(