Fix todos around 405 HEAD handling

Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
This commit is contained in:
Alex Greenbank 2024-03-21 15:41:39 +00:00
parent e5c5ef1a2d
commit 95f1ee61cf
2 changed files with 11 additions and 6 deletions

View file

@ -242,6 +242,14 @@ func (c *Client) GetProtoVersions(ctx context.Context) (string, error) {
// Check for an error
if httpResp.StatusCode != 200 {
if httpResp.StatusCode == 405 {
// If we get a 405 (MethodNotAllowed) error then it means the endpoint doesn't
// understand Remote Write 2.0, so we allow the lastRWHeader to be overwritten
// even if it is blank
// This will make subsequent sends use RemoteWrite 1.0 until the endpoint gives
// a response that confirms it can speak 2.0
c.lastRWHeader = promHeader
}
return promHeader, fmt.Errorf(httpResp.Status)
}

View file

@ -199,15 +199,12 @@ func (rws *WriteStorage) ApplyConfig(conf *config.Config) error {
case Version1:
// We use the standard value as there's no negotiation to be had
case Version2:
rwFormat = Version2
// 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
// The value of the header is kept in the client so no need to see it here
rwFormat = Version2
_, err := c.GetProtoVersions(context.Background()) // TODO(alexg) - better ctx to pass?
if err != nil {
// TODO(alexg) - Log an error based on this?
// TODO(alexg) - if we get 405 (MethodNotAllowed) then we should default to 1.0 (and downgrade rwFormat)?
}
_, _ = c.GetProtoVersions(context.Background())
// TODO(alexg): Since they're never used should I remove the return values of GetProtoVersion()?
}
// Redacted to remove any passwords in the URL (that are