Skip to content

Commit

Permalink
feat: querier supports select alert resource
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 committed Nov 4, 2024
1 parent dbe93b7 commit 9f16c56
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
5 changes: 5 additions & 0 deletions server/querier/engine/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,11 @@ var (
db: "_prometheus",
input: "SHOW tag-values",
output: []string{"SELECT field_name AS `label_name`, field_value AS `label_value` FROM flow_tag.`prometheus_custom_field_value` GROUP BY `label_name`, `label_value` ORDER BY `label_name` asc LIMIT 10000"},
}, {
name: "test_alert",
db: "event",
input: "SELECT Count(row), alert_policy, alert_policy_id, event_level, auto_service_0, auto_service_type_0, auto_service_type_1, auto_service_1 FROM alert_event where time >1730706654 GROUP BY alert_policy, alert_policy_id, event_level, auto_service_0, auto_service_type_0, auto_service_type_1, auto_service_1 LIMIT 1",
output: []string{"SELECT dictGet('flow_tag.alarm_policy_map', 'name', (toUInt64(policy_id))) AS `alert_policy`, policy_id AS `alert_policy_id`, event_level, tag_string_values[indexOf(tag_string_names,'auto_service_0')] AS `auto_service_0`, tag_int_values[indexOf(tag_int_names,'auto_service_type_0')] AS `auto_service_type_0`, tag_int_values[indexOf(tag_int_names,'auto_service_type_1')] AS `auto_service_type_1`, tag_string_values[indexOf(tag_string_names,'auto_service_1')] AS `auto_service_1`, COUNT(1) AS `Count(row)` FROM event.`alert_event` PREWHERE `time` > 1730706654 AND (policy_id!=0) GROUP BY dictGet('flow_tag.alarm_policy_map', 'name', (toUInt64(policy_id))) AS `alert_policy`, policy_id AS `alert_policy_id`, `event_level`, tag_string_values[indexOf(tag_string_names,'auto_service_0')] AS `auto_service_0`, `auto_service_type_0`, tag_int_values[indexOf(tag_int_names,'auto_service_type_0')] AS `auto_service_type_0`, tag_int_values[indexOf(tag_int_names,'auto_service_type_1')] AS `auto_service_type_1`, tag_string_values[indexOf(tag_string_names,'auto_service_1')] AS `auto_service_1` LIMIT 1"},
}}
)

Expand Down
15 changes: 13 additions & 2 deletions server/querier/engine/clickhouse/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,20 @@ func GetTagTranslator(name, alias string, e *CHEngine) ([]Statement, string, err
selectTag = alias
}
labelType := ""
tagItem, ok := tag.GetTag(strings.Trim(name, "`"), db, table, "default")
nameNoBackQuote := strings.Trim(name, "`")
tagItem, ok := tag.GetTag(nameNoBackQuote, db, table, "default")
if table == "alert_event" {
if ok {
if slices.Contains(tag.AUTO_CUSTOM_TAG_NAMES, nameNoBackQuote) {
autoTagMap := tagItem.TagTranslatorMap
autoTagSlice := []string{}
for autoTagKey, _ := range autoTagMap {
autoTagSlice = append(autoTagSlice, autoTagKey)
}
sort.Strings(autoTagSlice)
for _, autoTagKey := range autoTagSlice {
stmts = append(stmts, &SelectTag{Value: autoTagMap[autoTagKey], Alias: "`" + autoTagKey + "`"})
}
} else if ok {
tagTranslator := tagItem.TagTranslator
stmts = append(stmts, &SelectTag{Value: tagTranslator, Alias: selectTag})
} else {
Expand Down
Loading

0 comments on commit 9f16c56

Please sign in to comment.