mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Merge pull request #1669 from alileza/master
remove keeping_extra because it's replaced with keep_common
This commit is contained in:
commit
26f3b7bbc6
|
@ -101,11 +101,11 @@ type Expressions []Expr
|
|||
|
||||
// AggregateExpr represents an aggregation operation on a vector.
|
||||
type AggregateExpr struct {
|
||||
Op itemType // The used aggregation operation.
|
||||
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.
|
||||
Op itemType // The used aggregation operation.
|
||||
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.
|
||||
KeepCommonLabels bool // Whether to keep common labels among result elements.
|
||||
}
|
||||
|
||||
// BinaryExpr represents a binary expression between two child expressions.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -179,6 +179,7 @@ const (
|
|||
itemSummary
|
||||
itemDescription
|
||||
itemRunbook
|
||||
itemKeepExtra
|
||||
keywordsEnd
|
||||
)
|
||||
|
||||
|
@ -198,25 +199,25 @@ var key = map[string]itemType{
|
|||
"stdvar": itemStdvar,
|
||||
|
||||
// Keywords.
|
||||
"alert": itemAlert,
|
||||
"if": itemIf,
|
||||
"for": itemFor,
|
||||
"labels": itemLabels,
|
||||
"annotations": itemAnnotations,
|
||||
"offset": itemOffset,
|
||||
"by": itemBy,
|
||||
"without": itemWithout,
|
||||
"keeping_extra": itemKeepCommon,
|
||||
"keep_common": itemKeepCommon,
|
||||
"on": itemOn,
|
||||
"ignoring": itemIgnoring,
|
||||
"group_left": itemGroupLeft,
|
||||
"group_right": itemGroupRight,
|
||||
"bool": itemBool,
|
||||
"alert": itemAlert,
|
||||
"if": itemIf,
|
||||
"for": itemFor,
|
||||
"labels": itemLabels,
|
||||
"annotations": itemAnnotations,
|
||||
"offset": itemOffset,
|
||||
"by": itemBy,
|
||||
"without": itemWithout,
|
||||
"keep_common": itemKeepCommon,
|
||||
"on": itemOn,
|
||||
"ignoring": itemIgnoring,
|
||||
"group_left": itemGroupLeft,
|
||||
"group_right": itemGroupRight,
|
||||
"bool": itemBool,
|
||||
// Removed keywords. Just here to detect and print errors.
|
||||
"summary": itemSummary,
|
||||
"description": itemDescription,
|
||||
"runbook": itemRunbook,
|
||||
"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
|
||||
}
|
||||
|
|
|
@ -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"}},
|
||||
|
|
|
@ -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,20 +730,20 @@ 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'")
|
||||
}
|
||||
|
||||
return &AggregateExpr{
|
||||
Op: agop.typ,
|
||||
Expr: e,
|
||||
Grouping: grouping,
|
||||
Without: without,
|
||||
KeepExtraLabels: keepExtra,
|
||||
Op: agop.typ,
|
||||
Expr: e,
|
||||
Grouping: grouping,
|
||||
Without: without,
|
||||
KeepCommonLabels: keepCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1020,8 +1020,8 @@ var testExpr = []struct {
|
|||
}, {
|
||||
input: "sum by (foo) keep_common (some_metric)",
|
||||
expected: &AggregateExpr{
|
||||
Op: itemSum,
|
||||
KeepExtraLabels: true,
|
||||
Op: itemSum,
|
||||
KeepCommonLabels: true,
|
||||
Expr: &VectorSelector{
|
||||
Name: "some_metric",
|
||||
LabelMatchers: metric.LabelMatchers{
|
||||
|
@ -1033,8 +1033,8 @@ var testExpr = []struct {
|
|||
}, {
|
||||
input: "sum (some_metric) by (foo,bar) keep_common",
|
||||
expected: &AggregateExpr{
|
||||
Op: itemSum,
|
||||
KeepExtraLabels: true,
|
||||
Op: itemSum,
|
||||
KeepCommonLabels: true,
|
||||
Expr: &VectorSelector{
|
||||
Name: "some_metric",
|
||||
LabelMatchers: metric.LabelMatchers{
|
||||
|
@ -1065,8 +1065,8 @@ var testExpr = []struct {
|
|||
{Type: metric.Equal, Name: model.MetricNameLabel, Value: "some_metric"},
|
||||
},
|
||||
},
|
||||
Grouping: model.LabelNames{"foo"},
|
||||
KeepExtraLabels: true,
|
||||
Grouping: model.LabelNames{"foo"},
|
||||
KeepCommonLabels: true,
|
||||
},
|
||||
}, {
|
||||
input: "MIN (some_metric) by (foo) keep_common",
|
||||
|
@ -1078,8 +1078,8 @@ var testExpr = []struct {
|
|||
{Type: metric.Equal, Name: model.MetricNameLabel, Value: "some_metric"},
|
||||
},
|
||||
},
|
||||
Grouping: model.LabelNames{"foo"},
|
||||
KeepExtraLabels: true,
|
||||
Grouping: model.LabelNames{"foo"},
|
||||
KeepCommonLabels: true,
|
||||
},
|
||||
}, {
|
||||
input: "max by (foo)(some_metric)",
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue