Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(inputs.prometheus): add support for Custom header #12050

Merged
merged 14 commits into from
Nov 21, 2022
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion plugins/inputs/prometheus/prometheus.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
"strings"
"sync"
"time"

"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"

@@ -57,6 +57,8 @@ type Prometheus struct {
// Basic authentication credentials
Username string `toml:"username"`
Password string `toml:"password"`

HTTPHeaders map[string]string `toml:"http_headers"`

ResponseTimeout config.Duration `toml:"response_timeout"`

@@ -296,6 +298,12 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
req.Header.Set("Authorization", "Bearer "+p.BearerTokenString)
} else if p.Username != "" || p.Password != "" {
req.SetBasicAuth(p.Username, p.Password)
}

if p.HTTPHeaders != nil {
for key, value := range p.HTTPHeaders {
req.Header.Add(key, value)
}
}

var resp *http.Response
4 changes: 4 additions & 0 deletions plugins/inputs/prometheus/sample.conf
Original file line number Diff line number Diff line change
@@ -81,6 +81,10 @@
# username = ""
# password = ""

## Add custom headers to the HTTP request
# http_headers = [{"header1", "value1" },{ "header2", "value2" }]


## Specify timeout duration for slower prometheus clients (default is 3s)
# response_timeout = "3s"