mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Changes based on review comments
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
This commit is contained in:
parent
95f1ee61cf
commit
7b40203302
|
@ -88,9 +88,8 @@ func init() {
|
||||||
|
|
||||||
// Client allows reading and writing from/to a remote HTTP endpoint.
|
// Client allows reading and writing from/to a remote HTTP endpoint.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
remoteName string // Used to differentiate clients in metrics.
|
remoteName string // Used to differentiate clients in metrics.
|
||||||
urlString string // url.String()
|
urlString string // url.String()
|
||||||
rwFormat config.RemoteWriteFormat // For write clients, ignored for read clients.
|
|
||||||
lastRWHeader string
|
lastRWHeader string
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
@ -173,7 +172,6 @@ func NewWriteClient(name string, conf *ClientConfig) (WriteClient, error) {
|
||||||
httpClient.Transport = otelhttp.NewTransport(t)
|
httpClient.Transport = otelhttp.NewTransport(t)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
rwFormat: conf.RemoteWriteFormat,
|
|
||||||
remoteName: name,
|
remoteName: name,
|
||||||
urlString: conf.URL.String(),
|
urlString: conf.URL.String(),
|
||||||
Client: httpClient,
|
Client: httpClient,
|
||||||
|
@ -206,17 +204,14 @@ type RecoverableError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt a HEAD request against a remote write endpoint to see what it supports.
|
// Attempt a HEAD request against a remote write endpoint to see what it supports.
|
||||||
func (c *Client) GetProtoVersions(ctx context.Context) (string, error) {
|
func (c *Client) probeRemoteVersions(ctx context.Context) error {
|
||||||
// If we are in Version1 mode then don't even bother
|
// We assume we are in Version2 mode otherwise we shouldn't be calling this
|
||||||
if c.rwFormat == Version1 {
|
|
||||||
return RemoteWriteVersion1HeaderValue, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("HEAD", c.urlString, nil)
|
httpReq, err := http.NewRequest("HEAD", c.urlString, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Errors from NewRequest are from unparsable URLs, so are not
|
// Errors from NewRequest are from unparsable URLs, so are not
|
||||||
// recoverable.
|
// recoverable.
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the version header to be nice
|
// Set the version header to be nice
|
||||||
|
@ -229,7 +224,7 @@ func (c *Client) GetProtoVersions(ctx context.Context) (string, error) {
|
||||||
httpResp, err := c.Client.Do(httpReq.WithContext(ctx))
|
httpResp, err := c.Client.Do(httpReq.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We don't attempt a retry here
|
// We don't attempt a retry here
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if we got a header anyway
|
// See if we got a header anyway
|
||||||
|
@ -250,11 +245,11 @@ func (c *Client) GetProtoVersions(ctx context.Context) (string, error) {
|
||||||
// a response that confirms it can speak 2.0
|
// a response that confirms it can speak 2.0
|
||||||
c.lastRWHeader = promHeader
|
c.lastRWHeader = promHeader
|
||||||
}
|
}
|
||||||
return promHeader, fmt.Errorf(httpResp.Status)
|
return fmt.Errorf(httpResp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// All ok, return header and no error
|
// All ok, return no error
|
||||||
return promHeader, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store sends a batch of samples to the HTTP endpoint, the request is the proto marshalled
|
// Store sends a batch of samples to the HTTP endpoint, the request is the proto marshalled
|
||||||
|
@ -448,8 +443,8 @@ func NewTestClient(name, url string) WriteClient {
|
||||||
return &TestClient{name: name, url: url}
|
return &TestClient{name: name, url: url}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestClient) GetProtoVersions(_ context.Context) (string, error) {
|
func (c *TestClient) probeRemoteVersions(_ context.Context) error {
|
||||||
return "2.0;snappy,0.1.0", nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestClient) Store(_ context.Context, req []byte, _ int, _ config.RemoteWriteFormat, _ string) error {
|
func (c *TestClient) Store(_ context.Context, req []byte, _ int, _ config.RemoteWriteFormat, _ string) error {
|
||||||
|
|
|
@ -395,7 +395,7 @@ type WriteClient interface {
|
||||||
// Endpoint is the remote read or write endpoint for the storage client.
|
// Endpoint is the remote read or write endpoint for the storage client.
|
||||||
Endpoint() string
|
Endpoint() string
|
||||||
// Get the protocol versions supported by the endpoint
|
// Get the protocol versions supported by the endpoint
|
||||||
GetProtoVersions(ctx context.Context) (string, error)
|
probeRemoteVersions(ctx context.Context) error
|
||||||
// Get the last RW header received from the endpoint
|
// Get the last RW header received from the endpoint
|
||||||
GetLastRWHeader() string
|
GetLastRWHeader() string
|
||||||
}
|
}
|
||||||
|
|
|
@ -1317,8 +1317,8 @@ func (c *TestWriteClient) Endpoint() string {
|
||||||
return "http://test-remote.com/1234"
|
return "http://test-remote.com/1234"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestWriteClient) GetProtoVersions(_ context.Context) (string, error) {
|
func (c *TestWriteClient) probeRemoteVersions(_ context.Context) error {
|
||||||
return "2.0;snappy,0.1.0", nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestWriteClient) GetLastRWHeader() string {
|
func (c *TestWriteClient) GetLastRWHeader() string {
|
||||||
|
@ -1361,8 +1361,8 @@ func (c *TestBlockingWriteClient) Endpoint() string {
|
||||||
return "http://test-remote-blocking.com/1234"
|
return "http://test-remote-blocking.com/1234"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestBlockingWriteClient) GetProtoVersions(_ context.Context) (string, error) {
|
func (c *TestBlockingWriteClient) probeRemoteVersions(_ context.Context) error {
|
||||||
return "2.0;snappy,0.1.0", nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestBlockingWriteClient) GetLastRWHeader() string {
|
func (c *TestBlockingWriteClient) GetLastRWHeader() string {
|
||||||
|
@ -1378,8 +1378,8 @@ func (c *NopWriteClient) Store(context.Context, []byte, int, config.RemoteWriteF
|
||||||
}
|
}
|
||||||
func (c *NopWriteClient) Name() string { return "nopwriteclient" }
|
func (c *NopWriteClient) Name() string { return "nopwriteclient" }
|
||||||
func (c *NopWriteClient) Endpoint() string { return "http://test-remote.com/1234" }
|
func (c *NopWriteClient) Endpoint() string { return "http://test-remote.com/1234" }
|
||||||
func (c *NopWriteClient) GetProtoVersions(_ context.Context) (string, error) {
|
func (c *NopWriteClient) probeRemoteVersions(_ context.Context) error {
|
||||||
return "2.0;snappy,0.1.0", nil
|
return nil
|
||||||
}
|
}
|
||||||
func (c *NopWriteClient) GetLastRWHeader() string { return "2.0;snappy,0.1.0" }
|
func (c *NopWriteClient) GetLastRWHeader() string { return "2.0;snappy,0.1.0" }
|
||||||
|
|
||||||
|
|
|
@ -203,8 +203,8 @@ func (rws *WriteStorage) ApplyConfig(conf *config.Config) error {
|
||||||
// If this newer remote write format is enabled then we need to probe the remote server
|
// If this newer remote write format is enabled then we need to probe the remote server
|
||||||
// to work out the desired protocol version and compressions
|
// to work out the desired protocol version and compressions
|
||||||
// The value of the header is kept in the client so no need to see it here
|
// The value of the header is kept in the client so no need to see it here
|
||||||
_, _ = c.GetProtoVersions(context.Background())
|
_ = c.probeRemoteVersions(context.Background())
|
||||||
// TODO(alexg): Since they're never used should I remove the return values of GetProtoVersion()?
|
// We ignore any error here, at some point we may choose to log it
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redacted to remove any passwords in the URL (that are
|
// Redacted to remove any passwords in the URL (that are
|
||||||
|
|
Loading…
Reference in a new issue