Skip to content

Commit

Permalink
Merge pull request #7 from markmc/prober-http-status
Browse files Browse the repository at this point in the history
prober: check response http status code
  • Loading branch information
xiang90 authored Jan 16, 2019
2 parents 07dd2e8 + 902e162 commit 43a291a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package probing
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -60,6 +61,10 @@ func (p *prober) AddHTTP(id string, probingInterval time.Duration, endpoints []s
panic(err)
}
resp, err := p.tr.RoundTrip(req)
if err == nil && resp.StatusCode != http.StatusOK {
err = fmt.Errorf("got unexpected HTTP status code %s from %s", resp.Status, endpoints[pinned])
resp.Body.Close()
}
if err != nil {
s.recordFailure(err)
pinned = (pinned + 1) % len(endpoints)
Expand Down

0 comments on commit 43a291a

Please sign in to comment.