Skip to content

Commit

Permalink
feat: upstream/remote support custom http client (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
hidu authored Apr 12, 2024
1 parent c8d7ec9 commit e1c67e3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion upstream/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const cloudHostnameSuffix = "pyroscope.cloud"
type Remote struct {
cfg Config
jobs chan *upstream.UploadJob
client *http.Client
client HTTPClient
logger Logger

done chan struct{}
Expand All @@ -35,6 +35,10 @@ type Remote struct {
flushWG sync.WaitGroup
}

type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}

type Config struct {
AuthToken string
BasicAuthUser string // http basic auth user
Expand All @@ -45,6 +49,7 @@ type Config struct {
Address string
Timeout time.Duration
Logger Logger
HTTPClient HTTPClient // optional, custom client
}

type Logger interface {
Expand Down Expand Up @@ -74,6 +79,9 @@ func NewRemote(cfg Config) (*Remote, error) {
logger: cfg.Logger,
done: make(chan struct{}),
}
if cfg.HTTPClient != nil {
r.client = cfg.HTTPClient
}

// parse the upstream address
u, err := url.Parse(cfg.Address)
Expand Down

0 comments on commit e1c67e3

Please sign in to comment.