From 86ec87b78f9d442f3994e3617f3603dad46f6971 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 9 Jan 2017 12:25:17 +0100 Subject: [PATCH] vendoring: Update prometheus/common to pull in bug fixes In particular the one for https://github.com/prometheus/common/issues/72. --- .../prometheus/common/expfmt/decode.go | 47 +++++++++++++------ .../prometheus/common/expfmt/expfmt.go | 7 +-- .../prometheus/common/log/syslog_formatter.go | 11 ++++- .../prometheus/common/model/labels.go | 12 +++-- .../prometheus/common/model/labelset.go | 2 +- .../prometheus/common/model/metric.go | 11 +++-- .../prometheus/common/route/route.go | 7 +-- vendor/vendor.json | 32 ++++++------- 8 files changed, 82 insertions(+), 47 deletions(-) diff --git a/vendor/github.com/prometheus/common/expfmt/decode.go b/vendor/github.com/prometheus/common/expfmt/decode.go index 487fdc6cc..a7a42d5ef 100644 --- a/vendor/github.com/prometheus/common/expfmt/decode.go +++ b/vendor/github.com/prometheus/common/expfmt/decode.go @@ -31,6 +31,7 @@ type Decoder interface { Decode(*dto.MetricFamily) error } +// DecodeOptions contains options used by the Decoder and in sample extraction. type DecodeOptions struct { // Timestamp is added to each value from the stream that has no explicit timestamp set. Timestamp model.Time @@ -142,6 +143,8 @@ func (d *textDecoder) Decode(v *dto.MetricFamily) error { return nil } +// SampleDecoder wraps a Decoder to extract samples from the metric families +// decoded by the wrapped Decoder. type SampleDecoder struct { Dec Decoder Opts *DecodeOptions @@ -149,37 +152,51 @@ type SampleDecoder struct { 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 { - if err := sd.Dec.Decode(&sd.f); err != nil { + err := sd.Dec.Decode(&sd.f) + if err != nil { return err } - *s = extractSamples(&sd.f, sd.Opts) - return nil + *s, err = extractSamples(&sd.f, sd.Opts) + return err } -// Extract samples builds a slice of samples from the provided metric families. -func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) model.Vector { - var all model.Vector +// ExtractSamples builds a slice of samples from the provided metric +// families. If an error occurs during sample extraction, it continues to +// 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 { - 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() { case dto.MetricType_COUNTER: - return extractCounter(o, f) + return extractCounter(o, f), nil case dto.MetricType_GAUGE: - return extractGauge(o, f) + return extractGauge(o, f), nil case dto.MetricType_SUMMARY: - return extractSummary(o, f) + return extractSummary(o, f), nil case dto.MetricType_UNTYPED: - return extractUntyped(o, f) + return extractUntyped(o, f), nil 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 { diff --git a/vendor/github.com/prometheus/common/expfmt/expfmt.go b/vendor/github.com/prometheus/common/expfmt/expfmt.go index fae10f6eb..371ac7503 100644 --- a/vendor/github.com/prometheus/common/expfmt/expfmt.go +++ b/vendor/github.com/prometheus/common/expfmt/expfmt.go @@ -11,14 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -// A package for reading and writing Prometheus metrics. +// Package expfmt contains tools for reading and writing Prometheus metrics. package expfmt +// Format specifies the HTTP content type of the different wire protocols. type Format string +// Constants to assemble the Content-Type values for the different wire protocols. const ( - TextVersion = "0.0.4" - + TextVersion = "0.0.4" ProtoType = `application/vnd.google.protobuf` ProtoProtocol = `io.prometheus.client.MetricFamily` ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";" diff --git a/vendor/github.com/prometheus/common/log/syslog_formatter.go b/vendor/github.com/prometheus/common/log/syslog_formatter.go index fd8c6fbee..64f5fdac9 100644 --- a/vendor/github.com/prometheus/common/log/syslog_formatter.go +++ b/vendor/github.com/prometheus/common/log/syslog_formatter.go @@ -23,6 +23,8 @@ import ( "github.com/Sirupsen/logrus" ) +var _ logrus.Formatter = (*syslogger)(nil) + func init() { setSyslogFormatter = func(appname, local string) error { if appname == "" { @@ -43,7 +45,7 @@ func init() { } } -var ceeTag = []byte("@cee:") +var prefixTag []byte type syslogger struct { wrap logrus.Formatter @@ -56,6 +58,11 @@ func newSyslogger(appname string, facility string, fmter logrus.Formatter) (*sys return nil, err } out, err := syslog.New(priority, appname) + _, isJSON := fmter.(*logrus.JSONFormatter) + if isJSON { + // add cee tag to json formatted syslogs + prefixTag = []byte("@cee:") + } return &syslogger{ out: out, 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 // is returned - line := string(append(ceeTag, data...)) + line := string(append(prefixTag, data...)) switch e.Level { case logrus.PanicLevel: diff --git a/vendor/github.com/prometheus/common/model/labels.go b/vendor/github.com/prometheus/common/model/labels.go index 3b72e7ff8..41051a01a 100644 --- a/vendor/github.com/prometheus/common/model/labels.go +++ b/vendor/github.com/prometheus/common/model/labels.go @@ -80,14 +80,18 @@ const ( 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_]*$") // A LabelName is a key for a LabelSet or Metric. It has a value associated // therewith. 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 { if len(ln) == 0 { return false @@ -106,7 +110,7 @@ func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := unmarshal(&s); err != nil { return err } - if !LabelNameRE.MatchString(s) { + if !LabelName(s).IsValid() { return fmt.Errorf("%q is not a valid label name", s) } *ln = LabelName(s) @@ -119,7 +123,7 @@ func (ln *LabelName) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(b, &s); err != nil { return err } - if !LabelNameRE.MatchString(s) { + if !LabelName(s).IsValid() { return fmt.Errorf("%q is not a valid label name", s) } *ln = LabelName(s) diff --git a/vendor/github.com/prometheus/common/model/labelset.go b/vendor/github.com/prometheus/common/model/labelset.go index 5f931cdb9..6eda08a73 100644 --- a/vendor/github.com/prometheus/common/model/labelset.go +++ b/vendor/github.com/prometheus/common/model/labelset.go @@ -160,7 +160,7 @@ func (l *LabelSet) UnmarshalJSON(b []byte) error { // LabelName as a string and does not call its UnmarshalJSON method. // Thus, we have to replicate the behavior here. for ln := range m { - if !LabelNameRE.MatchString(string(ln)) { + if !ln.IsValid() { return fmt.Errorf("%q is not a valid label name", ln) } } diff --git a/vendor/github.com/prometheus/common/model/metric.go b/vendor/github.com/prometheus/common/model/metric.go index a5da59a50..f7250909b 100644 --- a/vendor/github.com/prometheus/common/model/metric.go +++ b/vendor/github.com/prometheus/common/model/metric.go @@ -21,8 +21,11 @@ import ( ) var ( - separator = []byte{0} - MetricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`) + separator = []byte{0} + // 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 @@ -41,7 +44,7 @@ func (m Metric) Before(o Metric) bool { // Clone returns a copy of the Metric. func (m Metric) Clone() Metric { - clone := Metric{} + clone := make(Metric, len(m)) for k, v := range m { clone[k] = v } @@ -85,6 +88,8 @@ func (m Metric) FastFingerprint() Fingerprint { } // 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 { if len(n) == 0 { return false diff --git a/vendor/github.com/prometheus/common/route/route.go b/vendor/github.com/prometheus/common/route/route.go index 930b52d4f..1e5638ed9 100644 --- a/vendor/github.com/prometheus/common/route/route.go +++ b/vendor/github.com/prometheus/common/route/route.go @@ -33,18 +33,19 @@ func WithParam(ctx context.Context, p, v string) context.Context { 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 // and per-request context injections. type Router struct { rtr *httprouter.Router prefix string - ctxFn contextFn + ctxFn ContextFunc } // New returns a new Router. -func New(ctxFn contextFn) *Router { +func New(ctxFn ContextFunc) *Router { if ctxFn == nil { ctxFn = func(r *http.Request) (context.Context, error) { return context.Background(), nil diff --git a/vendor/vendor.json b/vendor/vendor.json index 648bec426..631073955 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -540,40 +540,40 @@ "revisionTime": "2015-02-12T10:17:44Z" }, { - "checksumSHA1": "mHyjbJ3BWOfUV6q9f5PBt0gaY1k=", + "checksumSHA1": "jG8qYuDUuaZeflt4JxBBdyQBsXw=", "path": "github.com/prometheus/common/expfmt", - "revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", - "revisionTime": "2016-10-02T21:02:34Z" + "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4", + "revisionTime": "2017-01-08T23:12:12Z" }, { "checksumSHA1": "GWlM3d2vPYyNATtTFgftS10/A9w=", "path": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", - "revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", - "revisionTime": "2016-10-02T21:02:34Z" + "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4", + "revisionTime": "2017-01-08T23:12:12Z" }, { - "checksumSHA1": "UU6hIfhVjnAYDADQEfE/3T7Ddm8=", + "checksumSHA1": "ZA4MLHNAP905WiAOLy4BBzmcuxM=", "path": "github.com/prometheus/common/log", - "revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", - "revisionTime": "2016-10-02T21:02:34Z" + "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4", + "revisionTime": "2017-01-08T23:12:12Z" }, { - "checksumSHA1": "nFie+rxcX5WdIv1diZ+fu3aj6lE=", + "checksumSHA1": "vopCLXHzYm+3l5fPKOf4/fQwrCM=", "path": "github.com/prometheus/common/model", - "revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", - "revisionTime": "2016-10-02T21:02:34Z" + "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4", + "revisionTime": "2017-01-08T23:12:12Z" }, { - "checksumSHA1": "QQKJYoGcY10nIHxhBEHwjwUZQzk=", + "checksumSHA1": "ZbbESWBHHcPUJ/A5yrzKhTHuPc8=", "path": "github.com/prometheus/common/route", - "revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", - "revisionTime": "2016-10-02T21:02:34Z" + "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4", + "revisionTime": "2017-01-08T23:12:12Z" }, { "checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=", "path": "github.com/prometheus/common/version", - "revision": "85637ea67b04b5c3bb25e671dacded2977f8f9f6", - "revisionTime": "2016-10-02T21:02:34Z" + "revision": "dd2f054febf4a6c00f2343686efb775948a8bff4", + "revisionTime": "2017-01-08T23:12:12Z" }, { "checksumSHA1": "W218eJZPXJG783fUr/z6IaAZyes=",