mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-05 04:16:15 +02:00
discovery/scaleway: use http.Client instead of RoundTripper, enabling follow_redirects support
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
This commit is contained in:
parent
34cebfe953
commit
ddca8ee45a
@ -17,12 +17,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/common/config"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/version"
|
||||
"github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
|
||||
@ -71,28 +68,18 @@ func newBaremetalDiscovery(conf *SDConfig) (*baremetalDiscovery, error) {
|
||||
tagsFilter: conf.TagsFilter,
|
||||
}
|
||||
|
||||
rt, err := config.NewRoundTripperFromConfig(conf.HTTPClientConfig, "scaleway_sd")
|
||||
client, err := newScalewayHTTPClient(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if conf.SecretKeyFile != "" {
|
||||
rt, err = newAuthTokenFileRoundTripper(conf.SecretKeyFile, rt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
profile, err := loadProfile(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d.client, err = scw.NewClient(
|
||||
scw.WithHTTPClient(&http.Client{
|
||||
Transport: rt,
|
||||
Timeout: time.Duration(conf.RefreshInterval),
|
||||
}),
|
||||
scw.WithHTTPClient(client),
|
||||
scw.WithUserAgent(version.PrometheusUserAgent()),
|
||||
scw.WithProfile(profile),
|
||||
)
|
||||
|
||||
@ -17,12 +17,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/common/config"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/version"
|
||||
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
|
||||
@ -84,28 +81,18 @@ func newInstanceDiscovery(conf *SDConfig) (*instanceDiscovery, error) {
|
||||
tagsFilter: conf.TagsFilter,
|
||||
}
|
||||
|
||||
rt, err := config.NewRoundTripperFromConfig(conf.HTTPClientConfig, "scaleway_sd")
|
||||
client, err := newScalewayHTTPClient(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if conf.SecretKeyFile != "" {
|
||||
rt, err = newAuthTokenFileRoundTripper(conf.SecretKeyFile, rt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
profile, err := loadProfile(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d.client, err = scw.NewClient(
|
||||
scw.WithHTTPClient(&http.Client{
|
||||
Transport: rt,
|
||||
Timeout: time.Duration(conf.RefreshInterval),
|
||||
}),
|
||||
scw.WithHTTPClient(client),
|
||||
scw.WithUserAgent(version.PrometheusUserAgent()),
|
||||
scw.WithProfile(profile),
|
||||
)
|
||||
|
||||
@ -221,6 +221,27 @@ func newRefresher(conf *SDConfig) (refresher, error) {
|
||||
return nil, errors.New("unknown Scaleway discovery role")
|
||||
}
|
||||
|
||||
// newScalewayHTTPClient creates an HTTP client from the SD config, optionally
|
||||
// wrapping the transport with token-file authentication.
|
||||
func newScalewayHTTPClient(conf *SDConfig) (*http.Client, error) {
|
||||
client, err := config.NewClientFromConfig(conf.HTTPClientConfig, "scaleway_sd")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client.Timeout = time.Duration(conf.RefreshInterval)
|
||||
|
||||
if conf.SecretKeyFile != "" {
|
||||
rt, err := newAuthTokenFileRoundTripper(conf.SecretKeyFile, client.Transport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.Transport = rt
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func loadProfile(sdConfig *SDConfig) (*scw.Profile, error) {
|
||||
// Profile coming from Prometheus Configuration file
|
||||
prometheusConfigProfile := &scw.Profile{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user