Skip to content

Commit

Permalink
fix: querier TopK supporrt resource_id
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 authored and SongZhen0704 committed Sep 27, 2024
1 parent 347268f commit 2b35e20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 13 additions & 1 deletion server/querier/engine/clickhouse/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,19 @@ func GetTopKTrans(name string, args []string, alias string, e *CHEngine) (Statem
}

if condition == "" && metricStruct.TagType != "int" {
condition = dbFields[i] + " != ''"
if metricStruct.TagType == "string" || metricStruct.TagType == "ip" {
condition = dbFields[i] + " != ''"
} else if metricStruct.TagType == "int" || metricStruct.TagType == "id" {
condition = dbFields[i] + " != 0"
} else if metricStruct.TagType == "resource" && strings.Contains(metricStruct.DisplayName, "_id") {
if strings.Contains(metricStruct.DisplayName, "epc") {
condition = dbFields[i] + " != -2"
} else {
condition = dbFields[i] + " != 0"
}
} else {
condition = dbFields[i] + " != ''"
}
conditions = append(conditions, condition)
}

Expand Down
13 changes: 11 additions & 2 deletions server/querier/engine/clickhouse/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,20 @@ func GetMetrics(field, db, table, orgID string) (*Metrics, bool) {
if ok {
return metric, ok
} else {
// xx_id is not a metric
// resource type xx_id is a metric
if strings.Contains(field, "_id") {
noIDField := strings.ReplaceAll(field, "_id", "")
_, ok = newAllMetrics[noIDField]
noIDMetric, ok := newAllMetrics[noIDField]
if ok {
idMetric := noIDMetric
idMetric.DisplayName = field
idMetric.DBField, err = GetTagDBField(field, db, table, orgID)
if err != nil {
log.Error("Failed to get tag db field")
return nil, false
}
return idMetric, ok
} else {
return nil, false
}
}
Expand Down

0 comments on commit 2b35e20

Please sign in to comment.