Treat non-200 HTTP response as error.
Change-Id: I2a9f3b47012b3c4839be53aa44c66d16dd41a24a
This commit is contained in:
parent
e27447da5c
commit
814e479723
|
@ -224,6 +224,9 @@ func (t *target) scrape(timestamp clientmodel.Timestamp, ingester extraction.Ing
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("server returned HTTP status %s", resp.Status)
|
||||||
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
processor, err := extraction.ProcessorForRequestHeader(resp.Header)
|
processor, err := extraction.ProcessorForRequestHeader(resp.Header)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package retrieval
|
package retrieval
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -127,3 +128,20 @@ func TestTargetScrapeTimeout(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTargetScrape404(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
}))
|
||||||
|
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
testTarget := NewTarget(server.URL, 10*time.Millisecond, clientmodel.LabelSet{})
|
||||||
|
ingester := nopIngester{}
|
||||||
|
|
||||||
|
want := errors.New("server returned HTTP status 404 Not Found")
|
||||||
|
got := testTarget.Scrape(time.Now(), ingester)
|
||||||
|
if got == nil || want.Error() != got.Error() {
|
||||||
|
t.Fatalf("want err %q, got %q", want, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue