From 0f754bea490b425be531704522fe4ceec7125948 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 1 Jul 2020 02:19:58 +0300 Subject: [PATCH] lib/promscrape: add `-promscrape.disableKeepAlive` command-line flag for disabling http keep-alive connections when scraping targets Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/580 --- lib/promscrape/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index 8642e57a9..cf1b227db 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -16,6 +16,8 @@ var ( "Bigger responses are rejected") disableCompression = flag.Bool("promscrape.disableCompression", false, "Whether to disable sending 'Accept-Encoding: gzip' request headers to scrape targets. "+ "This may reduce CPU usage on scrape targets at the cost of higher network bandwidth utilization") + disableKeepAlive = flag.Bool("promscrape.disableKeepAlive", false, "Whether to disable HTTP keep-alive connections when scraping targets. This may be useful when targets "+ + "has no support for HTTP keep-alive connection. Note that disabling HTTP keep-alive may increase load on both vmagent and scrape targets") ) type client struct { @@ -73,6 +75,9 @@ func (c *client) ReadData(dst []byte) ([]byte, error) { if !*disableCompression { req.Header.Set("Accept-Encoding", "gzip") } + if *disableKeepAlive { + req.SetConnectionClose() + } if c.authHeader != "" { req.Header.Set("Authorization", c.authHeader) }