mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-13 17:14:05 -08:00
*: fix misc compile errors
This commit is contained in:
parent
622ece6273
commit
fecf9532b9
|
@ -59,3 +59,18 @@ func NewMatcher(t MatchType, n, v string) (*Matcher, error) {
|
||||||
func (m *Matcher) String() string {
|
func (m *Matcher) String() string {
|
||||||
return fmt.Sprintf("%s%s%q", m.Name, m.Type, m.Value)
|
return fmt.Sprintf("%s%s%q", m.Name, m.Type, m.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Matches returns whether the matcher matches the given string value.
|
||||||
|
func (m *Matcher) Matches(s string) bool {
|
||||||
|
switch m.Type {
|
||||||
|
case MatchEqual:
|
||||||
|
return s == m.Value
|
||||||
|
case MatchNotEqual:
|
||||||
|
return s != m.Value
|
||||||
|
case MatchRegexp:
|
||||||
|
return m.re.MatchString(s)
|
||||||
|
case MatchNotRegexp:
|
||||||
|
return !m.re.MatchString(s)
|
||||||
|
}
|
||||||
|
panic("labels.Matcher.Matches: invalid match type")
|
||||||
|
}
|
||||||
|
|
|
@ -793,7 +793,7 @@ func (ev *evaluator) VectorSelector(node *VectorSelector) Vector {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec = append(vec, Sample{
|
vec = append(vec, Sample{
|
||||||
Metric: toLabels(node.series[i].Labels()),
|
Metric: node.series[i].Labels(),
|
||||||
Point: Point{V: v, T: ev.Timestamp},
|
Point: Point{V: v, T: ev.Timestamp},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -811,7 +811,7 @@ func (ev *evaluator) MatrixSelector(node *MatrixSelector) Matrix {
|
||||||
|
|
||||||
for i, it := range node.iterators {
|
for i, it := range node.iterators {
|
||||||
ss := Series{
|
ss := Series{
|
||||||
Metric: toLabels(node.series[i].Labels()),
|
Metric: node.series[i].Labels(),
|
||||||
Points: make([]Point, 0, 16),
|
Points: make([]Point, 0, 16),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -553,7 +553,7 @@ func funcAbsent(ev *evaluator, args Expressions) Value {
|
||||||
|
|
||||||
if vs, ok := args[0].(*VectorSelector); ok {
|
if vs, ok := args[0].(*VectorSelector); ok {
|
||||||
for _, ma := range vs.LabelMatchers {
|
for _, ma := range vs.LabelMatchers {
|
||||||
if ma.Type == MatchEqual && ma.Name != labels.MetricName {
|
if ma.Type == labels.MatchEqual && ma.Name != labels.MetricName {
|
||||||
m = append(m, labels.Label{Name: ma.Name, Value: ma.Value})
|
m = append(m, labels.Label{Name: ma.Name, Value: ma.Value})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ func ParseMetric(input string) (m labels.Labels, err error) {
|
||||||
|
|
||||||
// ParseMetricSelector parses the provided textual metric selector into a list of
|
// ParseMetricSelector parses the provided textual metric selector into a list of
|
||||||
// label matchers.
|
// label matchers.
|
||||||
func ParseMetricSelector(input string) (m []*LabelMatcher, err error) {
|
func ParseMetricSelector(input string) (m []*labels.Matcher, err error) {
|
||||||
p := newParser(input)
|
p := newParser(input)
|
||||||
defer p.recover(&err)
|
defer p.recover(&err)
|
||||||
|
|
||||||
|
@ -815,10 +815,10 @@ func (p *parser) labelSet() labels.Labels {
|
||||||
//
|
//
|
||||||
// '{' [ <labelname> <match_op> <match_string>, ... ] '}'
|
// '{' [ <labelname> <match_op> <match_string>, ... ] '}'
|
||||||
//
|
//
|
||||||
func (p *parser) labelMatchers(operators ...itemType) []*LabelMatcher {
|
func (p *parser) labelMatchers(operators ...itemType) []*labels.Matcher {
|
||||||
const ctx = "label matching"
|
const ctx = "label matching"
|
||||||
|
|
||||||
matchers := []*LabelMatcher{}
|
matchers := []*labels.Matcher{}
|
||||||
|
|
||||||
p.expect(itemLeftBrace, ctx)
|
p.expect(itemLeftBrace, ctx)
|
||||||
|
|
||||||
|
@ -848,21 +848,21 @@ func (p *parser) labelMatchers(operators ...itemType) []*LabelMatcher {
|
||||||
val := p.unquoteString(p.expect(itemString, ctx).val)
|
val := p.unquoteString(p.expect(itemString, ctx).val)
|
||||||
|
|
||||||
// Map the item to the respective match type.
|
// Map the item to the respective match type.
|
||||||
var matchType MatchType
|
var matchType labels.MatchType
|
||||||
switch op {
|
switch op {
|
||||||
case itemEQL:
|
case itemEQL:
|
||||||
matchType = MatchEqual
|
matchType = labels.MatchEqual
|
||||||
case itemNEQ:
|
case itemNEQ:
|
||||||
matchType = MatchNotEqual
|
matchType = labels.MatchNotEqual
|
||||||
case itemEQLRegex:
|
case itemEQLRegex:
|
||||||
matchType = MatchRegexp
|
matchType = labels.MatchRegexp
|
||||||
case itemNEQRegex:
|
case itemNEQRegex:
|
||||||
matchType = MatchNotRegexp
|
matchType = labels.MatchNotRegexp
|
||||||
default:
|
default:
|
||||||
p.errorf("item %q is not a metric match type", op)
|
p.errorf("item %q is not a metric match type", op)
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := NewLabelMatcher(matchType, label.val, val)
|
m, err := labels.NewMatcher(matchType, label.val, val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.error(err)
|
p.error(err)
|
||||||
}
|
}
|
||||||
|
@ -941,7 +941,7 @@ func (p *parser) offset() time.Duration {
|
||||||
// [<metric_identifier>] <label_matchers>
|
// [<metric_identifier>] <label_matchers>
|
||||||
//
|
//
|
||||||
func (p *parser) VectorSelector(name string) *VectorSelector {
|
func (p *parser) VectorSelector(name string) *VectorSelector {
|
||||||
var matchers []*LabelMatcher
|
var matchers []*labels.Matcher
|
||||||
// Parse label matching if any.
|
// Parse label matching if any.
|
||||||
if t := p.peek(); t.typ == itemLeftBrace {
|
if t := p.peek(); t.typ == itemLeftBrace {
|
||||||
matchers = p.labelMatchers(itemEQL, itemNEQ, itemEQLRegex, itemNEQRegex)
|
matchers = p.labelMatchers(itemEQL, itemNEQ, itemEQLRegex, itemNEQRegex)
|
||||||
|
@ -954,7 +954,7 @@ func (p *parser) VectorSelector(name string) *VectorSelector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set name label matching.
|
// Set name label matching.
|
||||||
m, err := NewLabelMatcher(MatchEqual, labels.MetricName, name)
|
m, err := labels.NewMatcher(labels.MatchEqual, labels.MetricName, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // Must not happen with metric.Equal.
|
panic(err) // Must not happen with metric.Equal.
|
||||||
}
|
}
|
||||||
|
@ -968,7 +968,7 @@ func (p *parser) VectorSelector(name string) *VectorSelector {
|
||||||
// implicit selection of all metrics (e.g. by a typo).
|
// implicit selection of all metrics (e.g. by a typo).
|
||||||
notEmpty := false
|
notEmpty := false
|
||||||
for _, lm := range matchers {
|
for _, lm := range matchers {
|
||||||
if !lm.matcher().Matches("") {
|
if !lm.Matches("") {
|
||||||
notEmpty = true
|
notEmpty = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fabxc/tsdb/labels"
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testExpr = []struct {
|
var testExpr = []struct {
|
||||||
|
@ -142,8 +142,8 @@ var testExpr = []struct {
|
||||||
Op: itemSUB,
|
Op: itemSUB,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -152,8 +152,8 @@ var testExpr = []struct {
|
||||||
Op: itemADD,
|
Op: itemADD,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -261,14 +261,14 @@ var testExpr = []struct {
|
||||||
Op: itemMUL,
|
Op: itemMUL,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardOneToOne},
|
VectorMatching: &VectorMatching{Card: CardOneToOne},
|
||||||
|
@ -279,8 +279,8 @@ var testExpr = []struct {
|
||||||
Op: itemEQL,
|
Op: itemEQL,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &NumberLiteral{1},
|
RHS: &NumberLiteral{1},
|
||||||
|
@ -291,8 +291,8 @@ var testExpr = []struct {
|
||||||
Op: itemEQL,
|
Op: itemEQL,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &NumberLiteral{1},
|
RHS: &NumberLiteral{1},
|
||||||
|
@ -305,8 +305,8 @@ var testExpr = []struct {
|
||||||
LHS: &NumberLiteral{2.5},
|
LHS: &NumberLiteral{2.5},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -316,14 +316,14 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
|
@ -334,14 +334,14 @@ var testExpr = []struct {
|
||||||
Op: itemLOR,
|
Op: itemLOR,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
|
@ -352,14 +352,14 @@ var testExpr = []struct {
|
||||||
Op: itemLUnless,
|
Op: itemLUnless,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
|
@ -373,14 +373,14 @@ var testExpr = []struct {
|
||||||
Op: itemADD,
|
Op: itemADD,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardOneToOne},
|
VectorMatching: &VectorMatching{Card: CardOneToOne},
|
||||||
|
@ -389,14 +389,14 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "bla",
|
Name: "bla",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bla"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bla"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "blub",
|
Name: "blub",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "blub"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "blub"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
|
@ -414,30 +414,30 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "baz",
|
Name: "baz",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "baz"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "baz"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "qux",
|
Name: "qux",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "qux"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "qux"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
VectorMatching: &VectorMatching{Card: CardManyToMany},
|
||||||
|
@ -449,22 +449,22 @@ var testExpr = []struct {
|
||||||
Op: itemADD,
|
Op: itemADD,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &BinaryExpr{
|
RHS: &BinaryExpr{
|
||||||
Op: itemDIV,
|
Op: itemDIV,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "bla",
|
Name: "bla",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bla"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bla"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "blub",
|
Name: "blub",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "blub"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "blub"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -486,14 +486,14 @@ var testExpr = []struct {
|
||||||
Op: itemMUL,
|
Op: itemMUL,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -508,14 +508,14 @@ var testExpr = []struct {
|
||||||
Op: itemMUL,
|
Op: itemMUL,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -530,14 +530,14 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -552,14 +552,14 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -574,14 +574,14 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -595,14 +595,14 @@ var testExpr = []struct {
|
||||||
Op: itemLAND,
|
Op: itemLAND,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -616,14 +616,14 @@ var testExpr = []struct {
|
||||||
Op: itemLUnless,
|
Op: itemLUnless,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "baz",
|
Name: "baz",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "baz"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "baz"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -638,14 +638,14 @@ var testExpr = []struct {
|
||||||
Op: itemDIV,
|
Op: itemDIV,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -661,14 +661,14 @@ var testExpr = []struct {
|
||||||
Op: itemDIV,
|
Op: itemDIV,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -683,14 +683,14 @@ var testExpr = []struct {
|
||||||
Op: itemDIV,
|
Op: itemDIV,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -705,14 +705,14 @@ var testExpr = []struct {
|
||||||
Op: itemSUB,
|
Op: itemSUB,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -728,14 +728,14 @@ var testExpr = []struct {
|
||||||
Op: itemSUB,
|
Op: itemSUB,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &VectorSelector{
|
RHS: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
VectorMatching: &VectorMatching{
|
VectorMatching: &VectorMatching{
|
||||||
|
@ -823,8 +823,8 @@ var testExpr = []struct {
|
||||||
expected: &VectorSelector{
|
expected: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -832,8 +832,8 @@ var testExpr = []struct {
|
||||||
expected: &VectorSelector{
|
expected: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Offset: 5 * time.Minute,
|
Offset: 5 * time.Minute,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -841,9 +841,9 @@ var testExpr = []struct {
|
||||||
expected: &VectorSelector{
|
expected: &VectorSelector{
|
||||||
Name: "foo:bar",
|
Name: "foo:bar",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, "a", "bc"),
|
mustLabelMatcher(labels.MatchEqual, "a", "bc"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo:bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo:bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -851,9 +851,9 @@ var testExpr = []struct {
|
||||||
expected: &VectorSelector{
|
expected: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, "NaN", "bc"),
|
mustLabelMatcher(labels.MatchEqual, "NaN", "bc"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -861,12 +861,12 @@ var testExpr = []struct {
|
||||||
expected: &VectorSelector{
|
expected: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, "a", "b"),
|
mustLabelMatcher(labels.MatchEqual, "a", "b"),
|
||||||
mustLabelMatcher(MatchNotEqual, "foo", "bar"),
|
mustLabelMatcher(labels.MatchNotEqual, "foo", "bar"),
|
||||||
mustLabelMatcher(MatchRegexp, "test", "test"),
|
mustLabelMatcher(labels.MatchRegexp, "test", "test"),
|
||||||
mustLabelMatcher(MatchNotRegexp, "bar", "baz"),
|
mustLabelMatcher(labels.MatchNotRegexp, "bar", "baz"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -947,8 +947,8 @@ var testExpr = []struct {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
Range: 5 * time.Second,
|
Range: 5 * time.Second,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "test"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "test"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -957,8 +957,8 @@ var testExpr = []struct {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
Range: 5 * time.Minute,
|
Range: 5 * time.Minute,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "test"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "test"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -967,8 +967,8 @@ var testExpr = []struct {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Offset: 5 * time.Minute,
|
Offset: 5 * time.Minute,
|
||||||
Range: 5 * time.Hour,
|
Range: 5 * time.Hour,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "test"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "test"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -977,8 +977,8 @@ var testExpr = []struct {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Offset: 10 * time.Second,
|
Offset: 10 * time.Second,
|
||||||
Range: 5 * 24 * time.Hour,
|
Range: 5 * 24 * time.Hour,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "test"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "test"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -987,8 +987,8 @@ var testExpr = []struct {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Offset: 14 * 24 * time.Hour,
|
Offset: 14 * 24 * time.Hour,
|
||||||
Range: 5 * 7 * 24 * time.Hour,
|
Range: 5 * 7 * 24 * time.Hour,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "test"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "test"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -997,9 +997,9 @@ var testExpr = []struct {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Offset: 3 * 24 * time.Hour,
|
Offset: 3 * 24 * time.Hour,
|
||||||
Range: 5 * 365 * 24 * time.Hour,
|
Range: 5 * 365 * 24 * time.Hour,
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, "a", "b"),
|
mustLabelMatcher(labels.MatchEqual, "a", "b"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "test"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "test"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -1057,8 +1057,8 @@ var testExpr = []struct {
|
||||||
Op: itemSum,
|
Op: itemSum,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1070,8 +1070,8 @@ var testExpr = []struct {
|
||||||
KeepCommonLabels: true,
|
KeepCommonLabels: true,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1083,8 +1083,8 @@ var testExpr = []struct {
|
||||||
KeepCommonLabels: true,
|
KeepCommonLabels: true,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo", "bar"},
|
Grouping: []string{"foo", "bar"},
|
||||||
|
@ -1095,8 +1095,8 @@ var testExpr = []struct {
|
||||||
Op: itemAvg,
|
Op: itemAvg,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1107,8 +1107,8 @@ var testExpr = []struct {
|
||||||
Op: itemCount,
|
Op: itemCount,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1120,8 +1120,8 @@ var testExpr = []struct {
|
||||||
Op: itemMin,
|
Op: itemMin,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1133,8 +1133,8 @@ var testExpr = []struct {
|
||||||
Op: itemMax,
|
Op: itemMax,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1146,8 +1146,8 @@ var testExpr = []struct {
|
||||||
Without: true,
|
Without: true,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1159,8 +1159,8 @@ var testExpr = []struct {
|
||||||
Without: true,
|
Without: true,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1171,8 +1171,8 @@ var testExpr = []struct {
|
||||||
Op: itemStddev,
|
Op: itemStddev,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1182,8 +1182,8 @@ var testExpr = []struct {
|
||||||
Op: itemStdvar,
|
Op: itemStdvar,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"foo"},
|
Grouping: []string{"foo"},
|
||||||
|
@ -1194,8 +1194,8 @@ var testExpr = []struct {
|
||||||
Op: itemSum,
|
Op: itemSum,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{},
|
Grouping: []string{},
|
||||||
|
@ -1206,8 +1206,8 @@ var testExpr = []struct {
|
||||||
Op: itemTopK,
|
Op: itemTopK,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Param: &NumberLiteral{5},
|
Param: &NumberLiteral{5},
|
||||||
|
@ -1218,8 +1218,8 @@ var testExpr = []struct {
|
||||||
Op: itemCountValues,
|
Op: itemCountValues,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Param: &StringLiteral{"value"},
|
Param: &StringLiteral{"value"},
|
||||||
|
@ -1232,8 +1232,8 @@ var testExpr = []struct {
|
||||||
Without: true,
|
Without: true,
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grouping: []string{"and", "by", "avg", "count", "alert", "annotations"},
|
Grouping: []string{"and", "by", "avg", "count", "alert", "annotations"},
|
||||||
|
@ -1304,9 +1304,9 @@ var testExpr = []struct {
|
||||||
Args: Expressions{
|
Args: Expressions{
|
||||||
&VectorSelector{
|
&VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchNotEqual, "foo", "bar"),
|
mustLabelMatcher(labels.MatchNotEqual, "foo", "bar"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1318,8 +1318,8 @@ var testExpr = []struct {
|
||||||
Args: Expressions{
|
Args: Expressions{
|
||||||
&MatrixSelector{
|
&MatrixSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
Range: 5 * time.Minute,
|
Range: 5 * time.Minute,
|
||||||
},
|
},
|
||||||
|
@ -1332,8 +1332,8 @@ var testExpr = []struct {
|
||||||
Args: Expressions{
|
Args: Expressions{
|
||||||
&VectorSelector{
|
&VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1345,8 +1345,8 @@ var testExpr = []struct {
|
||||||
Args: Expressions{
|
Args: Expressions{
|
||||||
&VectorSelector{
|
&VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&NumberLiteral{5},
|
&NumberLiteral{5},
|
||||||
|
@ -1553,8 +1553,8 @@ var testStatement = []struct {
|
||||||
Args: Expressions{
|
Args: Expressions{
|
||||||
&MatrixSelector{
|
&MatrixSelector{
|
||||||
Name: "http_request_count",
|
Name: "http_request_count",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "http_request_count"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "http_request_count"),
|
||||||
},
|
},
|
||||||
Range: 5 * time.Minute,
|
Range: 5 * time.Minute,
|
||||||
},
|
},
|
||||||
|
@ -1569,8 +1569,8 @@ var testStatement = []struct {
|
||||||
Op: itemLSS,
|
Op: itemLSS,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "dc:http_request:rate5m",
|
Name: "dc:http_request:rate5m",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "dc:http_request:rate5m"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "dc:http_request:rate5m"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &NumberLiteral{10000},
|
RHS: &NumberLiteral{10000},
|
||||||
|
@ -1586,9 +1586,9 @@ var testStatement = []struct {
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, "label1", "value1"),
|
mustLabelMatcher(labels.MatchEqual, "label1", "value1"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: nil,
|
Labels: nil,
|
||||||
|
@ -1599,8 +1599,8 @@ var testStatement = []struct {
|
||||||
Op: itemGTR,
|
Op: itemGTR,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "foo"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &NumberLiteral{10},
|
RHS: &NumberLiteral{10},
|
||||||
|
@ -1620,10 +1620,10 @@ var testStatement = []struct {
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Expr: &VectorSelector{
|
Expr: &VectorSelector{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, "a", "b"),
|
mustLabelMatcher(labels.MatchEqual, "a", "b"),
|
||||||
mustLabelMatcher(MatchRegexp, "x", "y"),
|
mustLabelMatcher(labels.MatchRegexp, "x", "y"),
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "bar"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "bar"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: labels.FromStrings("x", "", "a", "z"),
|
Labels: labels.FromStrings("x", "", "a", "z"),
|
||||||
|
@ -1644,8 +1644,8 @@ var testStatement = []struct {
|
||||||
Op: itemGTR,
|
Op: itemGTR,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "some_metric",
|
Name: "some_metric",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
mustLabelMatcher(MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
mustLabelMatcher(labels.MatchEqual, string(model.MetricNameLabel), "some_metric"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &NumberLiteral{1},
|
RHS: &NumberLiteral{1},
|
||||||
|
@ -1764,8 +1764,8 @@ func TestParseStatements(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustLabelMatcher(mt MatchType, name, val string) *LabelMatcher {
|
func mustLabelMatcher(mt labels.MatchType, name, val string) *labels.Matcher {
|
||||||
m, err := NewLabelMatcher(mt, name, val)
|
m, err := labels.NewMatcher(mt, name, val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ func (node *VectorSelector) String() string {
|
||||||
labelStrings := make([]string, 0, len(node.LabelMatchers)-1)
|
labelStrings := make([]string, 0, len(node.LabelMatchers)-1)
|
||||||
for _, matcher := range node.LabelMatchers {
|
for _, matcher := range node.LabelMatchers {
|
||||||
// Only include the __name__ label if its no equality matching.
|
// Only include the __name__ label if its no equality matching.
|
||||||
if matcher.Name == labels.MetricName && matcher.Type == MatchEqual {
|
if matcher.Name == labels.MetricName && matcher.Type == labels.MatchEqual {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
labelStrings = append(labelStrings, matcher.String())
|
labelStrings = append(labelStrings, matcher.String())
|
||||||
|
|
|
@ -27,8 +27,8 @@ func TestStatementString(t *testing.T) {
|
||||||
Op: itemGTR,
|
Op: itemGTR,
|
||||||
LHS: &VectorSelector{
|
LHS: &VectorSelector{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
LabelMatchers: []*LabelMatcher{
|
LabelMatchers: []*labels.Matcher{
|
||||||
{Type: MatchEqual, Name: MetricNameLabel, Value: "bar"},
|
{Type: labels.MatchEqual, Name: labels.MetricName, Value: "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RHS: &NumberLiteral{10},
|
RHS: &NumberLiteral{10},
|
||||||
|
|
|
@ -23,11 +23,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/storage/local"
|
|
||||||
"github.com/prometheus/prometheus/util/testutil"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,11 +51,11 @@ type Test struct {
|
||||||
|
|
||||||
cmds []testCommand
|
cmds []testCommand
|
||||||
|
|
||||||
storage local.Storage
|
storage storage.Storage
|
||||||
closeStorage func()
|
|
||||||
queryEngine *Engine
|
queryEngine *Engine
|
||||||
context context.Context
|
context context.Context
|
||||||
cancelCtx context.CancelFunc
|
cancelCtx context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTest returns an initialized empty Test.
|
// NewTest returns an initialized empty Test.
|
||||||
|
@ -90,7 +89,7 @@ func (t *Test) Context() context.Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage returns the test's storage.
|
// Storage returns the test's storage.
|
||||||
func (t *Test) Storage() local.Storage {
|
func (t *Test) Storage() storage.Storage {
|
||||||
return t.storage
|
return t.storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +280,7 @@ func (cmd *loadCmd) set(m labels.Labels, vals ...sequenceValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// append the defined time series to the storage.
|
// append the defined time series to the storage.
|
||||||
func (cmd *loadCmd) append(a storage.SampleAppender) {
|
func (cmd *loadCmd) append(a storage.Appender) {
|
||||||
// TODO(fabxc): commented out until Appender refactoring.
|
// TODO(fabxc): commented out until Appender refactoring.
|
||||||
// for fp, samples := range cmd.defs {
|
// for fp, samples := range cmd.defs {
|
||||||
// met := cmd.metrics[fp]
|
// met := cmd.metrics[fp]
|
||||||
|
@ -469,8 +468,15 @@ func (t *Test) exec(tc testCommand) error {
|
||||||
t.clear()
|
t.clear()
|
||||||
|
|
||||||
case *loadCmd:
|
case *loadCmd:
|
||||||
cmd.append(t.storage)
|
app, err := t.storage.Appender()
|
||||||
t.storage.WaitForIndexing()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.append(app)
|
||||||
|
|
||||||
|
if err := app.Commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
case *evalCmd:
|
case *evalCmd:
|
||||||
q := t.queryEngine.newQuery(cmd.expr, cmd.start, cmd.end, cmd.interval)
|
q := t.queryEngine.newQuery(cmd.expr, cmd.start, cmd.end, cmd.interval)
|
||||||
|
@ -498,17 +504,16 @@ func (t *Test) exec(tc testCommand) error {
|
||||||
|
|
||||||
// clear the current test storage of all inserted samples.
|
// clear the current test storage of all inserted samples.
|
||||||
func (t *Test) clear() {
|
func (t *Test) clear() {
|
||||||
if t.closeStorage != nil {
|
if t.storage != nil {
|
||||||
t.closeStorage()
|
if err := t.storage.Close(); err != nil {
|
||||||
|
t.T.Fatalf("closing test storage: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if t.cancelCtx != nil {
|
if t.cancelCtx != nil {
|
||||||
t.cancelCtx()
|
t.cancelCtx()
|
||||||
}
|
}
|
||||||
|
t.storage = testutil.NewStorage(t)
|
||||||
|
|
||||||
var closer testutil.Closer
|
|
||||||
t.storage, closer = local.NewTestStorage(t, 2)
|
|
||||||
|
|
||||||
t.closeStorage = closer.Close
|
|
||||||
// TODO(fabxc): add back
|
// TODO(fabxc): add back
|
||||||
// t.queryEngine = NewEngine(t.storage, nil)
|
// t.queryEngine = NewEngine(t.storage, nil)
|
||||||
t.context, t.cancelCtx = context.WithCancel(context.Background())
|
t.context, t.cancelCtx = context.WithCancel(context.Background())
|
||||||
|
@ -517,7 +522,10 @@ func (t *Test) clear() {
|
||||||
// Close closes resources associated with the Test.
|
// Close closes resources associated with the Test.
|
||||||
func (t *Test) Close() {
|
func (t *Test) Close() {
|
||||||
t.cancelCtx()
|
t.cancelCtx()
|
||||||
t.closeStorage()
|
|
||||||
|
if err := t.storage.Close(); err != nil {
|
||||||
|
t.T.Fatalf("closing test storage: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// samplesAlmostEqual returns true if the two sample lines only differ by a
|
// samplesAlmostEqual returns true if the two sample lines only differ by a
|
||||||
|
|
|
@ -22,12 +22,13 @@ import (
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/storage/local"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRuleEval(t *testing.T) {
|
func TestRuleEval(t *testing.T) {
|
||||||
storage, closer := local.NewTestStorage(t)
|
storage := testutil.NewStorage(t)
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
engine := promql.NewEngine(storage, nil)
|
engine := promql.NewEngine(storage, nil)
|
||||||
ctx, cancelCtx := context.WithCancel(context.Background())
|
ctx, cancelCtx := context.WithCancel(context.Background())
|
||||||
defer cancelCtx()
|
defer cancelCtx()
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
|
// BufferedSeriesIterator wraps an iterator with a look-back buffer.
|
||||||
|
type BufferedSeriesIterator struct {
|
||||||
|
it SeriesIterator
|
||||||
|
buf *sampleRing
|
||||||
|
|
||||||
|
lastTime int64
|
||||||
|
}
|
||||||
|
|
||||||
// NewBuffer returns a new iterator that buffers the values within the time range
|
// NewBuffer returns a new iterator that buffers the values within the time range
|
||||||
// of the current element and the duration of delta before.
|
// of the current element and the duration of delta before.
|
||||||
|
|
|
@ -40,7 +40,7 @@ type Storage interface {
|
||||||
// Querier provides reading access to time series data.
|
// Querier provides reading access to time series data.
|
||||||
type Querier interface {
|
type Querier interface {
|
||||||
// Select returns a set of series that matches the given label matchers.
|
// Select returns a set of series that matches the given label matchers.
|
||||||
Select(...*labels.Matcher) (SeriesSet, error)
|
Select(...*labels.Matcher) SeriesSet
|
||||||
|
|
||||||
// LabelValues returns all potential values for a label name.
|
// LabelValues returns all potential values for a label name.
|
||||||
LabelValues(name string) ([]string, error)
|
LabelValues(name string) ([]string, error)
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// db implements a storage.Storage around TSDB.
|
// adapter implements a storage.Storage around TSDB.
|
||||||
type db struct {
|
type adapter struct {
|
||||||
db *tsdb.DB
|
db *tsdb.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,36 +20,28 @@ func Open(path string) (storage.Storage, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &storage{db: db}
|
return adapter{db: db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *db) Querier(mint, maxt int64) (storage.Querier, error) {
|
func (a adapter) Querier(mint, maxt int64) (storage.Querier, error) {
|
||||||
q, err := db.db.Querier(mint, maxt)
|
return querier{q: a.db.Querier(mint, maxt)}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return querier{q: q}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Appender returns a new appender against the storage.
|
// Appender returns a new appender against the storage.
|
||||||
func (db *db) Appender() (storage.Appender, error) {
|
func (a adapter) Appender() (storage.Appender, error) {
|
||||||
a, err := db.db.Appender()
|
return appender{a: a.db.Appender()}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return appender{a: a}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the storage and all its underlying resources.
|
// Close closes the storage and all its underlying resources.
|
||||||
func (db *db) Close() error {
|
func (a adapter) Close() error {
|
||||||
return db.Close()
|
return a.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
type querier struct {
|
type querier struct {
|
||||||
q tsdb.Querier
|
q tsdb.Querier
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *querier) Select(oms ...*labels.Matcher) (storage.SeriesSet, error) {
|
func (q querier) Select(oms ...*labels.Matcher) storage.SeriesSet {
|
||||||
ms := make([]tsdbLabels.Matcher, 0, len(oms))
|
ms := make([]tsdbLabels.Matcher, 0, len(oms))
|
||||||
|
|
||||||
for _, om := range oms {
|
for _, om := range oms {
|
||||||
|
@ -61,47 +53,47 @@ func (q *querier) Select(oms ...*labels.Matcher) (storage.SeriesSet, error) {
|
||||||
return seriesSet{set: set}
|
return seriesSet{set: set}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *querier) LabelValues(name string) ([]string, error) { return q.q.LabelValues(name) }
|
func (q querier) LabelValues(name string) ([]string, error) { return q.q.LabelValues(name) }
|
||||||
func (q *querier) Close() error { return q.q.Close() }
|
func (q querier) Close() error { return q.q.Close() }
|
||||||
|
|
||||||
type seriesSet struct {
|
type seriesSet struct {
|
||||||
set tsdb.SeriesSet
|
set tsdb.SeriesSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *seriesSet) Next() bool { return s.set.Next() }
|
func (s seriesSet) Next() bool { return s.set.Next() }
|
||||||
func (s *seriesSet) Err() error { return s.set.Err() }
|
func (s seriesSet) Err() error { return s.set.Err() }
|
||||||
func (s *seriesSet) Series() storage.Series { return series{s: s.set.Series()} }
|
func (s seriesSet) Series() storage.Series { return series{s: s.set.Series()} }
|
||||||
|
|
||||||
type series struct {
|
type series struct {
|
||||||
s tsdb.Series
|
s tsdb.Series
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *series) Labels() labels.Labels { return toLabels(s.s.Labels()) }
|
func (s series) Labels() labels.Labels { return toLabels(s.s.Labels()) }
|
||||||
func (s *series) Iterator() storage.SeriesIterator { return storage.SeriesIterator(s.s.Iterator()) }
|
func (s series) Iterator() storage.SeriesIterator { return storage.SeriesIterator(s.s.Iterator()) }
|
||||||
|
|
||||||
type appender struct {
|
type appender struct {
|
||||||
a tsdb.Appender
|
a tsdb.Appender
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *appender) Add(lset labels.Labels, t int64, v float64) { a.Add(toTSDBLabels(lset), t, v) }
|
func (a appender) Add(lset labels.Labels, t int64, v float64) { a.a.Add(toTSDBLabels(lset), t, v) }
|
||||||
func (a *appender) Commit() error { a.a.Commit() }
|
func (a appender) Commit() error { return a.a.Commit() }
|
||||||
|
|
||||||
func convertMatcher(m *labels.Matcher) tsdbLabels.Matcher {
|
func convertMatcher(m *labels.Matcher) tsdbLabels.Matcher {
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case MatchEqual:
|
case labels.MatchEqual:
|
||||||
return tsdbLabels.NewEqualMatcher(m.Name, m.Value)
|
return tsdbLabels.NewEqualMatcher(m.Name, m.Value)
|
||||||
|
|
||||||
case MatchNotEqual:
|
case labels.MatchNotEqual:
|
||||||
return tsdbLabels.Not(tsdbLabels.NewEqualMatcher(m.Name, m.Value))
|
return tsdbLabels.Not(tsdbLabels.NewEqualMatcher(m.Name, m.Value))
|
||||||
|
|
||||||
case MatchRegexp:
|
case labels.MatchRegexp:
|
||||||
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
|
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
case MatchNotRegexp:
|
case labels.MatchNotRegexp:
|
||||||
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
|
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -20,8 +20,9 @@ import (
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/storage/local"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testTemplatesScenario struct {
|
type testTemplatesScenario struct {
|
||||||
|
@ -200,21 +201,20 @@ func TestTemplateExpansion(t *testing.T) {
|
||||||
|
|
||||||
time := model.Time(0)
|
time := model.Time(0)
|
||||||
|
|
||||||
storage, closer := local.NewTestStorage(t, 2)
|
storage := testutil.NewStorage(t)
|
||||||
defer closer.Close()
|
defer storage.Close()
|
||||||
storage.Append(&model.Sample{
|
|
||||||
Metric: model.Metric{
|
app, err := storage.Appender()
|
||||||
model.MetricNameLabel: "metric",
|
if err != nil {
|
||||||
"instance": "a"},
|
t.Fatalf("get appender: %s", err)
|
||||||
Value: 11,
|
}
|
||||||
})
|
|
||||||
storage.Append(&model.Sample{
|
app.Add(labels.FromStrings(labels.MetricName, "metric", "instance", "a"), 0, 11)
|
||||||
Metric: model.Metric{
|
app.Add(labels.FromStrings(labels.MetricName, "metric", "instance", "b"), 0, 21)
|
||||||
model.MetricNameLabel: "metric",
|
|
||||||
"instance": "b"},
|
if err := app.Commit(); err != nil {
|
||||||
Value: 21,
|
t.Fatalf("commit samples: %s", err)
|
||||||
})
|
}
|
||||||
storage.WaitForIndexing()
|
|
||||||
|
|
||||||
engine := promql.NewEngine(storage, nil)
|
engine := promql.NewEngine(storage, nil)
|
||||||
|
|
||||||
|
|
|
@ -4,31 +4,31 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/fabxc/tsdb"
|
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
|
"github.com/prometheus/prometheus/storage/tsdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTestStorage returns a new storage for testing purposes
|
// NewStorage returns a new storage for testing purposes
|
||||||
// that removes all associated files on closing.
|
// that removes all associated files on closing.
|
||||||
func NewTestStorage(t T) storage.Storage {
|
func NewStorage(t T) storage.Storage {
|
||||||
dir, err := ioutil.TempDir("", "test_storage")
|
dir, err := ioutil.TempDir("", "test_storage")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Opening test dir failed: %s", errs)
|
t.Fatalf("Opening test dir failed: %s", err)
|
||||||
}
|
}
|
||||||
db, err := tsdb.Open(dir)
|
db, err := tsdb.Open(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Opening test storage failed: %s", err)
|
t.Fatalf("Opening test storage failed: %s", err)
|
||||||
}
|
}
|
||||||
return testStorage{DB: db, dir: dir}
|
return testStorage{Storage: db, dir: dir}
|
||||||
}
|
}
|
||||||
|
|
||||||
type testStorage struct {
|
type testStorage struct {
|
||||||
*tsdb.DB
|
storage.Storage
|
||||||
dir string
|
dir string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s testStorage) Close() error {
|
func (s testStorage) Close() error {
|
||||||
if err := s.db.Close(); err != nil {
|
if err := s.Storage.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.RemoveAll(s.dir)
|
return os.RemoveAll(s.dir)
|
||||||
|
|
Loading…
Reference in a new issue