Merge pull request #1669 from alileza/master

remove keeping_extra because it's replaced with keep_common
pull/1658/head
Julius Volz 2016-05-26 15:04:19 -05:00
commit 26f3b7bbc6
7 changed files with 48 additions and 48 deletions

View File

@ -105,7 +105,7 @@ type AggregateExpr struct {
Expr Expr // The vector expression over which is aggregated.
Grouping model.LabelNames // The labels by which to group the vector.
Without bool // Whether to drop the given labels rather than keep them.
KeepExtraLabels bool // Whether to keep extra labels common among result elements.
KeepCommonLabels bool // Whether to keep common labels among result elements.
}
// BinaryExpr represents a binary expression between two child expressions.

View File

@ -610,7 +610,7 @@ func (ev *evaluator) eval(expr Expr) model.Value {
switch e := expr.(type) {
case *AggregateExpr:
vector := ev.evalVector(e.Expr)
return ev.aggregation(e.Op, e.Grouping, e.Without, e.KeepExtraLabels, vector)
return ev.aggregation(e.Op, e.Grouping, e.Without, e.KeepCommonLabels, vector)
case *BinaryExpr:
lhs := ev.evalOneOf(e.LHS, model.ValScalar, model.ValVector)
@ -1062,7 +1062,7 @@ type groupedAggregation struct {
}
// aggregation evaluates an aggregation operation on a vector.
func (ev *evaluator) aggregation(op itemType, grouping model.LabelNames, without bool, keepExtra bool, vec vector) vector {
func (ev *evaluator) aggregation(op itemType, grouping model.LabelNames, without bool, keepCommon bool, vec vector) vector {
result := map[uint64]*groupedAggregation{}
@ -1086,7 +1086,7 @@ func (ev *evaluator) aggregation(op itemType, grouping model.LabelNames, without
// Add a new group if it doesn't exist.
if !ok {
var m metric.Metric
if keepExtra {
if keepCommon {
m = sample.Metric
m.Del(model.MetricNameLabel)
} else if without {
@ -1111,7 +1111,7 @@ func (ev *evaluator) aggregation(op itemType, grouping model.LabelNames, without
continue
}
// Add the sample to the existing group.
if keepExtra {
if keepCommon {
groupedResult.labels = labelIntersection(groupedResult.labels, sample.Metric)
}

View File

@ -179,6 +179,7 @@ const (
itemSummary
itemDescription
itemRunbook
itemKeepExtra
keywordsEnd
)
@ -206,7 +207,6 @@ var key = map[string]itemType{
"offset": itemOffset,
"by": itemBy,
"without": itemWithout,
"keeping_extra": itemKeepCommon,
"keep_common": itemKeepCommon,
"on": itemOn,
"ignoring": itemIgnoring,
@ -217,6 +217,7 @@ var key = map[string]itemType{
"summary": itemSummary,
"description": itemDescription,
"runbook": itemRunbook,
"keeping_extra": itemKeepExtra,
}
// These are the default string representations for common items. It does not
@ -411,6 +412,8 @@ func (l *lexer) nextItem() item {
t := item.typ
if t == itemSummary || t == itemDescription || t == itemRunbook {
log.Errorf("Token %q is not valid anymore. Alerting rule syntax has changed with version 0.17.0. Please read https://prometheus.io/docs/alerting/rules/.", item)
} else if t == itemKeepExtra {
log.Error("Token 'keeping_extra' is not valid anymore. Use 'keep_common' instead.")
}
return item
}

View File

@ -248,9 +248,6 @@ var tests = []struct {
{
input: "alert",
expected: []item{{itemAlert, 0, "alert"}},
}, {
input: "keeping_extra",
expected: []item{{itemKeepCommon, 0, "keeping_extra"}},
}, {
input: "keep_common",
expected: []item{{itemKeepCommon, 0, "keep_common"}},

View File

@ -695,7 +695,7 @@ func (p *parser) aggrExpr() *AggregateExpr {
p.errorf("expected aggregation operator but got %s", agop)
}
var grouping model.LabelNames
var keepExtra, without bool
var keepCommon, without bool
modifiersFirst := false
@ -709,7 +709,7 @@ func (p *parser) aggrExpr() *AggregateExpr {
}
if p.peek().typ == itemKeepCommon {
p.next()
keepExtra = true
keepCommon = true
modifiersFirst = true
}
@ -730,11 +730,11 @@ func (p *parser) aggrExpr() *AggregateExpr {
}
if p.peek().typ == itemKeepCommon {
p.next()
keepExtra = true
keepCommon = true
}
}
if keepExtra && without {
if keepCommon && without {
p.errorf("cannot use 'keep_common' with 'without'")
}
@ -743,7 +743,7 @@ func (p *parser) aggrExpr() *AggregateExpr {
Expr: e,
Grouping: grouping,
Without: without,
KeepExtraLabels: keepExtra,
KeepCommonLabels: keepCommon,
}
}

View File

@ -1021,7 +1021,7 @@ var testExpr = []struct {
input: "sum by (foo) keep_common (some_metric)",
expected: &AggregateExpr{
Op: itemSum,
KeepExtraLabels: true,
KeepCommonLabels: true,
Expr: &VectorSelector{
Name: "some_metric",
LabelMatchers: metric.LabelMatchers{
@ -1034,7 +1034,7 @@ var testExpr = []struct {
input: "sum (some_metric) by (foo,bar) keep_common",
expected: &AggregateExpr{
Op: itemSum,
KeepExtraLabels: true,
KeepCommonLabels: true,
Expr: &VectorSelector{
Name: "some_metric",
LabelMatchers: metric.LabelMatchers{
@ -1066,7 +1066,7 @@ var testExpr = []struct {
},
},
Grouping: model.LabelNames{"foo"},
KeepExtraLabels: true,
KeepCommonLabels: true,
},
}, {
input: "MIN (some_metric) by (foo) keep_common",
@ -1079,7 +1079,7 @@ var testExpr = []struct {
},
},
Grouping: model.LabelNames{"foo"},
KeepExtraLabels: true,
KeepCommonLabels: true,
},
}, {
input: "max by (foo)(some_metric)",

View File

@ -145,7 +145,7 @@ func (node *AggregateExpr) String() string {
}
aggrString = fmt.Sprintf(format, aggrString, node.Grouping)
}
if node.KeepExtraLabels {
if node.KeepCommonLabels {
aggrString += " KEEP_COMMON"
}
return aggrString