Add client tracing to external storage requests (#1626)

This commit is contained in:
Marwan Sulaiman
2020-06-14 11:03:48 -04:00
committed by GitHub
parent c08aa890cb
commit 38a6a6fe0b
2 changed files with 15 additions and 8 deletions
+12 -5
View File
@@ -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 -3
View File
@@ -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)
}