Update github.com/weaveworks/common

This commit is contained in:
Marcus Cobden
2018-08-09 11:50:56 +01:00
parent 1e0cd0ee32
commit b7c30d5bce
5 changed files with 53 additions and 21 deletions

View File

@@ -18,14 +18,7 @@ import (
// endpoint) or fully valid endpoint with dummy region assumed (e.g
// for URLs to emulated services).
func ConfigFromURL(awsURL *url.URL) (*aws.Config, error) {
if awsURL.User == nil {
return nil, fmt.Errorf("must specify escaped Access Key & Secret Access in URL")
}
password, _ := awsURL.User.Password()
creds := credentials.NewStaticCredentials(awsURL.User.Username(), password, "")
config := aws.NewConfig().
WithCredentials(creds).
// Use a custom http.Client with the golang defaults but also specifying
// MaxIdleConnsPerHost because of a bug in golang https://github.com/golang/go/issues/13801
// where MaxIdleConnsPerHost does not work as expected.
@@ -44,6 +37,13 @@ func ConfigFromURL(awsURL *url.URL) (*aws.Config, error) {
ExpectContinueTimeout: 1 * time.Second,
},
})
if awsURL.User != nil {
password, _ := awsURL.User.Password()
creds := credentials.NewStaticCredentials(awsURL.User.Username(), password, "")
config = config.WithCredentials(creds)
}
if strings.Contains(awsURL.Host, ".") {
return config.WithEndpoint(fmt.Sprintf("http://%s", awsURL.Host)).WithRegion("dummy"), nil
}

View File

@@ -60,8 +60,7 @@ func (i Instrument) Wrap(next http.Handler) http.Handler {
// 2. The request matches an unamed gorilla mux router. Munge the path
// template such that templates like '/api/{org}/foo' come out as
// 'api_org_foo'.
// 3. The request doesn't match a mux route. Munge the Path in the same
// manner as (2).
// 3. The request doesn't match a mux route. Return "other"
// We do all this as we do not wish to emit high cardinality labels to
// prometheus.
func (i Instrument) getRouteName(r *http.Request) string {
@@ -74,7 +73,7 @@ func (i Instrument) getRouteName(r *http.Request) string {
return MakeLabelValue(tmpl)
}
}
return MakeLabelValue(r.URL.Path)
return "other"
}
var invalidChars = regexp.MustCompile(`[^a-zA-Z0-9]+`)

View File

@@ -53,9 +53,9 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.IntVar(&cfg.HTTPListenPort, "server.http-listen-port", 80, "HTTP server listen port.")
f.IntVar(&cfg.GRPCListenPort, "server.grpc-listen-port", 9095, "gRPC server listen port.")
f.BoolVar(&cfg.RegisterInstrumentation, "server.register-instrumentation", true, "Register the intrumentation handlers (/metrics etc).")
f.DurationVar(&cfg.ServerGracefulShutdownTimeout, "server.graceful-shutdown-timeout", 5*time.Second, "Timeout for graceful shutdowns")
f.DurationVar(&cfg.HTTPServerReadTimeout, "server.http-read-timeout", 5*time.Second, "Read timeout for HTTP server")
f.DurationVar(&cfg.HTTPServerWriteTimeout, "server.http-write-timeout", 5*time.Second, "Write timeout for HTTP server")
f.DurationVar(&cfg.ServerGracefulShutdownTimeout, "server.graceful-shutdown-timeout", 30*time.Second, "Timeout for graceful shutdowns")
f.DurationVar(&cfg.HTTPServerReadTimeout, "server.http-read-timeout", 30*time.Second, "Read timeout for HTTP server")
f.DurationVar(&cfg.HTTPServerWriteTimeout, "server.http-write-timeout", 30*time.Second, "Write timeout for HTTP server")
f.DurationVar(&cfg.HTTPServerIdleTimeout, "server.http-idle-timeout", 120*time.Second, "Idle timeout for HTTP server")
cfg.LogLevel.RegisterFlags(f)
}
@@ -178,17 +178,48 @@ func RegisterInstrumentation(router *mux.Router) {
router.PathPrefix("/debug/pprof").Handler(http.DefaultServeMux)
}
// Run the server; blocks until SIGTERM is received.
func (s *Server) Run() {
go s.httpServer.Serve(s.httpListener)
// Run the server; blocks until SIGTERM or an error is received.
func (s *Server) Run() error {
errChan := make(chan error)
// Wait for a signal
go func() {
s.handler.Loop()
select {
case errChan <- nil:
default:
}
}()
go func() {
err := s.httpServer.Serve(s.httpListener)
if err == http.ErrServerClosed {
err = nil
}
select {
case errChan <- err:
default:
}
}()
// Setup gRPC server
// for HTTP over gRPC, ensure we don't double-count the middleware
httpgrpc.RegisterHTTPServer(s.GRPC, httpgrpc_server.NewServer(s.HTTP))
go s.GRPC.Serve(s.grpcListener)
// Wait for a signal
s.handler.Loop()
go func() {
err := s.GRPC.Serve(s.grpcListener)
if err == grpc.ErrServerStopped {
err = nil
}
select {
case errChan <- err:
default:
}
}()
return <-errChan
}
// Stop unblocks Run().

View File

@@ -7,11 +7,13 @@ import (
"os"
jaegercfg "github.com/uber/jaeger-client-go/config"
jaegerprom "github.com/uber/jaeger-lib/metrics/prometheus"
)
// installJaeger registers Jaeger as the OpenTracing implementation.
func installJaeger(serviceName string, cfg *jaegercfg.Configuration) io.Closer {
closer, err := cfg.InitGlobalTracer(serviceName)
metricsFactory := jaegerprom.New()
closer, err := cfg.InitGlobalTracer(serviceName, jaegercfg.Metrics(metricsFactory))
if err != nil {
fmt.Printf("Could not initialize jaeger tracer: %s\n", err.Error())
os.Exit(1)

2
vendor/manifest vendored
View File

@@ -1949,7 +1949,7 @@
"importpath": "github.com/weaveworks/common",
"repository": "https://github.com/weaveworks/common",
"vcs": "git",
"revision": "4d96fd8dcf2c7b417912c6219b310112cb4a4626",
"revision": "54b7e30527f846e1515fb5a85d0ff5674f05a267",
"branch": "HEAD",
"notests": true
},