Skip to content

Commit

Permalink
feat(xPrometheus): added header
Browse files Browse the repository at this point in the history
  • Loading branch information
paologallinaharbur committed Feb 19, 2024
1 parent b424bc1 commit f3a829d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions configs/nri-prometheus-config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ integrations:
audit: false

# The HTTP client timeout when fetching data from endpoints. Defaults to "5s" if it is not set.
# This timeout in seconds is passed as well as a X-Prometheus-Scrape-Timeout-Seconds header to the exporters
# scrape_timeout: "5s"

# Length in time to distribute the scraping from the endpoints. Default to "30s" if it is not set.
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func ResetTargetSize() {
}

const (
// XPrometheusHeader included in all requests. It informs exporters about its timeout.
XPrometheusHeader = "X-Prometheus-Scrape-Timeout-Seconds"
// XPrometheusScrapeTimeoutHeader included in all requests. It informs exporters about its timeout.
XPrometheusScrapeTimeoutHeader = "X-Prometheus-Scrape-Timeout-Seconds"
// AcceptHeader included in all requests
AcceptHeader = "Accept"
)
Expand All @@ -52,7 +52,7 @@ func Get(client HTTPDoer, url string, acceptHeader string, fetchTimeout string)
}

req.Header.Add(AcceptHeader, acceptHeader)
req.Header.Add(XPrometheusHeader, fetchTimeout)
req.Header.Add(XPrometheusScrapeTimeoutHeader, fetchTimeout)

resp, err := client.Do(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestGetHeader(t *testing.T) {
t.Errorf("Expected Accept header %s, got %q", testHeader, accept)
}

xPrometheus := r.Header.Get(prometheus.XPrometheusHeader)
xPrometheus := r.Header.Get(prometheus.XPrometheusScrapeTimeoutHeader)
if xPrometheus != fetchTimeout {
t.Errorf("Expected xPrometheus header %s, got %q", xPrometheus, fetchTimeout)
}
Expand Down

0 comments on commit f3a829d

Please sign in to comment.