Merge pull request #18539 from roidelapluie/roidelapluie/scwrt
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests for Prometheus upgrades and downgrades (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Compliance testing (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

discovery/scaleway: use http.Client instead of RoundTripper, enabling follow_redirects support
This commit is contained in:
Julien 2026-04-21 10:09:37 +02:00 committed by GitHub
commit 40efbd55b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 30 deletions

View file

@ -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),
)

View file

@ -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),
)

View file

@ -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{