|
|
@ -371,9 +371,10 @@ func (p *parser) alertStmt() *AlertStmt {
|
|
|
|
expr := p.expr()
|
|
|
|
expr := p.expr()
|
|
|
|
|
|
|
|
|
|
|
|
// Optional for clause.
|
|
|
|
// Optional for clause.
|
|
|
|
var duration time.Duration
|
|
|
|
var (
|
|
|
|
var err error
|
|
|
|
duration time.Duration
|
|
|
|
|
|
|
|
err error
|
|
|
|
|
|
|
|
)
|
|
|
|
if p.peek().typ == itemFor {
|
|
|
|
if p.peek().typ == itemFor {
|
|
|
|
p.next()
|
|
|
|
p.next()
|
|
|
|
dur := p.expect(itemDuration, ctx)
|
|
|
|
dur := p.expect(itemDuration, ctx)
|
|
|
@ -383,23 +384,64 @@ func (p *parser) alertStmt() *AlertStmt {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lset := model.LabelSet{}
|
|
|
|
// Accepting WITH instead of LABELS is temporary compatibility
|
|
|
|
if p.peek().typ == itemLabels {
|
|
|
|
// with the old alerting syntax.
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
hasLabels bool
|
|
|
|
|
|
|
|
oldSyntax bool
|
|
|
|
|
|
|
|
labels = model.LabelSet{}
|
|
|
|
|
|
|
|
annotations = model.LabelSet{}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if t := p.peek().typ; t == itemLabels {
|
|
|
|
p.expect(itemLabels, ctx)
|
|
|
|
p.expect(itemLabels, ctx)
|
|
|
|
lset = p.labelSet()
|
|
|
|
labels = p.labelSet()
|
|
|
|
|
|
|
|
hasLabels = true
|
|
|
|
|
|
|
|
} else if t == itemWith {
|
|
|
|
|
|
|
|
p.expect(itemWith, ctx)
|
|
|
|
|
|
|
|
labels = p.labelSet()
|
|
|
|
|
|
|
|
oldSyntax = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
annotations := model.LabelSet{}
|
|
|
|
// Only allow old annotation syntax if new label syntax isn't used.
|
|
|
|
|
|
|
|
if !hasLabels {
|
|
|
|
|
|
|
|
Loop:
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
switch p.next().typ {
|
|
|
|
|
|
|
|
case itemSummary:
|
|
|
|
|
|
|
|
annotations["summary"] = model.LabelValue(p.unquoteString(p.expect(itemString, ctx).val))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case itemDescription:
|
|
|
|
|
|
|
|
annotations["description"] = model.LabelValue(p.unquoteString(p.expect(itemString, ctx).val))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case itemRunbook:
|
|
|
|
|
|
|
|
annotations["runbook"] = model.LabelValue(p.unquoteString(p.expect(itemString, ctx).val))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
p.backup()
|
|
|
|
|
|
|
|
break Loop
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(annotations) > 0 {
|
|
|
|
|
|
|
|
oldSyntax = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only allow new annotation syntax if WITH or old annotation
|
|
|
|
|
|
|
|
// syntax weren't used.
|
|
|
|
|
|
|
|
if !oldSyntax {
|
|
|
|
if p.peek().typ == itemAnnotations {
|
|
|
|
if p.peek().typ == itemAnnotations {
|
|
|
|
p.expect(itemAnnotations, ctx)
|
|
|
|
p.expect(itemAnnotations, ctx)
|
|
|
|
annotations = p.labelSet()
|
|
|
|
annotations = p.labelSet()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.Warnf("Alerting rule with old syntax found. Support for this syntax will be removed with 0.18. Please update to the new syntax.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &AlertStmt{
|
|
|
|
return &AlertStmt{
|
|
|
|
Name: name.val,
|
|
|
|
Name: name.val,
|
|
|
|
Expr: expr,
|
|
|
|
Expr: expr,
|
|
|
|
Duration: duration,
|
|
|
|
Duration: duration,
|
|
|
|
Labels: lset,
|
|
|
|
Labels: labels,
|
|
|
|
Annotations: annotations,
|
|
|
|
Annotations: annotations,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|