Merge pull request #2327 from prometheus/beorn7/vendoring

vendoring: Update prometheus/common to pull in bug fixes
This commit is contained in:
Björn Rabenstein 2017-01-09 13:28:36 +01:00 committed by GitHub
commit 6ce97837ab
8 changed files with 82 additions and 47 deletions

View file

@ -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 {

View file

@ -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 + ";"

View file

@ -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:

View file

@ -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)

View file

@ -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)
}
}

View file

@ -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

View file

@ -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

32
vendor/vendor.json vendored
View file

@ -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=",