From b7c30d5bce4cdc597886b795787398236133de84 Mon Sep 17 00:00:00 2001 From: Marcus Cobden Date: Thu, 9 Aug 2018 11:50:56 +0100 Subject: [PATCH] Update github.com/weaveworks/common --- .../weaveworks/common/aws/config.go | 14 +++--- .../common/middleware/instrument.go | 5 +- .../weaveworks/common/server/server.go | 49 +++++++++++++++---- .../weaveworks/common/tracing/tracing.go | 4 +- vendor/manifest | 2 +- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/vendor/github.com/weaveworks/common/aws/config.go b/vendor/github.com/weaveworks/common/aws/config.go index dcba81fa5..378905c24 100644 --- a/vendor/github.com/weaveworks/common/aws/config.go +++ b/vendor/github.com/weaveworks/common/aws/config.go @@ -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 } diff --git a/vendor/github.com/weaveworks/common/middleware/instrument.go b/vendor/github.com/weaveworks/common/middleware/instrument.go index 99b1d1cb2..a88b3a17f 100644 --- a/vendor/github.com/weaveworks/common/middleware/instrument.go +++ b/vendor/github.com/weaveworks/common/middleware/instrument.go @@ -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]+`) diff --git a/vendor/github.com/weaveworks/common/server/server.go b/vendor/github.com/weaveworks/common/server/server.go index 39658b5dc..898ceae0d 100644 --- a/vendor/github.com/weaveworks/common/server/server.go +++ b/vendor/github.com/weaveworks/common/server/server.go @@ -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(). diff --git a/vendor/github.com/weaveworks/common/tracing/tracing.go b/vendor/github.com/weaveworks/common/tracing/tracing.go index 5be761863..fe817b5cf 100644 --- a/vendor/github.com/weaveworks/common/tracing/tracing.go +++ b/vendor/github.com/weaveworks/common/tracing/tracing.go @@ -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) diff --git a/vendor/manifest b/vendor/manifest index d03d440d3..0718437d5 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -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 },