Unverified Commit 1eb2acca authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #74248 from danielqsj/pdep

Update vendor prometheus/common/... to latest release
parents a826e80c c6a16d60
...@@ -3115,23 +3115,23 @@ ...@@ -3115,23 +3115,23 @@
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus", "ImportPath": "github.com/prometheus/client_golang/prometheus",
"Comment": "v0.9.1", "Comment": "v0.9.2",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/internal", "ImportPath": "github.com/prometheus/client_golang/prometheus/internal",
"Comment": "v0.9.1", "Comment": "v0.9.2",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/promhttp", "ImportPath": "github.com/prometheus/client_golang/prometheus/promhttp",
"Comment": "v0.9.1", "Comment": "v0.9.2",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/testutil", "ImportPath": "github.com/prometheus/client_golang/prometheus/testutil",
"Comment": "v0.9.1", "Comment": "v0.9.2",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_model/go", "ImportPath": "github.com/prometheus/client_model/go",
...@@ -3140,15 +3140,18 @@ ...@@ -3140,15 +3140,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/common/expfmt", "ImportPath": "github.com/prometheus/common/expfmt",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", "ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/model", "ImportPath": "github.com/prometheus/common/model",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/procfs", "ImportPath": "github.com/prometheus/procfs",
......
...@@ -572,15 +572,18 @@ ...@@ -572,15 +572,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus", "ImportPath": "github.com/prometheus/client_golang/prometheus",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/internal", "ImportPath": "github.com/prometheus/client_golang/prometheus/internal",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/promhttp", "ImportPath": "github.com/prometheus/client_golang/prometheus/promhttp",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_model/go", "ImportPath": "github.com/prometheus/client_model/go",
...@@ -588,15 +591,18 @@ ...@@ -588,15 +591,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/common/expfmt", "ImportPath": "github.com/prometheus/common/expfmt",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", "ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/model", "ImportPath": "github.com/prometheus/common/model",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/procfs", "ImportPath": "github.com/prometheus/procfs",
......
...@@ -552,15 +552,18 @@ ...@@ -552,15 +552,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus", "ImportPath": "github.com/prometheus/client_golang/prometheus",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/internal", "ImportPath": "github.com/prometheus/client_golang/prometheus/internal",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/promhttp", "ImportPath": "github.com/prometheus/client_golang/prometheus/promhttp",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_model/go", "ImportPath": "github.com/prometheus/client_model/go",
...@@ -568,15 +571,18 @@ ...@@ -568,15 +571,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/common/expfmt", "ImportPath": "github.com/prometheus/common/expfmt",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", "ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/model", "ImportPath": "github.com/prometheus/common/model",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/procfs", "ImportPath": "github.com/prometheus/procfs",
......
...@@ -220,11 +220,13 @@ ...@@ -220,11 +220,13 @@
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus", "ImportPath": "github.com/prometheus/client_golang/prometheus",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/internal", "ImportPath": "github.com/prometheus/client_golang/prometheus/internal",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_model/go", "ImportPath": "github.com/prometheus/client_model/go",
...@@ -232,15 +234,18 @@ ...@@ -232,15 +234,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/common/expfmt", "ImportPath": "github.com/prometheus/common/expfmt",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", "ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/model", "ImportPath": "github.com/prometheus/common/model",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/procfs", "ImportPath": "github.com/prometheus/procfs",
......
...@@ -204,11 +204,13 @@ ...@@ -204,11 +204,13 @@
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus", "ImportPath": "github.com/prometheus/client_golang/prometheus",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_golang/prometheus/internal", "ImportPath": "github.com/prometheus/client_golang/prometheus/internal",
"Rev": "abad2d1bd44235a26707c172eab6bca5bf2dbad3" "Comment": "v0.9.2",
"Rev": "505eaef017263e299324067d40ca2c48f6a2cf50"
}, },
{ {
"ImportPath": "github.com/prometheus/client_model/go", "ImportPath": "github.com/prometheus/client_model/go",
...@@ -216,15 +218,18 @@ ...@@ -216,15 +218,18 @@
}, },
{ {
"ImportPath": "github.com/prometheus/common/expfmt", "ImportPath": "github.com/prometheus/common/expfmt",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", "ImportPath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/common/model", "ImportPath": "github.com/prometheus/common/model",
"Rev": "13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207" "Comment": "v0.2.0",
"Rev": "cfeb6f9992ffa54aaa4f2170ade4067ee478b250"
}, },
{ {
"ImportPath": "github.com/prometheus/procfs", "ImportPath": "github.com/prometheus/procfs",
......
...@@ -93,7 +93,7 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) * ...@@ -93,7 +93,7 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *
// First add only the const label names and sort them... // First add only the const label names and sort them...
for labelName := range constLabels { for labelName := range constLabels {
if !checkLabelName(labelName) { if !checkLabelName(labelName) {
d.err = fmt.Errorf("%q is not a valid label name", labelName) d.err = fmt.Errorf("%q is not a valid label name for metric %q", labelName, fqName)
return d return d
} }
labelNames = append(labelNames, labelName) labelNames = append(labelNames, labelName)
...@@ -115,7 +115,7 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) * ...@@ -115,7 +115,7 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *
// dimension with a different mix between preset and variable labels. // dimension with a different mix between preset and variable labels.
for _, labelName := range variableLabels { for _, labelName := range variableLabels {
if !checkLabelName(labelName) { if !checkLabelName(labelName) {
d.err = fmt.Errorf("%q is not a valid label name", labelName) d.err = fmt.Errorf("%q is not a valid label name for metric %q", labelName, fqName)
return d return d
} }
labelNames = append(labelNames, "$"+labelName) labelNames = append(labelNames, "$"+labelName)
......
...@@ -872,7 +872,13 @@ func checkMetricConsistency( ...@@ -872,7 +872,13 @@ func checkMetricConsistency(
h = hashAddByte(h, separatorByte) h = hashAddByte(h, separatorByte)
// Make sure label pairs are sorted. We depend on it for the consistency // Make sure label pairs are sorted. We depend on it for the consistency
// check. // check.
sort.Sort(labelPairSorter(dtoMetric.Label)) if !sort.IsSorted(labelPairSorter(dtoMetric.Label)) {
// We cannot sort dtoMetric.Label in place as it is immutable by contract.
copiedLabels := make([]*dto.LabelPair, len(dtoMetric.Label))
copy(copiedLabels, dtoMetric.Label)
sort.Sort(labelPairSorter(copiedLabels))
dtoMetric.Label = copiedLabels
}
for _, lp := range dtoMetric.Label { for _, lp := range dtoMetric.Label {
h = hashAdd(h, lp.GetName()) h = hashAdd(h, lp.GetName())
h = hashAddByte(h, separatorByte) h = hashAddByte(h, separatorByte)
...@@ -903,8 +909,8 @@ func checkDescConsistency( ...@@ -903,8 +909,8 @@ func checkDescConsistency(
} }
// Is the desc consistent with the content of the metric? // Is the desc consistent with the content of the metric?
lpsFromDesc := make([]*dto.LabelPair, 0, len(dtoMetric.Label)) lpsFromDesc := make([]*dto.LabelPair, len(desc.constLabelPairs), len(dtoMetric.Label))
lpsFromDesc = append(lpsFromDesc, desc.constLabelPairs...) copy(lpsFromDesc, desc.constLabelPairs)
for _, l := range desc.variableLabels { for _, l := range desc.variableLabels {
lpsFromDesc = append(lpsFromDesc, &dto.LabelPair{ lpsFromDesc = append(lpsFromDesc, &dto.LabelPair{
Name: proto.String(l), Name: proto.String(l),
......
...@@ -37,7 +37,6 @@ import ( ...@@ -37,7 +37,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"reflect"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
...@@ -125,38 +124,43 @@ func CollectAndCompare(c prometheus.Collector, expected io.Reader, metricNames . ...@@ -125,38 +124,43 @@ func CollectAndCompare(c prometheus.Collector, expected io.Reader, metricNames .
// exposition format. If any metricNames are provided, only metrics with those // exposition format. If any metricNames are provided, only metrics with those
// names are compared. // names are compared.
func GatherAndCompare(g prometheus.Gatherer, expected io.Reader, metricNames ...string) error { func GatherAndCompare(g prometheus.Gatherer, expected io.Reader, metricNames ...string) error {
metrics, err := g.Gather() got, err := g.Gather()
if err != nil { if err != nil {
return fmt.Errorf("gathering metrics failed: %s", err) return fmt.Errorf("gathering metrics failed: %s", err)
} }
if metricNames != nil { if metricNames != nil {
metrics = filterMetrics(metrics, metricNames) got = filterMetrics(got, metricNames)
} }
var tp expfmt.TextParser var tp expfmt.TextParser
expectedMetrics, err := tp.TextToMetricFamilies(expected) wantRaw, err := tp.TextToMetricFamilies(expected)
if err != nil { if err != nil {
return fmt.Errorf("parsing expected metrics failed: %s", err) return fmt.Errorf("parsing expected metrics failed: %s", err)
} }
want := internal.NormalizeMetricFamilies(wantRaw)
if !reflect.DeepEqual(metrics, internal.NormalizeMetricFamilies(expectedMetrics)) { return compare(got, want)
// Encode the gathered output to the readable text format for comparison. }
var buf1 bytes.Buffer
enc := expfmt.NewEncoder(&buf1, expfmt.FmtText) // compare encodes both provided slices of metric families into the text format,
for _, mf := range metrics { // compares their string message, and returns an error if they do not match.
if err := enc.Encode(mf); err != nil { // The error contains the encoded text of both the desired and the actual
return fmt.Errorf("encoding result failed: %s", err) // result.
} func compare(got, want []*dto.MetricFamily) error {
var gotBuf, wantBuf bytes.Buffer
enc := expfmt.NewEncoder(&gotBuf, expfmt.FmtText)
for _, mf := range got {
if err := enc.Encode(mf); err != nil {
return fmt.Errorf("encoding gathered metrics failed: %s", err)
} }
// Encode normalized expected metrics again to generate them in the same ordering }
// the registry does to spot differences more easily. enc = expfmt.NewEncoder(&wantBuf, expfmt.FmtText)
var buf2 bytes.Buffer for _, mf := range want {
enc = expfmt.NewEncoder(&buf2, expfmt.FmtText) if err := enc.Encode(mf); err != nil {
for _, mf := range internal.NormalizeMetricFamilies(expectedMetrics) { return fmt.Errorf("encoding expected metrics failed: %s", err)
if err := enc.Encode(mf); err != nil {
return fmt.Errorf("encoding result failed: %s", err)
}
} }
}
if wantBuf.String() != gotBuf.String() {
return fmt.Errorf(` return fmt.Errorf(`
metric output does not match expectation; want: metric output does not match expectation; want:
...@@ -165,7 +169,8 @@ metric output does not match expectation; want: ...@@ -165,7 +169,8 @@ metric output does not match expectation; want:
got: got:
%s %s
`, buf2.String(), buf1.String()) `, wantBuf.String(), gotBuf.String())
} }
return nil return nil
} }
......
...@@ -39,13 +39,16 @@ func NewTimer(o Observer) *Timer { ...@@ -39,13 +39,16 @@ func NewTimer(o Observer) *Timer {
// ObserveDuration records the duration passed since the Timer was created with // ObserveDuration records the duration passed since the Timer was created with
// NewTimer. It calls the Observe method of the Observer provided during // NewTimer. It calls the Observe method of the Observer provided during
// construction with the duration in seconds as an argument. ObserveDuration is // construction with the duration in seconds as an argument. The observed
// usually called with a defer statement. // duration is also returned. ObserveDuration is usually called with a defer
// statement.
// //
// Note that this method is only guaranteed to never observe negative durations // Note that this method is only guaranteed to never observe negative durations
// if used with Go1.9+. // if used with Go1.9+.
func (t *Timer) ObserveDuration() { func (t *Timer) ObserveDuration() time.Duration {
d := time.Since(t.begin)
if t.observer != nil { if t.observer != nil {
t.observer.Observe(time.Since(t.begin).Seconds()) t.observer.Observe(d.Seconds())
} }
return d
} }
...@@ -164,9 +164,9 @@ func (sd *SampleDecoder) Decode(s *model.Vector) error { ...@@ -164,9 +164,9 @@ func (sd *SampleDecoder) Decode(s *model.Vector) error {
} }
// ExtractSamples builds a slice of samples from the provided metric // ExtractSamples builds a slice of samples from the provided metric
// families. If an error occurs during sample extraction, it continues to // families. If an error occurrs during sample extraction, it continues to
// extract from the remaining metric families. The returned error is the last // extract from the remaining metric families. The returned error is the last
// error that has occured. // error that has occurred.
func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) (model.Vector, error) { func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) (model.Vector, error) {
var ( var (
all model.Vector all model.Vector
......
...@@ -26,7 +26,7 @@ const ( ...@@ -26,7 +26,7 @@ const (
// The Content-Type values for the different wire protocols. // The Content-Type values for the different wire protocols.
FmtUnknown Format = `<unknown>` FmtUnknown Format = `<unknown>`
FmtText Format = `text/plain; version=` + TextVersion FmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
FmtProtoDelim Format = ProtoFmt + ` encoding=delimited` FmtProtoDelim Format = ProtoFmt + ` encoding=delimited`
FmtProtoText Format = ProtoFmt + ` encoding=text` FmtProtoText Format = ProtoFmt + ` encoding=text`
FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text` FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text`
......
...@@ -315,6 +315,10 @@ func (p *TextParser) startLabelValue() stateFn { ...@@ -315,6 +315,10 @@ func (p *TextParser) startLabelValue() stateFn {
if p.readTokenAsLabelValue(); p.err != nil { if p.readTokenAsLabelValue(); p.err != nil {
return nil return nil
} }
if !model.LabelValue(p.currentToken.String()).IsValid() {
p.parseError(fmt.Sprintf("invalid label value %q", p.currentToken.String()))
return nil
}
p.currentLabelPair.Value = proto.String(p.currentToken.String()) p.currentLabelPair.Value = proto.String(p.currentToken.String())
// Special treatment of summaries: // Special treatment of summaries:
// - Quantile labels are special, will result in dto.Quantile later. // - Quantile labels are special, will result in dto.Quantile later.
...@@ -355,7 +359,7 @@ func (p *TextParser) startLabelValue() stateFn { ...@@ -355,7 +359,7 @@ func (p *TextParser) startLabelValue() stateFn {
} }
return p.readingValue return p.readingValue
default: default:
p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.Value)) p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.GetValue()))
return nil return nil
} }
} }
...@@ -552,8 +556,8 @@ func (p *TextParser) readTokenUntilWhitespace() { ...@@ -552,8 +556,8 @@ func (p *TextParser) readTokenUntilWhitespace() {
// byte considered is the byte already read (now in p.currentByte). The first // byte considered is the byte already read (now in p.currentByte). The first
// newline byte encountered is still copied into p.currentByte, but not into // newline byte encountered is still copied into p.currentByte, but not into
// p.currentToken. If recognizeEscapeSequence is true, two escape sequences are // p.currentToken. If recognizeEscapeSequence is true, two escape sequences are
// recognized: '\\' tranlates into '\', and '\n' into a line-feed character. All // recognized: '\\' translates into '\', and '\n' into a line-feed character.
// other escape sequences are invalid and cause an error. // All other escape sequences are invalid and cause an error.
func (p *TextParser) readTokenUntilNewline(recognizeEscapeSequence bool) { func (p *TextParser) readTokenUntilNewline(recognizeEscapeSequence bool) {
p.currentToken.Reset() p.currentToken.Reset()
escaped := false escaped := false
......
/* /*
Copyright (c) 2011, Open Knowledge Foundation Ltd.
All rights reserved.
HTTP Content-Type Autonegotiation. HTTP Content-Type Autonegotiation.
The functions in this package implement the behaviour specified in The functions in this package implement the behaviour specified in
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Copyright (c) 2011, Open Knowledge Foundation Ltd.
All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
met: met:
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
) )
var ( var (
separator = []byte{0}
// MetricNameRE is a regular expression matching valid metric // MetricNameRE is a regular expression matching valid metric
// names. Note that the IsValidMetricName function performs the same // names. Note that the IsValidMetricName function performs the same
// check but faster than a match with this regular expression. // check but faster than a match with this regular expression.
......
...@@ -59,8 +59,8 @@ func (m *Matcher) Validate() error { ...@@ -59,8 +59,8 @@ func (m *Matcher) Validate() error {
return nil return nil
} }
// Silence defines the representation of a silence definiton // Silence defines the representation of a silence definition in the Prometheus
// in the Prometheus eco-system. // eco-system.
type Silence struct { type Silence struct {
ID uint64 `json:"id,omitempty"` ID uint64 `json:"id,omitempty"`
......
...@@ -43,7 +43,7 @@ const ( ...@@ -43,7 +43,7 @@ const (
// (1970-01-01 00:00 UTC) excluding leap seconds. // (1970-01-01 00:00 UTC) excluding leap seconds.
type Time int64 type Time int64
// Interval describes and interval between two timestamps. // Interval describes an interval between two timestamps.
type Interval struct { type Interval struct {
Start, End Time Start, End Time
} }
...@@ -163,9 +163,21 @@ func (t *Time) UnmarshalJSON(b []byte) error { ...@@ -163,9 +163,21 @@ 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
// Set implements pflag/flag.Value
func (d *Duration) Set(s string) error {
var err error
*d, err = ParseDuration(s)
return err
}
// Type implements pflag.Value
func (d *Duration) Type() string {
return "duration"
}
var durationRE = regexp.MustCompile("^([0-9]+)(y|w|d|h|m|s|ms)$") var durationRE = regexp.MustCompile("^([0-9]+)(y|w|d|h|m|s|ms)$")
// StringToDuration parses a string into a time.Duration, assuming that a year // ParseDuration parses a string into a time.Duration, assuming that a year
// always has 365d, a week always has 7d, and a day always has 24h. // always has 365d, a week always has 7d, and a day always has 24h.
func ParseDuration(durationStr string) (Duration, error) { func ParseDuration(durationStr string) (Duration, error) {
matches := durationRE.FindStringSubmatch(durationStr) matches := durationRE.FindStringSubmatch(durationStr)
...@@ -202,6 +214,9 @@ func (d Duration) String() string { ...@@ -202,6 +214,9 @@ func (d Duration) String() string {
ms = int64(time.Duration(d) / time.Millisecond) ms = int64(time.Duration(d) / time.Millisecond)
unit = "ms" unit = "ms"
) )
if ms == 0 {
return "0s"
}
factors := map[string]int64{ factors := map[string]int64{
"y": 1000 * 60 * 60 * 24 * 365, "y": 1000 * 60 * 60 * 24 * 365,
"w": 1000 * 60 * 60 * 24 * 7, "w": 1000 * 60 * 60 * 24 * 7,
......
...@@ -100,7 +100,7 @@ func (s *SamplePair) UnmarshalJSON(b []byte) error { ...@@ -100,7 +100,7 @@ func (s *SamplePair) UnmarshalJSON(b []byte) error {
} }
// Equal returns true if this SamplePair and o have equal Values and equal // Equal returns true if this SamplePair and o have equal Values and equal
// Timestamps. The sematics of Value equality is defined by SampleValue.Equal. // Timestamps. The semantics of Value equality is defined by SampleValue.Equal.
func (s *SamplePair) Equal(o *SamplePair) bool { func (s *SamplePair) Equal(o *SamplePair) bool {
return s == o || (s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp)) return s == o || (s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp))
} }
...@@ -117,7 +117,7 @@ type Sample struct { ...@@ -117,7 +117,7 @@ type Sample struct {
} }
// Equal compares first the metrics, then the timestamp, then the value. The // Equal compares first the metrics, then the timestamp, then the value. The
// sematics of value equality is defined by SampleValue.Equal. // semantics of value equality is defined by SampleValue.Equal.
func (s *Sample) Equal(o *Sample) bool { func (s *Sample) Equal(o *Sample) bool {
if s == o { if s == o {
return true return true
......
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment