Skip to content

Commit

Permalink
Support sending custom headers to remote write server
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLindvall authored and jacksontj committed Nov 7, 2024
1 parent 127fb5b commit 0e50acb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ type Client struct {
url *config_util.URL
client *http.Client
timeout time.Duration
headers map[string]string
}

// ClientConfig configures a Client.
type ClientConfig struct {
URL *config_util.URL
Timeout model.Duration
HTTPClientConfig config_util.HTTPClientConfig
Headers map[string]string
}

// NewClient creates a new Client.
Expand Down Expand Up @@ -87,6 +89,9 @@ func (c *Client) Store(ctx context.Context, req *prompb.WriteRequest) error {
httpReq.Header.Set("Content-Type", "application/x-protobuf")
httpReq.Header.Set("User-Agent", userAgent)
httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
for headerKey, headerValue := range c.headers {
httpReq.Header.Set(headerKey, headerValue)
}
httpReq = httpReq.WithContext(ctx)

ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
Expand Down
1 change: 1 addition & 0 deletions pkg/remote/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (s *Storage) ApplyConfig(conf *config.Config) error {
URL: rwConf.URL,
Timeout: rwConf.RemoteTimeout,
HTTPClientConfig: rwConf.HTTPClientConfig,
Headers: rwConf.Headers,
})
if err != nil {
return err
Expand Down

0 comments on commit 0e50acb

Please sign in to comment.