From 10d955f076eb4c89766ba5259e25b6498486aa55 Mon Sep 17 00:00:00 2001 From: Kamil Samigullin Date: Tue, 4 Sep 2018 13:22:11 +0300 Subject: [PATCH] update deps and fix build --- Gopkg.lock | 16 ++- .../go-kit/pkg/strings/builder_go110.go | 10 ++ .../go-kit/pkg/strings/builder_pre_go110.go | 121 ++++++++++++++++++ .../kamilsk/go-kit/pkg/strings/strings.go | 20 +++ .../client_golang/prometheus/desc.go | 2 +- .../client_golang/prometheus/metric.go | 18 ++- .../client_golang/prometheus/registry.go | 4 +- .../client_golang/prometheus/value.go | 2 +- 8 files changed, 173 insertions(+), 20 deletions(-) create mode 100644 vendor/github.com/kamilsk/go-kit/pkg/strings/builder_go110.go create mode 100644 vendor/github.com/kamilsk/go-kit/pkg/strings/builder_pre_go110.go create mode 100644 vendor/github.com/kamilsk/go-kit/pkg/strings/strings.go diff --git a/Gopkg.lock b/Gopkg.lock index f391636..d530d71 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -106,11 +106,14 @@ [[projects]] branch = "master" - digest = "1:5cc561c0f280b098d24dbaa192fa0c6409bbd0cbc06b6e4ac46f6e9b36077ca6" + digest = "1:4bd7ec2c74487ee345d42c79a970b73512b44fbef4e02db26ec61e15901e6b43" name = "github.com/kamilsk/go-kit" - packages = ["pkg/fn"] + packages = [ + "pkg/fn", + "pkg/strings", + ] pruneopts = "UT" - revision = "c4a06f93eaecb1ce90c8246c1f7ed8af368e567d" + revision = "0101ca8436fba89061a6961d864ae7fa731e5797" [[projects]] branch = "master" @@ -189,7 +192,7 @@ [[projects]] branch = "master" - digest = "1:5423af3e995a8d4cc5753845d80849c8df1ef1debcef4bf373b075a7c1ab8a23" + digest = "1:779b60df866a1d0c7a19d5988c86e4d5b0732d07fb6a047e5852ad4a038156b1" name = "github.com/prometheus/client_golang" packages = [ "prometheus", @@ -197,7 +200,7 @@ "prometheus/promhttp", ] pruneopts = "UT" - revision = "a10423e9da491a85bad70ec36c4215a6b063a7c0" + revision = "d968d2292ed0d640ba2065d86a22ddee4bf009f1" [[projects]] branch = "master" @@ -343,7 +346,7 @@ name = "golang.org/x/sys" packages = ["unix"] pruneopts = "UT" - revision = "fa5fdf94c78965f1aa8423f0cc50b8b8d728b05a" + revision = "2b024373dcd9800f0cae693839fac6ede8d64a8c" [[projects]] digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" @@ -446,6 +449,7 @@ "github.com/golang/protobuf/proto", "github.com/golang/protobuf/ptypes/timestamp", "github.com/kamilsk/go-kit/pkg/fn", + "github.com/kamilsk/go-kit/pkg/strings", "github.com/lib/pq", "github.com/magiconair/properties/assert", "github.com/mailru/easyjson", diff --git a/vendor/github.com/kamilsk/go-kit/pkg/strings/builder_go110.go b/vendor/github.com/kamilsk/go-kit/pkg/strings/builder_go110.go new file mode 100644 index 0000000..3cc191c --- /dev/null +++ b/vendor/github.com/kamilsk/go-kit/pkg/strings/builder_go110.go @@ -0,0 +1,10 @@ +// +build go1.10 + +package strings + +import "strings" + +// Builder is alias for built-in struct. +type Builder struct { + strings.Builder +} diff --git a/vendor/github.com/kamilsk/go-kit/pkg/strings/builder_pre_go110.go b/vendor/github.com/kamilsk/go-kit/pkg/strings/builder_pre_go110.go new file mode 100644 index 0000000..3b1f6b9 --- /dev/null +++ b/vendor/github.com/kamilsk/go-kit/pkg/strings/builder_pre_go110.go @@ -0,0 +1,121 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.10 + +package strings + +import ( + "unicode/utf8" + "unsafe" +) + +// A Builder is used to efficiently build a string using Write methods. +// It minimizes memory copying. The zero value is ready to use. +// Do not copy a non-zero Builder. +type Builder struct { + addr *Builder // of receiver, to detect copies by value + buf []byte +} + +// noescape hides a pointer from escape analysis. noescape is +// the identity function but escape analysis doesn't think the +// output depends on the input. noescape is inlined and currently +// compiles down to zero instructions. +// USE CAREFULLY! +// This was copied from the runtime; see issues 23382 and 7921. +//go:nosplit +func noescape(p unsafe.Pointer) unsafe.Pointer { + x := uintptr(p) + return unsafe.Pointer(x ^ 0) +} + +func (b *Builder) copyCheck() { + if b.addr == nil { + // This hack works around a failing of Go's escape analysis + // that was causing b to escape and be heap allocated. + // See issue 23382. + // TODO: once issue 7921 is fixed, this should be reverted to + // just "b.addr = b". + b.addr = (*Builder)(noescape(unsafe.Pointer(b))) + } else if b.addr != b { + panic("strings: illegal use of non-zero Builder copied by value") + } +} + +// String returns the accumulated string. +func (b *Builder) String() string { + return *(*string)(unsafe.Pointer(&b.buf)) +} + +// Len returns the number of accumulated bytes; b.Len() == len(b.String()). +func (b *Builder) Len() int { return len(b.buf) } + +// Reset resets the Builder to be empty. +func (b *Builder) Reset() { + b.addr = nil + b.buf = nil +} + +// grow copies the buffer to a new, larger buffer so that there are at least n +// bytes of capacity beyond len(b.buf). +func (b *Builder) grow(n int) { + buf := make([]byte, len(b.buf), 2*cap(b.buf)+n) + copy(buf, b.buf) + b.buf = buf +} + +// Grow grows b's capacity, if necessary, to guarantee space for +// another n bytes. After Grow(n), at least n bytes can be written to b +// without another allocation. If n is negative, Grow panics. +func (b *Builder) Grow(n int) { + b.copyCheck() + if n < 0 { + panic("strings.Builder.Grow: negative count") + } + if cap(b.buf)-len(b.buf) < n { + b.grow(n) + } +} + +// Write appends the contents of p to b's buffer. +// Write always returns len(p), nil. +func (b *Builder) Write(p []byte) (int, error) { + b.copyCheck() + b.buf = append(b.buf, p...) + return len(p), nil +} + +// WriteByte appends the byte c to b's buffer. +// The returned error is always nil. +func (b *Builder) WriteByte(c byte) error { + b.copyCheck() + b.buf = append(b.buf, c) + return nil +} + +// WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. +// It returns the length of r and a nil error. +func (b *Builder) WriteRune(r rune) (int, error) { + b.copyCheck() + if r < utf8.RuneSelf { + b.buf = append(b.buf, byte(r)) + return 1, nil + } + l := len(b.buf) + if cap(b.buf)-l < utf8.UTFMax { + b.grow(utf8.UTFMax) + } + n := utf8.EncodeRune(b.buf[l:l+utf8.UTFMax], r) + b.buf = b.buf[:l+n] + return n, nil +} + +// WriteString appends the contents of s to b's buffer. +// It returns the length of s and a nil error. +func (b *Builder) WriteString(s string) (int, error) { + b.copyCheck() + b.buf = append(b.buf, s...) + return len(s), nil +} diff --git a/vendor/github.com/kamilsk/go-kit/pkg/strings/strings.go b/vendor/github.com/kamilsk/go-kit/pkg/strings/strings.go new file mode 100644 index 0000000..1e550dd --- /dev/null +++ b/vendor/github.com/kamilsk/go-kit/pkg/strings/strings.go @@ -0,0 +1,20 @@ +package strings + +// Concat concatenates all passed strings. +func Concat(strings ...string) string { + b := &Builder{} + for _, str := range strings { + b.WriteString(str) + } + return b.String() +} + +// First returns first non-empty string. +func First(strings ...string) string { + for _, str := range strings { + if str != "" { + return str + } + } + return "" +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/desc.go b/vendor/github.com/prometheus/client_golang/prometheus/desc.go index 4a755b0..e959162 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/desc.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/desc.go @@ -156,7 +156,7 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) * Value: proto.String(v), }) } - sort.Sort(LabelPairSorter(d.constLabelPairs)) + sort.Sort(labelPairSorter(d.constLabelPairs)) return d } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/metric.go b/vendor/github.com/prometheus/client_golang/prometheus/metric.go index 06897f2..bfda075 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/metric.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/metric.go @@ -46,9 +46,8 @@ type Metric interface { // While populating dto.Metric, it is the responsibility of the // implementation to ensure validity of the Metric protobuf (like valid // UTF-8 strings or syntactically valid metric and label names). It is - // recommended to sort labels lexicographically. (Implementers may find - // LabelPairSorter useful for that.) Callers of Write should still make - // sure of sorting if they depend on it. + // recommended to sort labels lexicographically. Callers of Write should + // still make sure of sorting if they depend on it. Write(*dto.Metric) error // TODO(beorn7): The original rationale of passing in a pre-allocated // dto.Metric protobuf to save allocations has disappeared. The @@ -113,20 +112,19 @@ func BuildFQName(namespace, subsystem, name string) string { return name } -// LabelPairSorter implements sort.Interface. It is used to sort a slice of -// dto.LabelPair pointers. This is useful for implementing the Write method of -// custom metrics. -type LabelPairSorter []*dto.LabelPair +// labelPairSorter implements sort.Interface. It is used to sort a slice of +// dto.LabelPair pointers. +type labelPairSorter []*dto.LabelPair -func (s LabelPairSorter) Len() int { +func (s labelPairSorter) Len() int { return len(s) } -func (s LabelPairSorter) Swap(i, j int) { +func (s labelPairSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s LabelPairSorter) Less(i, j int) bool { +func (s labelPairSorter) Less(i, j int) bool { return s[i].GetName() < s[j].GetName() } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/registry.go b/vendor/github.com/prometheus/client_golang/prometheus/registry.go index 79c3dd6..5652850 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/registry.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/registry.go @@ -819,7 +819,7 @@ func checkMetricConsistency( h = hashAddByte(h, separatorByte) // Make sure label pairs are sorted. We depend on it for the consistency // check. - sort.Sort(LabelPairSorter(dtoMetric.Label)) + sort.Sort(labelPairSorter(dtoMetric.Label)) for _, lp := range dtoMetric.Label { h = hashAdd(h, lp.GetName()) h = hashAddByte(h, separatorByte) @@ -863,7 +863,7 @@ func checkDescConsistency( metricFamily.GetName(), dtoMetric, desc, ) } - sort.Sort(LabelPairSorter(lpsFromDesc)) + sort.Sort(labelPairSorter(lpsFromDesc)) for i, lpFromDesc := range lpsFromDesc { lpFromMetric := dtoMetric.Label[i] if lpFromDesc.GetName() != lpFromMetric.GetName() || diff --git a/vendor/github.com/prometheus/client_golang/prometheus/value.go b/vendor/github.com/prometheus/client_golang/prometheus/value.go index 9fb7eab..e066298 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/value.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/value.go @@ -153,6 +153,6 @@ func makeLabelPairs(desc *Desc, labelValues []string) []*dto.LabelPair { }) } labelPairs = append(labelPairs, desc.constLabelPairs...) - sort.Sort(LabelPairSorter(labelPairs)) + sort.Sort(labelPairSorter(labelPairs)) return labelPairs }