mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Remote write: read first line of response and include it in the error.
This commit is contained in:
parent
1c9499bbbd
commit
46abe8cbf2
|
@ -14,6 +14,7 @@
|
||||||
package remote
|
package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -117,7 +118,12 @@ func (c *Client) Store(samples model.Samples) error {
|
||||||
defer httpResp.Body.Close()
|
defer httpResp.Body.Close()
|
||||||
|
|
||||||
if httpResp.StatusCode/100 != 2 {
|
if httpResp.StatusCode/100 != 2 {
|
||||||
err = fmt.Errorf("server returned HTTP status %s", httpResp.Status)
|
scanner := bufio.NewScanner(httpResp.Body)
|
||||||
|
line := ""
|
||||||
|
if scanner.Scan() {
|
||||||
|
line = scanner.Text()
|
||||||
|
}
|
||||||
|
err = fmt.Errorf("server returned HTTP status %s: %s", httpResp.Status, line)
|
||||||
}
|
}
|
||||||
if httpResp.StatusCode/100 == 5 {
|
if httpResp.StatusCode/100 == 5 {
|
||||||
return recoverableError{err}
|
return recoverableError{err}
|
||||||
|
|
|
@ -37,15 +37,15 @@ func TestStoreHTTPErrorHandling(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 300,
|
code: 300,
|
||||||
err: fmt.Errorf("server returned HTTP status 300 Multiple Choices"),
|
err: fmt.Errorf("server returned HTTP status 300 Multiple Choices: test error"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 404,
|
code: 404,
|
||||||
err: fmt.Errorf("server returned HTTP status 404 Not Found"),
|
err: fmt.Errorf("server returned HTTP status 404 Not Found: test error"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 500,
|
code: 500,
|
||||||
err: recoverableError{fmt.Errorf("server returned HTTP status 500 Internal Server Error")},
|
err: recoverableError{fmt.Errorf("server returned HTTP status 500 Internal Server Error: test error")},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func TestStoreHTTPErrorHandling(t *testing.T) {
|
||||||
|
|
||||||
err = c.Store(nil)
|
err = c.Store(nil)
|
||||||
if !reflect.DeepEqual(err, test.err) {
|
if !reflect.DeepEqual(err, test.err) {
|
||||||
t.Fatalf("%d. Unexpected error; want %v, got %v", i, test.err, err)
|
t.Errorf("%d. Unexpected error; want %v, got %v", i, test.err, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server.Close()
|
server.Close()
|
||||||
|
|
Loading…
Reference in a new issue