From 5085468a2a2ad3084bfc2655b46070b2770321d4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 23 Aug 2018 11:12:12 +0000 Subject: [PATCH] Update weaveworks/common to latest This fixes inconsistencies between the vendor dir and 'dep'. Removes some files under vendor/github.com/segmentio that are no longer used. Also brings in a change to http 500 error formatting and unit-test diff printing. --- Gopkg.lock | 15 +++++- .../github.com/segmentio/fasthash/.gitignore | 17 ------ .../github.com/segmentio/fasthash/README.md | 54 ------------------- .../github.com/segmentio/fasthash/fasthash.go | 26 --------- .../segmentio/fasthash/fasthash32.go | 26 --------- .../common/httpgrpc/server/server.go | 3 ++ .../weaveworks/common/middleware/logging.go | 28 +++++++--- .../github.com/weaveworks/common/test/diff.go | 4 +- 8 files changed, 39 insertions(+), 134 deletions(-) delete mode 100644 vendor/github.com/segmentio/fasthash/.gitignore delete mode 100644 vendor/github.com/segmentio/fasthash/README.md delete mode 100644 vendor/github.com/segmentio/fasthash/fasthash.go delete mode 100644 vendor/github.com/segmentio/fasthash/fasthash32.go diff --git a/Gopkg.lock b/Gopkg.lock index aed1f09b1b5..27bbb7132e6 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -829,6 +829,14 @@ revision = "879c5887cd475cd7864858769793b2ceb0d44feb" version = "v1.1.0" +[[projects]] + branch = "master" + digest = "1:c59d82fe02e030fcbd31e71534e2c72028e50ef14eaa3fbe26b077fdf82daa6e" + name = "github.com/segmentio/fasthash" + packages = ["fnv1a"] + pruneopts = "UT" + revision = "a72b379d632eab4b49e4f4b2c765cfebf0a74796" + [[projects]] digest = "1:8e79da55d2a6a92374cc7ca5ce1a7739fe0a13ca04b6f8c806a50f1873138eff" name = "github.com/sercand/kuberesolver" @@ -910,7 +918,7 @@ [[projects]] branch = "master" - digest = "1:5fb4b51835377c63ba87d8c6120d6c7c87ee7ea31a0883bf028f4caefca411f7" + digest = "1:a3d33cb49d37fae16881f4b7ba60c55c9d99237695f912b158b6b773e1a333f8" name = "github.com/weaveworks/common" packages = [ "aws", @@ -930,7 +938,7 @@ "user", ] pruneopts = "UT" - revision = "54b7e30527f846e1515fb5a85d0ff5674f05a267" + revision = "80ff0769bb38e575cd85a64a4575a2ca1ef5ada5" [[projects]] digest = "1:efac30de93ca1ff38050f46dc34f1338ebc8778de488f919f79ad9e6188719d3" @@ -1381,12 +1389,14 @@ "github.com/prometheus/prometheus/web/api/v1", "github.com/prometheus/tsdb", "github.com/prometheus/tsdb/fileutil", + "github.com/segmentio/fasthash/fnv1a", "github.com/stretchr/testify/assert", "github.com/stretchr/testify/require", "github.com/weaveworks/billing-client", "github.com/weaveworks/common/aws", "github.com/weaveworks/common/errors", "github.com/weaveworks/common/httpgrpc", + "github.com/weaveworks/common/httpgrpc/server", "github.com/weaveworks/common/instrument", "github.com/weaveworks/common/logging", "github.com/weaveworks/common/mflag", @@ -1408,6 +1418,7 @@ "google.golang.org/grpc/encoding/gzip", "google.golang.org/grpc/health/grpc_health_v1", "google.golang.org/grpc/metadata", + "google.golang.org/grpc/naming", "google.golang.org/grpc/status", "gopkg.in/yaml.v2", ] diff --git a/vendor/github.com/segmentio/fasthash/.gitignore b/vendor/github.com/segmentio/fasthash/.gitignore deleted file mode 100644 index 30ff29ca785..00000000000 --- a/vendor/github.com/segmentio/fasthash/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# Binaries for programs and plugins -*.exe -*.dll -*.so -*.dylib - -# Test binary, build with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 -.glide/ - -# Emacs -*~ diff --git a/vendor/github.com/segmentio/fasthash/README.md b/vendor/github.com/segmentio/fasthash/README.md deleted file mode 100644 index 24f5874a8f3..00000000000 --- a/vendor/github.com/segmentio/fasthash/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# fasthash [![CircleCI](https://circleci.com/gh/segmentio/fasthash.svg?style=shield)](https://circleci.com/gh/segmentio/fasthash) [![Go Report Card](https://goreportcard.com/badge/github.com/segmentio/fasthash)](https://goreportcard.com/report/github.com/segmentio/fasthash) [![GoDoc](https://godoc.org/github.com/segmentio/fasthash?status.svg)](https://godoc.org/github.com/segmentio/fasthash) -Go package porting the standard hashing algorithms to a more efficient implementation. - -## Motivations - -Go has great support for hashing algorithms in the standard library, but the -APIs are all exposed as interfaces, which means passing strings or byte slices -to those require dynamic memory allocations. Hashing a string typically requires -2 allocations, one for the Hash value, and one to covert the string to a byte -slice. - -This package attempts to solve this issue by exposing functions that implement -string hashing algorithms and don't require dynamic memory alloations. - -## Testing - -To ensure consistency between the `fasthash` package and the standard library, -all tests must be implemented to run against the standard hash functions and -validate that both packages produced the same results. - -## Benchmarks - -The implementations also have to prove that they are more efficient in terms of -CPU and memory usage than the functions found in the standard library. -Here's an example with fnv-1a: -``` -BenchmarkHash64/standard_hash_function 20000000 105.0 ns/op 342.31 MB/s 56 B/op 2 allocs/op -BenchmarkHash64/hash_function 50000000 38.6 ns/op 932.35 MB/s 0 B/op 0 allocs/op -``` - -# Usage Example: FNV-1a - -```go -package main - -import ( - "fmt" - - "github.com/segmentio/fasthash/fnv1a" -) - -func main() { - // Hash a single string. - h1 := fnv1a.HashString64("Hello World!") - fmt.Println("FNV-1a hash of 'Hello World!':", h1) - - // Incrementally compute a hash value from a sequence of strings. - h2 := fnv1a.Init64 - h2 = fnv1a.AddString64(h2, "A") - h2 = fnv1a.AddString64(h2, "B") - h2 = fnv1a.AddString64(h2, "C") - fmt.Println("FNV-1a hash of 'ABC':", h2) -} -``` diff --git a/vendor/github.com/segmentio/fasthash/fasthash.go b/vendor/github.com/segmentio/fasthash/fasthash.go deleted file mode 100644 index dfadd8ecfb6..00000000000 --- a/vendor/github.com/segmentio/fasthash/fasthash.go +++ /dev/null @@ -1,26 +0,0 @@ -package fasthash - -import ( - "encoding/binary" - "hash" -) - -// HashString64 makes a hashing function from the hashing algorithm returned by f. -func HashString64(f func() hash.Hash64) func(string) uint64 { - return func(s string) uint64 { - h := f() - h.Write([]byte(s)) - return h.Sum64() - } -} - -// HashUint64 makes a hashing function from the hashing algorithm return by f. -func HashUint64(f func() hash.Hash64) func(uint64) uint64 { - return func(u uint64) uint64 { - b := [8]byte{} - binary.BigEndian.PutUint64(b[:], u) - h := f() - h.Write(b[:]) - return h.Sum64() - } -} diff --git a/vendor/github.com/segmentio/fasthash/fasthash32.go b/vendor/github.com/segmentio/fasthash/fasthash32.go deleted file mode 100644 index 7e2207d7030..00000000000 --- a/vendor/github.com/segmentio/fasthash/fasthash32.go +++ /dev/null @@ -1,26 +0,0 @@ -package fasthash - -import ( - "encoding/binary" - "hash" -) - -// HashString32 makes a hashing function from the hashing algorithm returned by f. -func HashString32(f func() hash.Hash32) func(string) uint32 { - return func(s string) uint32 { - h := f() - h.Write([]byte(s)) - return h.Sum32() - } -} - -// HashUint32 makes a hashing function from the hashing algorithm return by f. -func HashUint32(f func() hash.Hash32) func(uint32) uint32 { - return func(u uint32) uint32 { - b := [4]byte{} - binary.BigEndian.PutUint32(b[:], u) - h := f() - h.Write(b[:]) - return h.Sum32() - } -} diff --git a/vendor/github.com/weaveworks/common/httpgrpc/server/server.go b/vendor/github.com/weaveworks/common/httpgrpc/server/server.go index 1fdb607e40d..7695523e1a5 100644 --- a/vendor/github.com/weaveworks/common/httpgrpc/server/server.go +++ b/vendor/github.com/weaveworks/common/httpgrpc/server/server.go @@ -143,6 +143,7 @@ func NewClient(address string) (*Client, error) { }, nil } +// HTTPRequest wraps an ordinary HTTPRequest with a gRPC one func HTTPRequest(r *http.Request) (*httpgrpc.HTTPRequest, error) { body, err := ioutil.ReadAll(r.Body) if err != nil { @@ -156,6 +157,7 @@ func HTTPRequest(r *http.Request) (*httpgrpc.HTTPRequest, error) { }, nil } +// WriteResponse converts an httpgrpc response to an HTTP one func WriteResponse(w http.ResponseWriter, resp *httpgrpc.HTTPResponse) error { toHeader(resp.Headers, w.Header()) w.WriteHeader(int(resp.Code)) @@ -163,6 +165,7 @@ func WriteResponse(w http.ResponseWriter, resp *httpgrpc.HTTPResponse) error { return err } +// WriteError converts an httpgrpc error to an HTTP one func WriteError(w http.ResponseWriter, err error) { resp, ok := httpgrpc.HTTPResponseFromError(err) if ok { diff --git a/vendor/github.com/weaveworks/common/middleware/logging.go b/vendor/github.com/weaveworks/common/middleware/logging.go index fc669d0edc8..c081dbc056e 100644 --- a/vendor/github.com/weaveworks/common/middleware/logging.go +++ b/vendor/github.com/weaveworks/common/middleware/logging.go @@ -3,7 +3,6 @@ package middleware import ( "bytes" "net/http" - "net/http/httputil" "time" "github.com/weaveworks/common/logging" @@ -27,7 +26,7 @@ func (l Log) Wrap(next http.Handler) http.Handler { begin := time.Now() uri := r.RequestURI // capture the URI before running next, as it may get rewritten // Log headers before running 'next' in case other interceptors change the data. - headers, err := httputil.DumpRequest(r, false) + headers, err := dumpRequest(r) if err != nil { headers = nil l.logWithRequest(r).Errorf("Could not dump request headers: %v", err) @@ -39,14 +38,11 @@ func (l Log) Wrap(next http.Handler) http.Handler { if 100 <= statusCode && statusCode < 500 || statusCode == http.StatusBadGateway || statusCode == http.StatusServiceUnavailable { l.logWithRequest(r).Debugf("%s %s (%d) %s", r.Method, uri, statusCode, time.Since(begin)) if l.LogRequestHeaders && headers != nil { - l.logWithRequest(r).Debugf("Is websocket request: %v\n%s", IsWSHandshakeRequest(r), string(headers)) + l.logWithRequest(r).Debugf("ws: %v; %s", IsWSHandshakeRequest(r), string(headers)) } } else { - l.logWithRequest(r).Warnf("%s %s (%d) %s", r.Method, uri, statusCode, time.Since(begin)) - if headers != nil { - l.logWithRequest(r).Warnf("Is websocket request: %v\n%s", IsWSHandshakeRequest(r), string(headers)) - } - l.logWithRequest(r).Warnf("Response: %s", buf.Bytes()) + l.logWithRequest(r).Warnf("%s %s (%d) %s Response: %q ws: %v; %s", + r.Method, uri, statusCode, time.Since(begin), buf.Bytes(), IsWSHandshakeRequest(r), headers) } }) } @@ -56,3 +52,19 @@ func (l Log) Wrap(next http.Handler) http.Handler { var Logging = Log{ Log: logging.Global(), } + +func dumpRequest(req *http.Request) ([]byte, error) { + var b bytes.Buffer + + // Exclude some headers for security, or just that we don't need them when debugging + err := req.Header.WriteSubset(&b, map[string]bool{ + "Cookie": true, + "X-Csrf-Token": true, + }) + if err != nil { + return nil, err + } + + ret := bytes.Replace(b.Bytes(), []byte("\r\n"), []byte("; "), -1) + return ret, nil +} diff --git a/vendor/github.com/weaveworks/common/test/diff.go b/vendor/github.com/weaveworks/common/test/diff.go index 477ae98f966..5678972b61a 100644 --- a/vendor/github.com/weaveworks/common/test/diff.go +++ b/vendor/github.com/weaveworks/common/test/diff.go @@ -8,7 +8,9 @@ import ( // Diff diffs two arbitrary data structures, giving human-readable output. func Diff(want, have interface{}) string { config := spew.NewDefaultConfig() - config.ContinueOnMethod = true + // Set ContinueOnMethod to true if you cannot see a difference and + // want to look beyond the String() method + config.ContinueOnMethod = false config.SortKeys = true config.SpewKeys = true text, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{