diff options
| author | dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> | 2023-07-21 10:41:17 +0000 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2023-07-24 06:24:36 +0000 |
| commit | b03242d7ab98645d2c936e1899aac9f0aeb9813e (patch) | |
| tree | 4f74d0da1ea42a38a125b3a972b44c434b2a38fa /vendor/github.com/prometheus/common/model | |
| parent | f0f7d1e0a67964f4733690290b236755148b8188 (diff) | |
mod: do: bump github.com/prometheus/client_golang from 1.14.0 to 1.16.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.14.0 to 1.16.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.14.0...v1.16.0)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/prometheus/common/model')
4 files changed, 92 insertions, 205 deletions
diff --git a/vendor/github.com/prometheus/common/model/time.go b/vendor/github.com/prometheus/common/model/time.go index c909b8aa8..5727452c1 100644 --- a/vendor/github.com/prometheus/common/model/time.go +++ b/vendor/github.com/prometheus/common/model/time.go @@ -18,7 +18,6 @@ import ( "errors" "fmt" "math" - "regexp" "strconv" "strings" "time" @@ -183,54 +182,78 @@ func (d *Duration) Type() string { return "duration" } -var durationRE = regexp.MustCompile("^(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?$") +func isdigit(c byte) bool { return c >= '0' && c <= '9' } + +// Units are required to go in order from biggest to smallest. +// This guards against confusion from "1m1d" being 1 minute + 1 day, not 1 month + 1 day. +var unitMap = map[string]struct { + pos int + mult uint64 +}{ + "ms": {7, uint64(time.Millisecond)}, + "s": {6, uint64(time.Second)}, + "m": {5, uint64(time.Minute)}, + "h": {4, uint64(time.Hour)}, + "d": {3, uint64(24 * time.Hour)}, + "w": {2, uint64(7 * 24 * time.Hour)}, + "y": {1, uint64(365 * 24 * time.Hour)}, +} // ParseDuration parses a string into a time.Duration, assuming that a year // always has 365d, a week always has 7d, and a day always has 24h. -func ParseDuration(durationStr string) (Duration, error) { - switch durationStr { +func ParseDuration(s string) (Duration, error) { + switch s { case "0": // Allow 0 without a unit. return 0, nil case "": return 0, errors.New("empty duration string") } - matches := durationRE.FindStringSubmatch(durationStr) - if matches == nil { - return 0, fmt.Errorf("not a valid duration string: %q", durationStr) - } - var dur time.Duration - // Parse the match at pos `pos` in the regex and use `mult` to turn that - // into ms, then add that value to the total parsed duration. - var overflowErr error - m := func(pos int, mult time.Duration) { - if matches[pos] == "" { - return + orig := s + var dur uint64 + lastUnitPos := 0 + + for s != "" { + if !isdigit(s[0]) { + return 0, fmt.Errorf("not a valid duration string: %q", orig) + } + // Consume [0-9]* + i := 0 + for ; i < len(s) && isdigit(s[i]); i++ { + } + v, err := strconv.ParseUint(s[:i], 10, 0) + if err != nil { + return 0, fmt.Errorf("not a valid duration string: %q", orig) } - n, _ := strconv.Atoi(matches[pos]) + s = s[i:] + // Consume unit. + for i = 0; i < len(s) && !isdigit(s[i]); i++ { + } + if i == 0 { + return 0, fmt.Errorf("not a valid duration string: %q", orig) + } + u := s[:i] + s = s[i:] + unit, ok := unitMap[u] + if !ok { + return 0, fmt.Errorf("unknown unit %q in duration %q", u, orig) + } + if unit.pos <= lastUnitPos { // Units must go in order from biggest to smallest. + return 0, fmt.Errorf("not a valid duration string: %q", orig) + } + lastUnitPos = unit.pos // Check if the provided duration overflows time.Duration (> ~ 290years). - if n > int((1<<63-1)/mult/time.Millisecond) { - overflowErr = errors.New("duration out of range") + if v > 1<<63/unit.mult { + return 0, errors.New("duration out of range") } - d := time.Duration(n) * time.Millisecond - dur += d * mult - - if dur < 0 { - overflowErr = errors.New("duration out of range") + dur += v * unit.mult + if dur > 1<<63-1 { + return 0, errors.New("duration out of range") } } - - m(2, 1000*60*60*24*365) // y - m(4, 1000*60*60*24*7) // w - m(6, 1000*60*60*24) // d - m(8, 1000*60*60) // h - m(10, 1000*60) // m - m(12, 1000) // s - m(14, 1) // ms - - return Duration(dur), overflowErr + return Duration(dur), nil } func (d Duration) String() string { diff --git a/vendor/github.com/prometheus/common/model/value_float.go b/vendor/github.com/prometheus/common/model/value_float.go index 8b59571a3..0f615a705 100644 --- a/vendor/github.com/prometheus/common/model/value_float.go +++ b/vendor/github.com/prometheus/common/model/value_float.go @@ -18,15 +18,8 @@ import ( "fmt" "math" "strconv" - "unsafe" - - jsoniter "github.com/json-iterator/go" ) -func init() { - jsoniter.RegisterTypeEncoderFunc("model.SamplePair", marshalSamplePairJSON, marshalJSONIsEmpty) -} - var ( // ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a // non-existing sample pair. It is a SamplePair with timestamp Earliest and @@ -78,18 +71,16 @@ type SamplePair struct { Value SampleValue } -// marshalSamplePairJSON writes `[ts, "val"]`. -func marshalSamplePairJSON(ptr unsafe.Pointer, stream *jsoniter.Stream) { - p := *((*SamplePair)(ptr)) - stream.WriteArrayStart() - MarshalTimestamp(int64(p.Timestamp), stream) - stream.WriteMore() - MarshalValue(float64(p.Value), stream) - stream.WriteArrayEnd() -} - func (s SamplePair) MarshalJSON() ([]byte, error) { - return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(s) + t, err := json.Marshal(s.Timestamp) + if err != nil { + return nil, err + } + v, err := json.Marshal(s.Value) + if err != nil { + return nil, err + } + return []byte(fmt.Sprintf("[%s,%s]", t, v)), nil } // UnmarshalJSON implements json.Unmarshaler. diff --git a/vendor/github.com/prometheus/common/model/value_histogram.go b/vendor/github.com/prometheus/common/model/value_histogram.go index cc221a886..54bb038cf 100644 --- a/vendor/github.com/prometheus/common/model/value_histogram.go +++ b/vendor/github.com/prometheus/common/model/value_histogram.go @@ -18,16 +18,8 @@ import ( "fmt" "strconv" "strings" - "unsafe" - - jsoniter "github.com/json-iterator/go" ) -func init() { - jsoniter.RegisterTypeEncoderFunc("model.HistogramBucket", marshalHistogramBucketJSON, marshalJSONIsEmpty) - jsoniter.RegisterTypeEncoderFunc("model.SampleHistogramPair", marshalSampleHistogramPairJSON, marshalJSONIsEmpty) -} - type FloatString float64 func (v FloatString) String() string { @@ -57,10 +49,24 @@ type HistogramBucket struct { Count FloatString } -// marshalHistogramBucketJSON writes fmt.Sprintf("[%s,%s,%s,%s]", b.Boundaries, b.Lower, b.Upper, b.Count). -func marshalHistogramBucketJSON(ptr unsafe.Pointer, stream *jsoniter.Stream) { - b := *((*HistogramBucket)(ptr)) - MarshalHistogramBucket(b, stream) +func (s HistogramBucket) MarshalJSON() ([]byte, error) { + b, err := json.Marshal(s.Boundaries) + if err != nil { + return nil, err + } + l, err := json.Marshal(s.Lower) + if err != nil { + return nil, err + } + u, err := json.Marshal(s.Upper) + if err != nil { + return nil, err + } + c, err := json.Marshal(s.Count) + if err != nil { + return nil, err + } + return []byte(fmt.Sprintf("[%s,%s,%s,%s]", b, l, u, c)), nil } func (s *HistogramBucket) UnmarshalJSON(buf []byte) error { @@ -133,21 +139,19 @@ type SampleHistogramPair struct { Histogram *SampleHistogram } -// marshalSampleHistogramPairJSON writes `[ts, "val"]`. -func marshalSampleHistogramPairJSON(ptr unsafe.Pointer, stream *jsoniter.Stream) { - p := *((*SampleHistogramPair)(ptr)) - stream.WriteArrayStart() - MarshalTimestamp(int64(p.Timestamp), stream) - stream.WriteMore() - MarshalHistogram(*p.Histogram, stream) - stream.WriteArrayEnd() -} - func (s SampleHistogramPair) MarshalJSON() ([]byte, error) { if s.Histogram == nil { return nil, fmt.Errorf("histogram is nil") } - return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(s) + t, err := json.Marshal(s.Timestamp) + if err != nil { + return nil, err + } + v, err := json.Marshal(s.Histogram) + if err != nil { + return nil, err + } + return []byte(fmt.Sprintf("[%s,%s]", t, v)), nil } func (s *SampleHistogramPair) UnmarshalJSON(buf []byte) error { diff --git a/vendor/github.com/prometheus/common/model/value_marshal.go b/vendor/github.com/prometheus/common/model/value_marshal.go deleted file mode 100644 index df193bcb3..000000000 --- a/vendor/github.com/prometheus/common/model/value_marshal.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2013 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package model - -import ( - "math" - "strconv" - "unsafe" - - jsoniter "github.com/json-iterator/go" -) - -func marshalJSONIsEmpty(ptr unsafe.Pointer) bool { - return false -} - -// MarshalTimestamp marshals a point timestamp using the passed jsoniter stream. -func MarshalTimestamp(t int64, stream *jsoniter.Stream) { - // Write out the timestamp as a float divided by 1000. - // This is ~3x faster than converting to a float. - if t < 0 { - stream.WriteRaw(`-`) - t = -t - } - stream.WriteInt64(t / 1000) - fraction := t % 1000 - if fraction != 0 { - stream.WriteRaw(`.`) - if fraction < 100 { - stream.WriteRaw(`0`) - } - if fraction < 10 { - stream.WriteRaw(`0`) - } - stream.WriteInt64(fraction) - } -} - -// MarshalValue marshals a point value using the passed jsoniter stream. -func MarshalValue(v float64, stream *jsoniter.Stream) { - stream.WriteRaw(`"`) - // Taken from https://github.com/json-iterator/go/blob/master/stream_float.go#L71 as a workaround - // to https://github.com/json-iterator/go/issues/365 (jsoniter, to follow json standard, doesn't allow inf/nan). - buf := stream.Buffer() - abs := math.Abs(v) - fmt := byte('f') - // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. - if abs != 0 { - if abs < 1e-6 || abs >= 1e21 { - fmt = 'e' - } - } - buf = strconv.AppendFloat(buf, v, fmt, -1, 64) - stream.SetBuffer(buf) - stream.WriteRaw(`"`) -} - -// MarshalHistogramBucket writes something like: [ 3, "-0.25", "0.25", "3"] -// See MarshalHistogram to understand what the numbers mean -func MarshalHistogramBucket(b HistogramBucket, stream *jsoniter.Stream) { - stream.WriteArrayStart() - stream.WriteInt32(b.Boundaries) - stream.WriteMore() - MarshalValue(float64(b.Lower), stream) - stream.WriteMore() - MarshalValue(float64(b.Upper), stream) - stream.WriteMore() - MarshalValue(float64(b.Count), stream) - stream.WriteArrayEnd() -} - -// MarshalHistogram writes something like: -// -// { -// "count": "42", -// "sum": "34593.34", -// "buckets": [ -// [ 3, "-0.25", "0.25", "3"], -// [ 0, "0.25", "0.5", "12"], -// [ 0, "0.5", "1", "21"], -// [ 0, "2", "4", "6"] -// ] -// } -// -// The 1st element in each bucket array determines if the boundaries are -// inclusive (AKA closed) or exclusive (AKA open): -// -// 0: lower exclusive, upper inclusive -// 1: lower inclusive, upper exclusive -// 2: both exclusive -// 3: both inclusive -// -// The 2nd and 3rd elements are the lower and upper boundary. The 4th element is -// the bucket count. -func MarshalHistogram(h SampleHistogram, stream *jsoniter.Stream) { - stream.WriteObjectStart() - stream.WriteObjectField(`count`) - MarshalValue(float64(h.Count), stream) - stream.WriteMore() - stream.WriteObjectField(`sum`) - MarshalValue(float64(h.Sum), stream) - - bucketFound := false - for _, bucket := range h.Buckets { - if bucket.Count == 0 { - continue // No need to expose empty buckets in JSON. - } - stream.WriteMore() - if !bucketFound { - stream.WriteObjectField(`buckets`) - stream.WriteArrayStart() - } - bucketFound = true - MarshalHistogramBucket(*bucket, stream) - } - if bucketFound { - stream.WriteArrayEnd() - } - stream.WriteObjectEnd() -} |
