mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 23:19:41 -08:00
parent
d6da51f70c
commit
f66850c0fe
|
@ -161,7 +161,7 @@ START_METRIC_SELECTOR
|
||||||
// Type definitions for grammar rules.
|
// Type definitions for grammar rules.
|
||||||
%type <matchers> label_match_list
|
%type <matchers> label_match_list
|
||||||
%type <matcher> label_matcher
|
%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 <labels> label_set metric
|
||||||
%type <lblList> label_set_list
|
%type <lblList> label_set_list
|
||||||
%type <label> label_set_item
|
%type <label> label_set_item
|
||||||
|
@ -582,7 +582,11 @@ label_match_list: label_match_list COMMA label_matcher
|
||||||
;
|
;
|
||||||
|
|
||||||
label_matcher : IDENTIFIER match_op STRING
|
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
|
| IDENTIFIER match_op error
|
||||||
{ yylex.(*parser).unexpected("label matching", "string"); $$ = nil}
|
{ yylex.(*parser).unexpected("label matching", "string"); $$ = nil}
|
||||||
| IDENTIFIER error
|
| IDENTIFIER error
|
||||||
|
@ -901,7 +905,17 @@ string_literal : STRING
|
||||||
PosRange: $1.PositionRange(),
|
PosRange: $1.PositionRange(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
string_identifier : STRING
|
||||||
|
{
|
||||||
|
$$ = Item{
|
||||||
|
Typ: METRIC_IDENTIFIER,
|
||||||
|
Pos: $1.PositionRange().Start,
|
||||||
|
Val: yylex.(*parser).unquoteString($1.Val),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrappers for optional arguments.
|
* 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
|
// Skip the check for non-empty matchers because an explicit
|
||||||
// metric name is a non-empty matcher.
|
// metric name is a non-empty matcher.
|
||||||
break
|
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
|
// 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
|
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.
|
// addOffset is used to set the offset in the generated parser.
|
||||||
func (p *parser) addOffset(e Node, offset time.Duration) {
|
func (p *parser) addOffset(e Node, offset time.Duration) {
|
||||||
var orgoffsetp *time.Duration
|
var orgoffsetp *time.Duration
|
||||||
|
|
Loading…
Reference in a new issue