Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[querier] Support tag is equal to empty #4457

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions server/querier/engine/clickhouse/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,25 @@ func GetPrometheusFilter(promTag, table, op, value string) (string, error) {
}
labelNameID, ok := Prometheus.LabelNameToID[nameNoPreffix]
if !ok {
errorMessage := fmt.Sprintf("%s not found", nameNoPreffix)
return filter, errors.New(errorMessage)
if value == "" {
filter = "1=1"
} else {
filter = "1!=1"
}
debugMessage := fmt.Sprintf("%s not found", nameNoPreffix)
log.Debug(debugMessage)
return filter, nil
}
// Determine whether the tag is app_label or target_label
isAppLabel := false
if appLabels, ok := Prometheus.MetricAppLabelLayout[table]; ok {
for _, appLabel := range appLabels {
if appLabel.AppLabelName == nameNoPreffix {
isAppLabel = true
if value == "" {
filter = fmt.Sprintf("app_label_value_id_%d = 0", appLabel.appLabelColumnIndex)
return filter, nil
}
if strings.Contains(op, "match") {
filter = fmt.Sprintf("toUInt64(app_label_value_id_%d) IN (SELECT label_value_id FROM flow_tag.app_label_live_view WHERE label_name_id=%d and %s(label_value,%s))", appLabel.appLabelColumnIndex, labelNameID, op, value)
} else {
Expand Down Expand Up @@ -846,8 +856,14 @@ func GetRemoteReadFilter(promTag, table, op, value, originFilter string, e *CHEn
}
labelNameID, ok := Prometheus.LabelNameToID[nameNoPreffix]
if !ok {
errorMessage := fmt.Sprintf("%s not found", nameNoPreffix)
return filter, errors.New(errorMessage)
if value == "" {
filter = "1=1"
} else {
filter = "1!=1"
}
debugMessage := fmt.Sprintf("%s not found", nameNoPreffix)
log.Debug(debugMessage)
return filter, nil
}
prometheusSubqueryCache := GetPrometheusSubqueryCache()
// Determine whether the tag is app_label or target_label
Expand All @@ -863,6 +879,12 @@ func GetRemoteReadFilter(promTag, table, op, value, originFilter string, e *CHEn
return filter, nil
}
}
if value == "" {
filter = fmt.Sprintf("app_label_value_id_%d = 0", appLabel.appLabelColumnIndex)
entryValue := common.EntryValue{Time: time.Now(), Filter: filter}
prometheusSubqueryCache.PrometheusSubqueryCache.Add(originFilter, entryValue)
return filter, nil
}

// lru timeout
if strings.Contains(op, "match") {
Expand Down Expand Up @@ -909,7 +931,6 @@ func GetRemoteReadFilter(promTag, table, op, value, originFilter string, e *CHEn
}
targetLabelFilter := TargetLabelFilter{OriginFilter: originFilter, TransFilter: transFilter}
e.TargetLabelFilters = append(e.TargetLabelFilters, targetLabelFilter)
// FIXME delete placeholders
filter = ""
}
return filter, nil
Expand Down
Loading