Skip to content

Commit

Permalink
[querier] update promql empty value match
Browse files Browse the repository at this point in the history
  • Loading branch information
taloric committed Jun 21, 2024
1 parent 2a691ac commit d9c1fa4
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions server/querier/app/prometheus/service/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ func (p *prometheusReader) promReaderTransToSQL(ctx context.Context, req *prompb
filters = append(filters, fmt.Sprintf("(%s)", strings.Join(tmpFilters, " OR ")))
} else {
// () with only ONE condition in it will cause error
filters = append(filters, fmt.Sprintf("%s %s '%s'", tagMatcher, operation, escapeSingleQuote(value[0])))
if value[0] == "" {
filters = append(filters, fmt.Sprintf("%s(%s)", operation, tagMatcher))
} else {
filters = append(filters, fmt.Sprintf("%s %s '%s'", tagMatcher, operation, escapeSingleQuote(value[0])))
}
}

if db == "" || db == chCommon.DB_NAME_PROMETHEUS || db == chCommon.DB_NAME_EXT_METRICS {
Expand Down Expand Up @@ -992,7 +996,11 @@ func (p *prometheusReader) parseQueryRequestToSQL(ctx context.Context, queryReq
}
filters = append(filters, fmt.Sprintf("(%s)", strings.Join(tmpFilters, " OR ")))
} else {
filters = append(filters, fmt.Sprintf("%s %s '%s'", tagMatcher, operation, escapeSingleQuote(value[0])))
if value[0] == "" {
filters = append(filters, fmt.Sprintf("%s(%s)", operation, tagMatcher))
} else {
filters = append(filters, fmt.Sprintf("%s %s '%s'", tagMatcher, operation, escapeSingleQuote(value[0])))
}
}

if isDeepFlowTag && cap(groupBy) == 0 {
Expand Down Expand Up @@ -1107,15 +1115,23 @@ func parseMatcherType(t labels.MatchType) prompb.LabelMatcher_Type {
func getLabelMatcher(t prompb.LabelMatcher_Type, v string) (string, []string) {
switch t {
case prompb.LabelMatcher_EQ:
return "=", []string{v}
if v == "" {
return "not exist", []string{v}
} else {
return "=", []string{v}
}
case prompb.LabelMatcher_NEQ:
return "!=", []string{v}
if v == "" {
return "exist", []string{v}
} else {
return "!=", []string{v}
}
case prompb.LabelMatcher_RE:
// for regex like 'a|b', convert to 'tag=a OR tag=b'
if _match_fullmatch_reg.MatchString(v) {
return "=", strings.Split(v, "|")
} else if v == "" {
return "=", []string{v}
return "not exist", []string{v}
} else {
return "REGEXP", []string{appendRegexRules(v)}
}
Expand All @@ -1124,7 +1140,7 @@ func getLabelMatcher(t prompb.LabelMatcher_Type, v string) (string, []string) {
if _match_fullmatch_reg.MatchString(v) {
return "!=", strings.Split(v, "|")
} else if v == "" {
return "!=", []string{v}
return "exist", []string{v}
} else {
return "NOT REGEXP", []string{appendRegexRules(v)}
}
Expand Down

0 comments on commit d9c1fa4

Please sign in to comment.