Merge pull request #10423 from markmc/prober-http-status

prober: check response http status code
release-3.4
Xiang Li 2019-01-22 11:19:15 -08:00 committed by GitHub
commit de8e29e71c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

2
go.mod
View File

@ -44,7 +44,7 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8
github.com/ugorji/go v1.1.1
github.com/urfave/cli v1.18.0
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2
go.etcd.io/bbolt v1.3.1-etcd.7
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect

4
go.sum
View File

@ -90,8 +90,8 @@ github.com/ugorji/go v1.1.1 h1:gmervu+jDMvXTbcHQ0pd2wee85nEoE0BsVyEuzkfK8w=
github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/urfave/cli v1.18.0 h1:m9MfmZWX7bwr9kUcs/Asr95j0IVXzGNNc+/5ku2m26Q=
github.com/urfave/cli v1.18.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
go.etcd.io/bbolt v1.3.1-etcd.7 h1:M0l89sIuZ+RkW0rLbUsmxescVzLwLUs+Kvks+0jeHdM=
go.etcd.io/bbolt v1.3.1-etcd.7/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=

View File

@ -3,6 +3,7 @@ package probing
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"sync"
"time"
@ -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)