Merge pull request #1669 from alileza/master

remove keeping_extra because it's replaced with keep_common
This commit is contained in:
Julius Volz 2016-05-26 15:04:19 -05:00
commit 26f3b7bbc6
7 changed files with 48 additions and 48 deletions

View file

@ -101,11 +101,11 @@ type Expressions []Expr
// AggregateExpr represents an aggregation operation on a vector. // AggregateExpr represents an aggregation operation on a vector.
type AggregateExpr struct { type AggregateExpr struct {
Op itemType // The used aggregation operation. Op itemType // The used aggregation operation.
Expr Expr // The vector expression over which is aggregated. Expr Expr // The vector expression over which is aggregated.
Grouping model.LabelNames // The labels by which to group the vector. Grouping model.LabelNames // The labels by which to group the vector.
Without bool // Whether to drop the given labels rather than keep them. 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. // 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) { switch e := expr.(type) {
case *AggregateExpr: case *AggregateExpr:
vector := ev.evalVector(e.Expr) 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: case *BinaryExpr:
lhs := ev.evalOneOf(e.LHS, model.ValScalar, model.ValVector) lhs := ev.evalOneOf(e.LHS, model.ValScalar, model.ValVector)
@ -1062,7 +1062,7 @@ type groupedAggregation struct {
} }
// aggregation evaluates an aggregation operation on a vector. // 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{} 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. // Add a new group if it doesn't exist.
if !ok { if !ok {
var m metric.Metric var m metric.Metric
if keepExtra { if keepCommon {
m = sample.Metric m = sample.Metric
m.Del(model.MetricNameLabel) m.Del(model.MetricNameLabel)
} else if without { } else if without {
@ -1111,7 +1111,7 @@ func (ev *evaluator) aggregation(op itemType, grouping model.LabelNames, without
continue continue
} }
// Add the sample to the existing group. // Add the sample to the existing group.
if keepExtra { if keepCommon {
groupedResult.labels = labelIntersection(groupedResult.labels, sample.Metric) groupedResult.labels = labelIntersection(groupedResult.labels, sample.Metric)
} }

View file

@ -179,6 +179,7 @@ const (
itemSummary itemSummary
itemDescription itemDescription
itemRunbook itemRunbook
itemKeepExtra
keywordsEnd keywordsEnd
) )
@ -198,25 +199,25 @@ var key = map[string]itemType{
"stdvar": itemStdvar, "stdvar": itemStdvar,
// Keywords. // Keywords.
"alert": itemAlert, "alert": itemAlert,
"if": itemIf, "if": itemIf,
"for": itemFor, "for": itemFor,
"labels": itemLabels, "labels": itemLabels,
"annotations": itemAnnotations, "annotations": itemAnnotations,
"offset": itemOffset, "offset": itemOffset,
"by": itemBy, "by": itemBy,
"without": itemWithout, "without": itemWithout,
"keeping_extra": itemKeepCommon, "keep_common": itemKeepCommon,
"keep_common": itemKeepCommon, "on": itemOn,
"on": itemOn, "ignoring": itemIgnoring,
"ignoring": itemIgnoring, "group_left": itemGroupLeft,
"group_left": itemGroupLeft, "group_right": itemGroupRight,
"group_right": itemGroupRight, "bool": itemBool,
"bool": itemBool,
// Removed keywords. Just here to detect and print errors. // Removed keywords. Just here to detect and print errors.
"summary": itemSummary, "summary": itemSummary,
"description": itemDescription, "description": itemDescription,
"runbook": itemRunbook, "runbook": itemRunbook,
"keeping_extra": itemKeepExtra,
} }
// These are the default string representations for common items. It does not // These are the default string representations for common items. It does not
@ -411,6 +412,8 @@ func (l *lexer) nextItem() item {
t := item.typ t := item.typ
if t == itemSummary || t == itemDescription || t == itemRunbook { 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) 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 return item
} }

View file

@ -248,9 +248,6 @@ var tests = []struct {
{ {
input: "alert", input: "alert",
expected: []item{{itemAlert, 0, "alert"}}, expected: []item{{itemAlert, 0, "alert"}},
}, {
input: "keeping_extra",
expected: []item{{itemKeepCommon, 0, "keeping_extra"}},
}, { }, {
input: "keep_common", input: "keep_common",
expected: []item{{itemKeepCommon, 0, "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) p.errorf("expected aggregation operator but got %s", agop)
} }
var grouping model.LabelNames var grouping model.LabelNames
var keepExtra, without bool var keepCommon, without bool
modifiersFirst := false modifiersFirst := false
@ -709,7 +709,7 @@ func (p *parser) aggrExpr() *AggregateExpr {
} }
if p.peek().typ == itemKeepCommon { if p.peek().typ == itemKeepCommon {
p.next() p.next()
keepExtra = true keepCommon = true
modifiersFirst = true modifiersFirst = true
} }
@ -730,20 +730,20 @@ func (p *parser) aggrExpr() *AggregateExpr {
} }
if p.peek().typ == itemKeepCommon { if p.peek().typ == itemKeepCommon {
p.next() p.next()
keepExtra = true keepCommon = true
} }
} }
if keepExtra && without { if keepCommon && without {
p.errorf("cannot use 'keep_common' with 'without'") p.errorf("cannot use 'keep_common' with 'without'")
} }
return &AggregateExpr{ return &AggregateExpr{
Op: agop.typ, Op: agop.typ,
Expr: e, Expr: e,
Grouping: grouping, Grouping: grouping,
Without: without, Without: without,
KeepExtraLabels: keepExtra, KeepCommonLabels: keepCommon,
} }
} }

View file

@ -1020,8 +1020,8 @@ var testExpr = []struct {
}, { }, {
input: "sum by (foo) keep_common (some_metric)", input: "sum by (foo) keep_common (some_metric)",
expected: &AggregateExpr{ expected: &AggregateExpr{
Op: itemSum, Op: itemSum,
KeepExtraLabels: true, KeepCommonLabels: true,
Expr: &VectorSelector{ Expr: &VectorSelector{
Name: "some_metric", Name: "some_metric",
LabelMatchers: metric.LabelMatchers{ LabelMatchers: metric.LabelMatchers{
@ -1033,8 +1033,8 @@ var testExpr = []struct {
}, { }, {
input: "sum (some_metric) by (foo,bar) keep_common", input: "sum (some_metric) by (foo,bar) keep_common",
expected: &AggregateExpr{ expected: &AggregateExpr{
Op: itemSum, Op: itemSum,
KeepExtraLabels: true, KeepCommonLabels: true,
Expr: &VectorSelector{ Expr: &VectorSelector{
Name: "some_metric", Name: "some_metric",
LabelMatchers: metric.LabelMatchers{ LabelMatchers: metric.LabelMatchers{
@ -1065,8 +1065,8 @@ var testExpr = []struct {
{Type: metric.Equal, Name: model.MetricNameLabel, Value: "some_metric"}, {Type: metric.Equal, Name: model.MetricNameLabel, Value: "some_metric"},
}, },
}, },
Grouping: model.LabelNames{"foo"}, Grouping: model.LabelNames{"foo"},
KeepExtraLabels: true, KeepCommonLabels: true,
}, },
}, { }, {
input: "MIN (some_metric) by (foo) keep_common", input: "MIN (some_metric) by (foo) keep_common",
@ -1078,8 +1078,8 @@ var testExpr = []struct {
{Type: metric.Equal, Name: model.MetricNameLabel, Value: "some_metric"}, {Type: metric.Equal, Name: model.MetricNameLabel, Value: "some_metric"},
}, },
}, },
Grouping: model.LabelNames{"foo"}, Grouping: model.LabelNames{"foo"},
KeepExtraLabels: true, KeepCommonLabels: true,
}, },
}, { }, {
input: "max by (foo)(some_metric)", input: "max by (foo)(some_metric)",

View file

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