@ -26,7 +26,8 @@ import (
"time"
"github.com/go-kit/kit/log"
config_util "github.com/prometheus/common/config"
"github.com/pkg/errors"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/refresh"
"github.com/prometheus/prometheus/discovery/targetgroup"
@ -54,7 +55,7 @@ func newRobotDiscovery(conf *SDConfig, logger log.Logger) (*robotDiscovery, erro
endpoint : conf . robotEndpoint ,
}
rt , err := config_util . NewRoundTripperFromConfig ( conf . HTTPClientConfig , "hetzner_sd" , false , false )
rt , err := config . NewRoundTripperFromConfig ( conf . HTTPClientConfig , "hetzner_sd" , false , false )
if err != nil {
return nil , err
}
@ -70,10 +71,16 @@ func (d *robotDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, err
if err != nil {
return nil , err
}
defer func ( ) {
io . Copy ( ioutil . Discard , resp . Body )
resp . Body . Close ( )
} ( )
if resp . StatusCode / 100 != 2 {
return nil , errors . Errorf ( "non 2xx status '%d' response during hetzner service discovery with role robot" , resp . StatusCode )
}
var servers serversList
err = json . NewDecoder ( resp . Body ) . Decode ( & servers )
if err != nil {