Update common/* package vendoring
This commit is contained in:
parent
5d96e6cb6d
commit
943faa704f
|
@ -18,7 +18,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Matcher describes a matches the value of a given label.
|
// Matcher describes a matches the value of a given label.
|
||||||
|
@ -54,7 +53,7 @@ func (m *Matcher) Validate() error {
|
||||||
if _, err := regexp.Compile(m.Value); err != nil {
|
if _, err := regexp.Compile(m.Value); err != nil {
|
||||||
return fmt.Errorf("invalid regular expression %q", m.Value)
|
return fmt.Errorf("invalid regular expression %q", m.Value)
|
||||||
}
|
}
|
||||||
} else if !utf8.ValidString(m.Value) || len(m.Value) == 0 {
|
} else if !LabelValue(m.Value).IsValid() || len(m.Value) == 0 {
|
||||||
return fmt.Errorf("invalid value %q", m.Value)
|
return fmt.Errorf("invalid value %q", m.Value)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -163,6 +163,8 @@ func (t *Time) UnmarshalJSON(b []byte) error {
|
||||||
// This type should not propagate beyond the scope of input/output processing.
|
// This type should not propagate beyond the scope of input/output processing.
|
||||||
type Duration time.Duration
|
type Duration time.Duration
|
||||||
|
|
||||||
|
var durationRE = regexp.MustCompile("^([0-9]+)(d|h|m|s|ms)$")
|
||||||
|
|
||||||
// StringToDuration parses a string into a time.Duration, assuming that a year
|
// StringToDuration parses a string into a time.Duration, assuming that a year
|
||||||
// a day always has 24h.
|
// a day always has 24h.
|
||||||
func ParseDuration(durationStr string) (Duration, error) {
|
func ParseDuration(durationStr string) (Duration, error) {
|
||||||
|
@ -170,44 +172,51 @@ func ParseDuration(durationStr string) (Duration, error) {
|
||||||
if len(matches) != 3 {
|
if len(matches) != 3 {
|
||||||
return 0, fmt.Errorf("not a valid duration string: %q", durationStr)
|
return 0, fmt.Errorf("not a valid duration string: %q", durationStr)
|
||||||
}
|
}
|
||||||
durSeconds, _ := strconv.Atoi(matches[1])
|
var (
|
||||||
dur := time.Duration(durSeconds) * time.Second
|
n, _ = strconv.Atoi(matches[1])
|
||||||
unit := matches[2]
|
dur = time.Duration(n) * time.Millisecond
|
||||||
switch unit {
|
)
|
||||||
|
switch unit := matches[2]; unit {
|
||||||
case "d":
|
case "d":
|
||||||
dur *= 60 * 60 * 24
|
dur *= 1000 * 60 * 60 * 24
|
||||||
case "h":
|
case "h":
|
||||||
dur *= 60 * 60
|
dur *= 1000 * 60 * 60
|
||||||
case "m":
|
case "m":
|
||||||
dur *= 60
|
dur *= 1000 * 60
|
||||||
case "s":
|
case "s":
|
||||||
dur *= 1
|
dur *= 1000
|
||||||
|
case "ms":
|
||||||
|
// Value already correct
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("invalid time unit in duration string: %q", unit)
|
return 0, fmt.Errorf("invalid time unit in duration string: %q", unit)
|
||||||
}
|
}
|
||||||
return Duration(dur), nil
|
return Duration(dur), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var durationRE = regexp.MustCompile("^([0-9]+)([ywdhms]+)$")
|
|
||||||
|
|
||||||
func (d Duration) String() string {
|
func (d Duration) String() string {
|
||||||
seconds := int64(time.Duration(d) / time.Second)
|
var (
|
||||||
|
ms = int64(time.Duration(d) / time.Millisecond)
|
||||||
|
unit = "ms"
|
||||||
|
)
|
||||||
factors := map[string]int64{
|
factors := map[string]int64{
|
||||||
"d": 60 * 60 * 24,
|
"d": 1000 * 60 * 60 * 24,
|
||||||
"h": 60 * 60,
|
"h": 1000 * 60 * 60,
|
||||||
"m": 60,
|
"m": 1000 * 60,
|
||||||
"s": 1,
|
"s": 1000,
|
||||||
|
"ms": 1,
|
||||||
}
|
}
|
||||||
unit := "s"
|
|
||||||
switch int64(0) {
|
switch int64(0) {
|
||||||
case seconds % factors["d"]:
|
case ms % factors["d"]:
|
||||||
unit = "d"
|
unit = "d"
|
||||||
case seconds % factors["h"]:
|
case ms % factors["h"]:
|
||||||
unit = "h"
|
unit = "h"
|
||||||
case seconds % factors["m"]:
|
case ms % factors["m"]:
|
||||||
unit = "m"
|
unit = "m"
|
||||||
|
case ms % factors["s"]:
|
||||||
|
unit = "s"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%v%v", seconds/factors[unit], unit)
|
return fmt.Sprintf("%v%v", ms/factors[unit], unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalYAML implements the yaml.Marshaler interface.
|
// MarshalYAML implements the yaml.Marshaler interface.
|
||||||
|
|
|
@ -75,6 +75,11 @@ func (r *Router) Get(path string, h http.HandlerFunc) {
|
||||||
r.rtr.GET(r.prefix+path, handle(h))
|
r.rtr.GET(r.prefix+path, handle(h))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Options registers a new OPTIONS route.
|
||||||
|
func (r *Router) Options(path string, h http.HandlerFunc) {
|
||||||
|
r.rtr.OPTIONS(r.prefix+path, handle(h))
|
||||||
|
}
|
||||||
|
|
||||||
// Del registers a new DELETE route.
|
// Del registers a new DELETE route.
|
||||||
func (r *Router) Del(path string, h http.HandlerFunc) {
|
func (r *Router) Del(path string, h http.HandlerFunc) {
|
||||||
r.rtr.DELETE(r.prefix+path, handle(h))
|
r.rtr.DELETE(r.prefix+path, handle(h))
|
||||||
|
|
|
@ -69,13 +69,13 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "github.com/prometheus/common/model",
|
"path": "github.com/prometheus/common/model",
|
||||||
"revision": "56b90312e937d43b930f06a59bf0d6a4ae1944bc",
|
"revision": "14ca1097bbe21584194c15e391a9dab95ad42a59",
|
||||||
"revisionTime": "2015-12-09T21:44:25+01:00"
|
"revisionTime": "2016-01-25T23:57:51+01:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "github.com/prometheus/common/route",
|
"path": "github.com/prometheus/common/route",
|
||||||
"revision": "210d6543ee217ec38b676a40549af1df9431d80d",
|
"revision": "14ca1097bbe21584194c15e391a9dab95ad42a59",
|
||||||
"revisionTime": "2015-09-28T11:56:39+02:00"
|
"revisionTime": "2016-01-25T23:57:51+01:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "github.com/prometheus/procfs",
|
"path": "github.com/prometheus/procfs",
|
||||||
|
|
Loading…
Reference in New Issue