Merge pull request #2327 from prometheus/beorn7/vendoring

vendoring: Update prometheus/common to pull in bug fixes
pull/2331/head
Björn Rabenstein 8 years ago committed by GitHub
commit 6ce97837ab

@ -31,6 +31,7 @@ type Decoder interface {
Decode(*dto.MetricFamily) error Decode(*dto.MetricFamily) error
} }
// DecodeOptions contains options used by the Decoder and in sample extraction.
type DecodeOptions struct { type DecodeOptions struct {
// Timestamp is added to each value from the stream that has no explicit timestamp set. // Timestamp is added to each value from the stream that has no explicit timestamp set.
Timestamp model.Time Timestamp model.Time
@ -142,6 +143,8 @@ func (d *textDecoder) Decode(v *dto.MetricFamily) error {
return nil return nil
} }
// SampleDecoder wraps a Decoder to extract samples from the metric families
// decoded by the wrapped Decoder.
type SampleDecoder struct { type SampleDecoder struct {
Dec Decoder Dec Decoder
Opts *DecodeOptions Opts *DecodeOptions
@ -149,37 +152,51 @@ type SampleDecoder struct {
f dto.MetricFamily f dto.MetricFamily
} }
// Decode calls the Decode method of the wrapped Decoder and then extracts the
// samples from the decoded MetricFamily into the provided model.Vector.
func (sd *SampleDecoder) Decode(s *model.Vector) error { func (sd *SampleDecoder) Decode(s *model.Vector) error {
if err := sd.Dec.Decode(&sd.f); err != nil { err := sd.Dec.Decode(&sd.f)
if err != nil {
return err return err
} }
*s = extractSamples(&sd.f, sd.Opts) *s, err = extractSamples(&sd.f, sd.Opts)
return nil return err
} }
// Extract samples builds a slice of samples from the provided metric families. // ExtractSamples builds a slice of samples from the provided metric
func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) model.Vector { // families. If an error occurs during sample extraction, it continues to
var all model.Vector // extract from the remaining metric families. The returned error is the last
// error that has occured.
func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) (model.Vector, error) {
var (
all model.Vector
lastErr error
)
for _, f := range fams { for _, f := range fams {
all = append(all, extractSamples(f, o)...) some, err := extractSamples(f, o)
if err != nil {
lastErr = err
continue
}
all = append(all, some...)
} }
return all return all, lastErr
} }
func extractSamples(f *dto.MetricFamily, o *DecodeOptions) model.Vector { func extractSamples(f *dto.MetricFamily, o *DecodeOptions) (model.Vector, error) {
switch f.GetType() { switch f.GetType() {
case dto.MetricType_COUNTER: case dto.MetricType_COUNTER:
return extractCounter(o, f) return extractCounter(o, f), nil
case dto.MetricType_GAUGE: case dto.MetricType_GAUGE:
return extractGauge(o, f) return extractGauge(o, f), nil
case dto.MetricType_SUMMARY: case dto.MetricType_SUMMARY:
return extractSummary(o, f) return extractSummary(o, f), nil
case dto.MetricType_UNTYPED: case dto.MetricType_UNTYPED:
return extractUntyped(o, f) return extractUntyped(o, f), nil
case dto.MetricType_HISTOGRAM: case dto.MetricType_HISTOGRAM:
return extractHistogram(o, f) return extractHistogram(o, f), nil
} }
panic("expfmt.extractSamples: unknown metric family type") return nil, fmt.Errorf("expfmt.extractSamples: unknown metric family type %v", f.GetType())
} }
func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector { func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector {

@ -11,14 +11,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// A package for reading and writing Prometheus metrics. // Package expfmt contains tools for reading and writing Prometheus metrics.
package expfmt package expfmt
// Format specifies the HTTP content type of the different wire protocols.
type Format string type Format string
// Constants to assemble the Content-Type values for the different wire protocols.
const ( const (
TextVersion = "0.0.4" TextVersion = "0.0.4"
ProtoType = `application/vnd.google.protobuf` ProtoType = `application/vnd.google.protobuf`
ProtoProtocol = `io.prometheus.client.MetricFamily` ProtoProtocol = `io.prometheus.client.MetricFamily`
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";" ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"

@ -23,6 +23,8 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
) )
var _ logrus.Formatter = (*syslogger)(nil)
func init() { func init() {
setSyslogFormatter = func(appname, local string) error { setSyslogFormatter = func(appname, local string) error {
if appname == "" { if appname == "" {
@ -43,7 +45,7 @@ func init() {
} }
} }
var ceeTag = []byte("@cee:") var prefixTag []byte
type syslogger struct { type syslogger struct {
wrap logrus.Formatter wrap logrus.Formatter
@ -56,6 +58,11 @@ func newSyslogger(appname string, facility string, fmter logrus.Formatter) (*sys
return nil, err return nil, err
} }
out, err := syslog.New(priority, appname) out, err := syslog.New(priority, appname)
_, isJSON := fmter.(*logrus.JSONFormatter)
if isJSON {
// add cee tag to json formatted syslogs
prefixTag = []byte("@cee:")
}
return &syslogger{ return &syslogger{
out: out, out: out,
wrap: fmter, wrap: fmter,
@ -92,7 +99,7 @@ func (s *syslogger) Format(e *logrus.Entry) ([]byte, error) {
} }
// only append tag to data sent to syslog (line), not to what // only append tag to data sent to syslog (line), not to what
// is returned // is returned
line := string(append(ceeTag, data...)) line := string(append(prefixTag, data...))
switch e.Level { switch e.Level {
case logrus.PanicLevel: case logrus.PanicLevel:

@ -80,14 +80,18 @@ const (
QuantileLabel = "quantile" QuantileLabel = "quantile"
) )
// LabelNameRE is a regular expression matching valid label names. // LabelNameRE is a regular expression matching valid label names. Note that the
// IsValid method of LabelName performs the same check but faster than a match
// with this regular expression.
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$") var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
// A LabelName is a key for a LabelSet or Metric. It has a value associated // A LabelName is a key for a LabelSet or Metric. It has a value associated
// therewith. // therewith.
type LabelName string type LabelName string
// IsValid is true iff the label name matches the pattern of LabelNameRE. // IsValid is true iff the label name matches the pattern of LabelNameRE. This
// method, however, does not use LabelNameRE for the check but a much faster
// hardcoded implementation.
func (ln LabelName) IsValid() bool { func (ln LabelName) IsValid() bool {
if len(ln) == 0 { if len(ln) == 0 {
return false return false
@ -106,7 +110,7 @@ func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&s); err != nil { if err := unmarshal(&s); err != nil {
return err return err
} }
if !LabelNameRE.MatchString(s) { if !LabelName(s).IsValid() {
return fmt.Errorf("%q is not a valid label name", s) return fmt.Errorf("%q is not a valid label name", s)
} }
*ln = LabelName(s) *ln = LabelName(s)
@ -119,7 +123,7 @@ func (ln *LabelName) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &s); err != nil { if err := json.Unmarshal(b, &s); err != nil {
return err return err
} }
if !LabelNameRE.MatchString(s) { if !LabelName(s).IsValid() {
return fmt.Errorf("%q is not a valid label name", s) return fmt.Errorf("%q is not a valid label name", s)
} }
*ln = LabelName(s) *ln = LabelName(s)

@ -160,7 +160,7 @@ func (l *LabelSet) UnmarshalJSON(b []byte) error {
// LabelName as a string and does not call its UnmarshalJSON method. // LabelName as a string and does not call its UnmarshalJSON method.
// Thus, we have to replicate the behavior here. // Thus, we have to replicate the behavior here.
for ln := range m { for ln := range m {
if !LabelNameRE.MatchString(string(ln)) { if !ln.IsValid() {
return fmt.Errorf("%q is not a valid label name", ln) return fmt.Errorf("%q is not a valid label name", ln)
} }
} }

@ -21,8 +21,11 @@ import (
) )
var ( var (
separator = []byte{0} separator = []byte{0}
MetricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`) // MetricNameRE is a regular expression matching valid metric
// names. Note that the IsValidMetricName function performs the same
// check but faster than a match with this regular expression.
MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`)
) )
// A Metric is similar to a LabelSet, but the key difference is that a Metric is // A Metric is similar to a LabelSet, but the key difference is that a Metric is
@ -41,7 +44,7 @@ func (m Metric) Before(o Metric) bool {
// Clone returns a copy of the Metric. // Clone returns a copy of the Metric.
func (m Metric) Clone() Metric { func (m Metric) Clone() Metric {
clone := Metric{} clone := make(Metric, len(m))
for k, v := range m { for k, v := range m {
clone[k] = v clone[k] = v
} }
@ -85,6 +88,8 @@ func (m Metric) FastFingerprint() Fingerprint {
} }
// IsValidMetricName returns true iff name matches the pattern of MetricNameRE. // IsValidMetricName returns true iff name matches the pattern of MetricNameRE.
// This function, however, does not use MetricNameRE for the check but a much
// faster hardcoded implementation.
func IsValidMetricName(n LabelValue) bool { func IsValidMetricName(n LabelValue) bool {
if len(n) == 0 { if len(n) == 0 {
return false return false

@ -33,18 +33,19 @@ func WithParam(ctx context.Context, p, v string) context.Context {
return context.WithValue(ctx, param(p), v) return context.WithValue(ctx, param(p), v)
} }
type contextFn func(r *http.Request) (context.Context, error) // ContextFunc returns a new context for a request.
type ContextFunc func(r *http.Request) (context.Context, error)
// Router wraps httprouter.Router and adds support for prefixed sub-routers // Router wraps httprouter.Router and adds support for prefixed sub-routers
// and per-request context injections. // and per-request context injections.
type Router struct { type Router struct {
rtr *httprouter.Router rtr *httprouter.Router
prefix string prefix string
ctxFn contextFn ctxFn ContextFunc
} }
// New returns a new Router. // New returns a new Router.
func New(ctxFn contextFn) *Router { func New(ctxFn ContextFunc) *Router {
if ctxFn == nil { if ctxFn == nil {
ctxFn = func(r *http.Request) (context.Context, error) { ctxFn = func(r *http.Request) (context.Context, error) {
return context.Background(), nil return context.Background(), nil

32
vendor/vendor.json vendored

@ -540,40 +540,40 @@
"revisionTime": "2015-02-12T10:17:44Z" "revisionTime": "2015-02-12T10:17:44Z"
}, },
{ {
"checksumSHA1": "mHyjbJ3BWOfUV6q9f5PBt0gaY1k=", "checksumSHA1": "jG8qYuDUuaZeflt4JxBBdyQBsXw=",
"path": "github.com/prometheus/common/expfmt", "path": "github.com/prometheus/common/expfmt",
"revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4",
"revisionTime": "2016-10-02T21:02:34Z" "revisionTime": "2017-01-08T23:12:12Z"
}, },
{ {
"checksumSHA1": "GWlM3d2vPYyNATtTFgftS10/A9w=", "checksumSHA1": "GWlM3d2vPYyNATtTFgftS10/A9w=",
"path": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", "path": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg",
"revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4",
"revisionTime": "2016-10-02T21:02:34Z" "revisionTime": "2017-01-08T23:12:12Z"
}, },
{ {
"checksumSHA1": "UU6hIfhVjnAYDADQEfE/3T7Ddm8=", "checksumSHA1": "ZA4MLHNAP905WiAOLy4BBzmcuxM=",
"path": "github.com/prometheus/common/log", "path": "github.com/prometheus/common/log",
"revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4",
"revisionTime": "2016-10-02T21:02:34Z" "revisionTime": "2017-01-08T23:12:12Z"
}, },
{ {
"checksumSHA1": "nFie+rxcX5WdIv1diZ+fu3aj6lE=", "checksumSHA1": "vopCLXHzYm+3l5fPKOf4/fQwrCM=",
"path": "github.com/prometheus/common/model", "path": "github.com/prometheus/common/model",
"revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4",
"revisionTime": "2016-10-02T21:02:34Z" "revisionTime": "2017-01-08T23:12:12Z"
}, },
{ {
"checksumSHA1": "QQKJYoGcY10nIHxhBEHwjwUZQzk=", "checksumSHA1": "ZbbESWBHHcPUJ/A5yrzKhTHuPc8=",
"path": "github.com/prometheus/common/route", "path": "github.com/prometheus/common/route",
"revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4",
"revisionTime": "2016-10-02T21:02:34Z" "revisionTime": "2017-01-08T23:12:12Z"
}, },
{ {
"checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=", "checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=",
"path": "github.com/prometheus/common/version", "path": "github.com/prometheus/common/version",
"revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4",
"revisionTime": "2016-10-02T21:02:34Z" "revisionTime": "2017-01-08T23:12:12Z"
}, },
{ {
"checksumSHA1": "W218eJZPXJG783fUr/z6IaAZyes=", "checksumSHA1": "W218eJZPXJG783fUr/z6IaAZyes=",

Loading…
Cancel
Save