update prometheus dependencies (#5520)

Signed-off-by: junot <junotxiang@kubesphere.io>
This commit is contained in:
junot
2023-02-14 09:46:22 +08:00
committed by GitHub
parent a979342f56
commit 2cd5f45d47
769 changed files with 81283 additions and 30511 deletions

2
vendor/github.com/go-openapi/strfmt/.gitattributes generated vendored Normal file
View File

@@ -0,0 +1,2 @@
*.go text eol=lf

View File

@@ -25,6 +25,20 @@ linters:
- whitespace
- wsl
- funlen
- wrapcheck
- testpackage
- nlreturn
- gofumpt
- goerr113
- gci
- gomnd
- godot
- exhaustivestruct
- paralleltest
- varnamelen
- ireturn
- exhaustruct
#- thelper
issues:
exclude-rules:

View File

@@ -1,15 +0,0 @@
after_success:
- bash <(curl -s https://codecov.io/bash)
go:
- 1.11.x
- 1.12.x
install:
- GO111MODULE=off go get -u gotest.tools/gotestsum
language: go
env:
- GO111MODULE=on
notifications:
slack:
secure: zE5AtIYTpYfQPnTzP+EaQPN7JKtfFAGv6PrJqoIZLOXa8B6zGb6+J1JRNNxWi7faWbyJOxa4FSSsuPsKZMycUK6wlLFIdhDxwqeo7Ew8r6rdZKdfUHQggfNS9wO79ARoNYUDHtmnaBUS+eWSM1YqSc4i99QxyyfuURLOeAaA/q14YbdlTlaw3lrZ0qT92ot1FnVGNOx064zuHtFeUf+jAVRMZ6Q3rvqllwIlPszE6rmHGXBt2VoJxRaBetdwd7FgkcYw9FPXKHhadwC7/75ZAdmxIukhxNMw4Tr5NuPcqNcnbYLenDP7B3lssGVIrP4BRSqekS1d/tqvdvnnFWHMwrNCkSnSc065G5+qWTlXKAemIclgiXXqE2furBNLm05MDdG8fn5epS0UNarkjD+zX336RiqwBlOX4KbF+vPyqcO98CsN0lnd+H6loc9reiTHs37orFFpQ+309av9be2GGsHUsRB9ssIyrewmhAccOmkRtr2dVTZJNFQwa5Kph5TNJuTjnZEwG/xUkEX2YSfwShOsb062JWiflV6PJdnl80pc9Tn7D5sO5Bf9DbijGRJwwP+YiiJtwtr+vsvS+n4sM0b5eqm4UoRo+JJO8ffoJtHS7ItuyRbVQCwEPJ4221WLcf5PquEEDdAPwR+K4Gj8qTXqTDdxOiES1xFUKVgmzhI=
script:
- gotestsum -f short-verbose -- -race -coverprofile=coverage.txt -covermode=atomic ./...

View File

@@ -38,6 +38,7 @@ It also provides convenient extensions to go-openapi users.
- ssn
- uuid, uuid3, uuid4, uuid5
- cidr (e.g. "192.0.2.1/24", "2001:db8:a0b:12f0::1/32")
- ulid (e.g. "00000PP9HGSBSSDZ1JTEXBJ0PW", [spec](https://github.com/ulid/spec))
> NOTE: as the name stands for, this package is intended to support string formatting only.
> It does not provide validation for numerical values with swagger format extension for JSON types "number" or
@@ -84,3 +85,4 @@ List of defined types:
- UUID3
- UUID4
- UUID5
- [ULID](https://github.com/ulid/spec)

View File

@@ -39,10 +39,10 @@ func IsBSONObjectID(str string) bool {
// ObjectId represents a BSON object ID (alias to go.mongodb.org/mongo-driver/bson/primitive.ObjectID)
//
// swagger:strfmt bsonobjectid
type ObjectId bsonprim.ObjectID
type ObjectId bsonprim.ObjectID //nolint:revive
// NewObjectId creates a ObjectId from a Hex String
func NewObjectId(hex string) ObjectId {
func NewObjectId(hex string) ObjectId { //nolint:revive
oid, err := bsonprim.ObjectIDFromHex(hex)
if err != nil {
panic(err)
@@ -95,7 +95,7 @@ func (id ObjectId) Value() (driver.Value, error) {
}
func (id ObjectId) String() string {
return bsonprim.ObjectID(id).String()
return bsonprim.ObjectID(id).Hex()
}
// MarshalJSON returns the ObjectId as JSON

View File

@@ -180,3 +180,8 @@ func (d *Date) UnmarshalBinary(data []byte) error {
return nil
}
// Equal checks if two Date instances are equal
func (d Date) Equal(d2 Date) bool {
return time.Time(d).Equal(time.Time(d2))
}

View File

@@ -65,7 +65,7 @@ type NameNormalizer func(string) string
// DefaultNameNormalizer removes all dashes
func DefaultNameNormalizer(name string) string {
return strings.Replace(name, "-", "", -1)
return strings.ReplaceAll(name, "-", "")
}
type defaultFormats struct {
@@ -76,6 +76,7 @@ type defaultFormats struct {
// NewFormats creates a new formats registry seeded with the values from the default
func NewFormats() Registry {
//nolint:forcetypeassert
return NewSeededFormats(Default.(*defaultFormats).data, nil)
}
@@ -93,73 +94,84 @@ func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
}
// MapStructureHookFunc is a decode hook function for mapstructure
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc {
return func(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error) {
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc { //nolint:gocyclo,cyclop
return func(from reflect.Type, to reflect.Type, obj interface{}) (interface{}, error) {
if from.Kind() != reflect.String {
return data, nil
return obj, nil
}
data, ok := obj.(string)
if !ok {
return nil, fmt.Errorf("failed to cast %+v to string", obj)
}
for _, v := range f.data {
tpe, _ := f.GetType(v.Name)
if to == tpe {
switch v.Name {
case "date":
d, err := time.Parse(RFC3339FullDate, data.(string))
d, err := time.Parse(RFC3339FullDate, data)
if err != nil {
return nil, err
}
return Date(d), nil
case "datetime":
input := data.(string)
input := data
if len(input) == 0 {
return nil, fmt.Errorf("empty string is an invalid datetime format")
}
return ParseDateTime(input)
case "duration":
dur, err := ParseDuration(data.(string))
dur, err := ParseDuration(data)
if err != nil {
return nil, err
}
return Duration(dur), nil
case "uri":
return URI(data.(string)), nil
return URI(data), nil
case "email":
return Email(data.(string)), nil
return Email(data), nil
case "uuid":
return UUID(data.(string)), nil
return UUID(data), nil
case "uuid3":
return UUID3(data.(string)), nil
return UUID3(data), nil
case "uuid4":
return UUID4(data.(string)), nil
return UUID4(data), nil
case "uuid5":
return UUID5(data.(string)), nil
return UUID5(data), nil
case "hostname":
return Hostname(data.(string)), nil
return Hostname(data), nil
case "ipv4":
return IPv4(data.(string)), nil
return IPv4(data), nil
case "ipv6":
return IPv6(data.(string)), nil
return IPv6(data), nil
case "cidr":
return CIDR(data.(string)), nil
return CIDR(data), nil
case "mac":
return MAC(data.(string)), nil
return MAC(data), nil
case "isbn":
return ISBN(data.(string)), nil
return ISBN(data), nil
case "isbn10":
return ISBN10(data.(string)), nil
return ISBN10(data), nil
case "isbn13":
return ISBN13(data.(string)), nil
return ISBN13(data), nil
case "creditcard":
return CreditCard(data.(string)), nil
return CreditCard(data), nil
case "ssn":
return SSN(data.(string)), nil
return SSN(data), nil
case "hexcolor":
return HexColor(data.(string)), nil
return HexColor(data), nil
case "rgbcolor":
return RGBColor(data.(string)), nil
return RGBColor(data), nil
case "byte":
return Base64(data.(string)), nil
return Base64(data), nil
case "password":
return Password(data.(string)), nil
return Password(data), nil
case "ulid":
ulid, err := ParseULID(data)
if err != nil {
return nil, err
}
return ulid, nil
default:
return nil, errors.InvalidTypeName(v.Name)
}

View File

@@ -18,6 +18,7 @@ import (
"database/sql/driver"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"regexp"
"strings"
@@ -55,23 +56,36 @@ func IsDateTime(str string) bool {
const (
// RFC3339Millis represents a ISO8601 format to millis instead of to nanos
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
// RFC3339MillisNoColon represents a ISO8601 format to millis instead of to nanos
RFC3339MillisNoColon = "2006-01-02T15:04:05.000Z0700"
// RFC3339Micro represents a ISO8601 format to micro instead of to nano
RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
// RFC3339MicroNoColon represents a ISO8601 format to micro instead of to nano
RFC3339MicroNoColon = "2006-01-02T15:04:05.000000Z0700"
// ISO8601LocalTime represents a ISO8601 format to ISO8601 in local time (no timezone)
ISO8601LocalTime = "2006-01-02T15:04:05"
// ISO8601TimeWithReducedPrecision represents a ISO8601 format with reduced precision (dropped secs)
ISO8601TimeWithReducedPrecision = "2006-01-02T15:04Z"
// ISO8601TimeWithReducedPrecision represents a ISO8601 format with reduced precision and no timezone (dropped seconds + no timezone)
// ISO8601TimeWithReducedPrecisionLocaltime represents a ISO8601 format with reduced precision and no timezone (dropped seconds + no timezone)
ISO8601TimeWithReducedPrecisionLocaltime = "2006-01-02T15:04"
// ISO8601TimeUniversalSortableDateTimePattern represents a ISO8601 universal sortable date time pattern.
ISO8601TimeUniversalSortableDateTimePattern = "2006-01-02 15:04:05"
// DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6
DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$`
)
var (
dateTimeFormats = []string{RFC3339Micro, RFC3339Millis, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime, ISO8601TimeWithReducedPrecision, ISO8601TimeWithReducedPrecisionLocaltime}
rxDateTime = regexp.MustCompile(DateTimePattern)
rxDateTime = regexp.MustCompile(DateTimePattern)
// DateTimeFormats is the collection of formats used by ParseDateTime()
DateTimeFormats = []string{RFC3339Micro, RFC3339MicroNoColon, RFC3339Millis, RFC3339MillisNoColon, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime, ISO8601TimeWithReducedPrecision, ISO8601TimeWithReducedPrecisionLocaltime, ISO8601TimeUniversalSortableDateTimePattern}
// MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds)
MarshalFormat = RFC3339Millis
// NormalizeTimeForMarshal provides a normalization function on time befeore marshalling (e.g. time.UTC).
// By default, the time value is not changed.
NormalizeTimeForMarshal = func(t time.Time) time.Time { return t }
)
// ParseDateTime parses a string that represents an ISO8601 time or a unix epoch
@@ -80,7 +94,7 @@ func ParseDateTime(data string) (DateTime, error) {
return NewDateTime(), nil
}
var lastError error
for _, layout := range dateTimeFormats {
for _, layout := range DateTimeFormats {
dd, err := time.Parse(layout, data)
if err != nil {
lastError = err
@@ -106,7 +120,7 @@ func NewDateTime() DateTime {
// String converts this time to a string
func (t DateTime) String() string {
return time.Time(t).Format(MarshalFormat)
return NormalizeTimeForMarshal(time.Time(t)).Format(MarshalFormat)
}
// MarshalText implements the text marshaller interface
@@ -150,7 +164,7 @@ func (t DateTime) Value() (driver.Value, error) {
// MarshalJSON returns the DateTime as JSON
func (t DateTime) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Time(t).Format(MarshalFormat))
return json.Marshal(NormalizeTimeForMarshal(time.Time(t)).Format(MarshalFormat))
}
// UnmarshalJSON sets the DateTime from JSON
@@ -197,9 +211,12 @@ func (t *DateTime) UnmarshalBSON(data []byte) error {
// Marshals a DateTime as a bsontype.DateTime, an int64 representing
// milliseconds since epoch.
func (t DateTime) MarshalBSONValue() (bsontype.Type, []byte, error) {
// UnixNano cannot be used, the result of calling UnixNano on the zero
// Time is undefined.
i64 := time.Time(t).Unix() * 1000
// UnixNano cannot be used directly, the result of calling UnixNano on the zero
// Time is undefined. Thats why we use time.Nanosecond() instead.
tNorm := NormalizeTimeForMarshal(time.Time(t))
i64 := tNorm.Unix()*1000 + int64(tNorm.Nanosecond())/1e6
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(i64))
@@ -211,6 +228,15 @@ func (t DateTime) MarshalBSONValue() (bsontype.Type, []byte, error) {
// assumed to be valid. UnmarshalBSONValue must copy the BSON value bytes if it
// wishes to retain the data after returning.
func (t *DateTime) UnmarshalBSONValue(tpe bsontype.Type, data []byte) error {
if tpe == bsontype.Null {
*t = DateTime{}
return nil
}
if len(data) != 8 {
return errors.New("bson date field length not exactly 8 bytes")
}
i64 := int64(binary.LittleEndian.Uint64(data))
// TODO: Use bsonprim.DateTime.Time() method
*t = DateTime(time.Unix(i64/1000, i64%1000*1000000))
@@ -245,7 +271,7 @@ func (t *DateTime) GobDecode(data []byte) error {
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (t DateTime) MarshalBinary() ([]byte, error) {
return time.Time(t).MarshalBinary()
return NormalizeTimeForMarshal(time.Time(t)).MarshalBinary()
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
@@ -261,3 +287,8 @@ func (t *DateTime) UnmarshalBinary(data []byte) error {
return nil
}
// Equal checks if two DateTime instances are equal using time.Time's Equal method
func (t DateTime) Equal(t2 DateTime) bool {
return time.Time(t).Equal(time.Time(t2))
}

225
vendor/github.com/go-openapi/strfmt/ulid.go generated vendored Normal file
View File

@@ -0,0 +1,225 @@
package strfmt
import (
cryptorand "crypto/rand"
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"io"
"sync"
"github.com/oklog/ulid"
"go.mongodb.org/mongo-driver/bson"
)
// ULID represents a ulid string format
// ref:
// https://github.com/ulid/spec
// impl:
// https://github.com/oklog/ulid
//
// swagger:strfmt ulid
type ULID struct {
ulid.ULID
}
var (
ulidEntropyPool = sync.Pool{
New: func() interface{} {
return cryptorand.Reader
},
}
ULIDScanDefaultFunc = func(raw interface{}) (ULID, error) {
u := NewULIDZero()
switch x := raw.(type) {
case nil:
// zerp ulid
return u, nil
case string:
if x == "" {
// zero ulid
return u, nil
}
return u, u.UnmarshalText([]byte(x))
case []byte:
return u, u.UnmarshalText(x)
}
return u, fmt.Errorf("cannot sql.Scan() strfmt.ULID from: %#v: %w", raw, ulid.ErrScanValue)
}
// ULIDScanOverrideFunc allows you to override the Scan method of the ULID type
ULIDScanOverrideFunc = ULIDScanDefaultFunc
ULIDValueDefaultFunc = func(u ULID) (driver.Value, error) {
return driver.Value(u.String()), nil
}
// ULIDValueOverrideFunc allows you to override the Value method of the ULID type
ULIDValueOverrideFunc = ULIDValueDefaultFunc
)
func init() {
// register formats in the default registry:
// - ulid
ulid := ULID{}
Default.Add("ulid", &ulid, IsULID)
}
// IsULID checks if provided string is ULID format
// Be noticed that this function considers overflowed ULID as non-ulid.
// For more details see https://github.com/ulid/spec
func IsULID(str string) bool {
_, err := ulid.ParseStrict(str)
return err == nil
}
// ParseULID parses a string that represents an valid ULID
func ParseULID(str string) (ULID, error) {
var u ULID
return u, u.UnmarshalText([]byte(str))
}
// NewULIDZero returns a zero valued ULID type
func NewULIDZero() ULID {
return ULID{}
}
// NewULID generates new unique ULID value and a error if any
func NewULID() (u ULID, err error) {
obj := ulidEntropyPool.Get()
entropy, ok := obj.(io.Reader)
if !ok {
return u, fmt.Errorf("failed to cast %+v to io.Reader", obj)
}
id, err := ulid.New(ulid.Now(), entropy)
if err != nil {
return u, err
}
ulidEntropyPool.Put(entropy)
u.ULID = id
return u, nil
}
// GetULID returns underlying instance of ULID
func (u *ULID) GetULID() interface{} {
return u.ULID
}
// MarshalText returns this instance into text
func (u ULID) MarshalText() ([]byte, error) {
return u.ULID.MarshalText()
}
// UnmarshalText hydrates this instance from text
func (u *ULID) UnmarshalText(data []byte) error { // validation is performed later on
return u.ULID.UnmarshalText(data)
}
// Scan reads a value from a database driver
func (u *ULID) Scan(raw interface{}) error {
ul, err := ULIDScanOverrideFunc(raw)
if err == nil {
*u = ul
}
return err
}
// Value converts a value to a database driver value
func (u ULID) Value() (driver.Value, error) {
return ULIDValueOverrideFunc(u)
}
func (u ULID) String() string {
return u.ULID.String()
}
// MarshalJSON returns the ULID as JSON
func (u ULID) MarshalJSON() ([]byte, error) {
return json.Marshal(u.String())
}
// UnmarshalJSON sets the ULID from JSON
func (u *ULID) UnmarshalJSON(data []byte) error {
if string(data) == jsonNull {
return nil
}
var ustr string
if err := json.Unmarshal(data, &ustr); err != nil {
return err
}
id, err := ulid.ParseStrict(ustr)
if err != nil {
return fmt.Errorf("couldn't parse JSON value as ULID: %w", err)
}
u.ULID = id
return nil
}
// MarshalBSON document from this value
func (u ULID) MarshalBSON() ([]byte, error) {
return bson.Marshal(bson.M{"data": u.String()})
}
// UnmarshalBSON document into this value
func (u *ULID) UnmarshalBSON(data []byte) error {
var m bson.M
if err := bson.Unmarshal(data, &m); err != nil {
return err
}
if ud, ok := m["data"].(string); ok {
id, err := ulid.ParseStrict(ud)
if err != nil {
return fmt.Errorf("couldn't parse bson bytes as ULID: %w", err)
}
u.ULID = id
return nil
}
return errors.New("couldn't unmarshal bson bytes as ULID")
}
// DeepCopyInto copies the receiver and writes its value into out.
func (u *ULID) DeepCopyInto(out *ULID) {
*out = *u
}
// DeepCopy copies the receiver into a new ULID.
func (u *ULID) DeepCopy() *ULID {
if u == nil {
return nil
}
out := new(ULID)
u.DeepCopyInto(out)
return out
}
// GobEncode implements the gob.GobEncoder interface.
func (u ULID) GobEncode() ([]byte, error) {
return u.ULID.MarshalBinary()
}
// GobDecode implements the gob.GobDecoder interface.
func (u *ULID) GobDecode(data []byte) error {
return u.ULID.UnmarshalBinary(data)
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (u ULID) MarshalBinary() ([]byte, error) {
return u.ULID.MarshalBinary()
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (u *ULID) UnmarshalBinary(data []byte) error {
return u.ULID.UnmarshalBinary(data)
}
// Equal checks if two ULID instances are equal by their underlying type
func (u ULID) Equal(other ULID) bool {
return u.ULID == other.ULID
}