mirror of
https://github.com/gomods/athens
synced 2026-02-03 08:40:31 +00:00
Add client tracing to external storage requests (#1626)
This commit is contained in:
@@ -26,11 +26,6 @@ func App(conf *config.Config) (http.Handler, error) {
|
||||
// ENV is used to help switch settings based on where the
|
||||
// application is being run. Default is "development".
|
||||
ENV := conf.GoEnv
|
||||
store, err := GetStorage(conf.StorageType, conf.Storage, conf.TimeoutDuration())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error getting storage configuration (%s)", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if conf.GithubToken != "" {
|
||||
if conf.NETRCPath != "" {
|
||||
@@ -115,11 +110,23 @@ func App(conf *config.Config) (http.Handler, error) {
|
||||
r.Use(mw.NewFilterMiddleware(mf, conf.GlobalEndpoint))
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &ochttp.Transport{
|
||||
Base: http.DefaultTransport,
|
||||
},
|
||||
}
|
||||
|
||||
// Having the hook set means we want to use it
|
||||
if vHook := conf.ValidatorHook; vHook != "" {
|
||||
r.Use(mw.NewValidationMiddleware(vHook))
|
||||
}
|
||||
|
||||
store, err := GetStorage(conf.StorageType, conf.Storage, conf.TimeoutDuration(), client)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error getting storage configuration (%s)", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxyRouter := r
|
||||
if subRouter != nil {
|
||||
proxyRouter = subRouter
|
||||
|
||||
@@ -3,6 +3,7 @@ package actions
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gomods/athens/pkg/config"
|
||||
@@ -20,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
// GetStorage returns storage backend based on env configuration
|
||||
func GetStorage(storageType string, storageConfig *config.StorageConfig, timeout time.Duration) (storage.Backend, error) {
|
||||
func GetStorage(storageType string, storageConfig *config.StorageConfig, timeout time.Duration, client *http.Client) (storage.Backend, error) {
|
||||
const op errors.Op = "actions.GetStorage"
|
||||
switch storageType {
|
||||
case "memory":
|
||||
@@ -65,8 +66,7 @@ func GetStorage(storageType string, storageConfig *config.StorageConfig, timeout
|
||||
if storageConfig.External == nil {
|
||||
return nil, errors.E(op, "Invalid External Storage Configuration")
|
||||
}
|
||||
// TODO(marwan-at-work): add client tracing
|
||||
return external.NewClient(storageConfig.External.URL, nil), nil
|
||||
return external.NewClient(storageConfig.External.URL, client), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("storage type %s is unknown", storageType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user