mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 06:59:40 -08:00
parent
d6da51f70c
commit
f66850c0fe
|
@ -161,7 +161,7 @@ START_METRIC_SELECTOR
|
|||
// Type definitions for grammar rules.
|
||||
%type <matchers> label_match_list
|
||||
%type <matcher> label_matcher
|
||||
%type <item> aggregate_op grouping_label match_op maybe_label metric_identifier unary_op at_modifier_preprocessors
|
||||
%type <item> aggregate_op grouping_label match_op maybe_label metric_identifier unary_op at_modifier_preprocessors string_identifier
|
||||
%type <labels> label_set metric
|
||||
%type <lblList> label_set_list
|
||||
%type <label> label_set_item
|
||||
|
@ -582,7 +582,11 @@ label_match_list: label_match_list COMMA label_matcher
|
|||
;
|
||||
|
||||
label_matcher : IDENTIFIER match_op STRING
|
||||
{ $$ = yylex.(*parser).newLabelMatcher($1, $2, $3); }
|
||||
{ $$ = yylex.(*parser).newLabelMatcher($1, $2, $3); }
|
||||
| string_identifier match_op STRING
|
||||
{ $$ = yylex.(*parser).newLabelMatcher($1, $2, $3); }
|
||||
| string_identifier
|
||||
{ $$ = yylex.(*parser).newMetricNameMatcher($1); }
|
||||
| IDENTIFIER match_op error
|
||||
{ yylex.(*parser).unexpected("label matching", "string"); $$ = nil}
|
||||
| IDENTIFIER error
|
||||
|
@ -901,7 +905,17 @@ string_literal : STRING
|
|||
PosRange: $1.PositionRange(),
|
||||
}
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
string_identifier : STRING
|
||||
{
|
||||
$$ = Item{
|
||||
Typ: METRIC_IDENTIFIER,
|
||||
Pos: $1.PositionRange().Start,
|
||||
Val: yylex.(*parser).unquoteString($1.Val),
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
/*
|
||||
* Wrappers for optional arguments.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -791,6 +791,18 @@ func (p *parser) checkAST(node Node) (typ ValueType) {
|
|||
// Skip the check for non-empty matchers because an explicit
|
||||
// metric name is a non-empty matcher.
|
||||
break
|
||||
} else {
|
||||
// We also have to make sure a metric name was not set twice inside the
|
||||
// braces.
|
||||
foundMetricName := ""
|
||||
for _, m := range n.LabelMatchers {
|
||||
if m != nil && m.Name == labels.MetricName {
|
||||
if foundMetricName != "" {
|
||||
p.addParseErrf(n.PositionRange(), "metric name must not be set twice: %q or %q", foundMetricName, m.Value)
|
||||
}
|
||||
foundMetricName = m.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A Vector selector must contain at least one non-empty matcher to prevent
|
||||
|
@ -874,6 +886,15 @@ func (p *parser) newLabelMatcher(label, operator, value Item) *labels.Matcher {
|
|||
return m
|
||||
}
|
||||
|
||||
func (p *parser) newMetricNameMatcher(value Item) *labels.Matcher {
|
||||
m, err := labels.NewMatcher(labels.MatchEqual, labels.MetricName, value.Val)
|
||||
if err != nil {
|
||||
p.addParseErr(value.PositionRange(), err)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// addOffset is used to set the offset in the generated parser.
|
||||
func (p *parser) addOffset(e Node, offset time.Duration) {
|
||||
var orgoffsetp *time.Duration
|
||||
|
|
Loading…
Reference in a new issue