lib/promscrape/client: make User-Agent consistent between fasthttp and native client (#4886)

User agent was not set for native client which resulted in using one provided by Golang.

See: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4884

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
(cherry picked from commit 6788704152)
This commit is contained in:
Zakhar Bessarab 2023-08-24 13:31:13 +04:00 committed by hagen1778
parent 33bf28e1bd
commit 1242460fa6
No known key found for this signature in database
GPG key ID: 3BF75F3741CA9640

View file

@ -201,6 +201,8 @@ func (c *client) GetStreamReader() (*streamReader, error) {
// Set X-Prometheus-Scrape-Timeout-Seconds like Prometheus does, since it is used by some exporters such as PushProx. // Set X-Prometheus-Scrape-Timeout-Seconds like Prometheus does, since it is used by some exporters such as PushProx.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1179#issuecomment-813117162 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1179#issuecomment-813117162
req.Header.Set("X-Prometheus-Scrape-Timeout-Seconds", c.scrapeTimeoutSecondsStr) req.Header.Set("X-Prometheus-Scrape-Timeout-Seconds", c.scrapeTimeoutSecondsStr)
// Set same useragent as fasthttp.HostClient at c.hc uses for scraping
req.Header.Set("User-Agent", "vm_promscrape")
c.setHeaders(req) c.setHeaders(req)
c.setProxyHeaders(req) c.setProxyHeaders(req)
scrapeRequests.Inc() scrapeRequests.Inc()