Skip to content

Commit

Permalink
fix: querier converts types when using dictget
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 authored and SongZhen0704 committed Aug 29, 2024
1 parent fc752ea commit e23b3f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions server/querier/engine/clickhouse/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ func GetPrometheusGroup(name string, e *CHEngine) string {
for _, appLabel := range appLabels {
if appLabel.AppLabelName == nameNoPreffix {
isAppLabel = true
tagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.app_label_map', 'label_value', (%d, app_label_value_id_%d))", labelNameID, appLabel.AppLabelColumnIndex)
tagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.app_label_map', 'label_value', (%d, toUInt64(app_label_value_id_%d)))", labelNameID, appLabel.AppLabelColumnIndex)
break
}
}
}
if !isAppLabel {
tagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.target_label_map', 'label_value', (%d, %d, target_id))", metricID, labelNameID)
tagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.target_label_map', 'label_value', (%d, %d, toUInt64(target_id)))", metricID, labelNameID)
}
} else {
tagTranslatorStr = name
Expand Down
8 changes: 4 additions & 4 deletions server/querier/engine/clickhouse/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,14 @@ func GetPrometheusSingleTagTranslator(tag, table, orgID string) (string, string,
if appLabel.AppLabelName == nameNoPreffix {
isAppLabel = true
labelType = "app"
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.app_label_map', 'label_value', (%d, app_label_value_id_%d))", labelNameID, appLabel.AppLabelColumnIndex)
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.app_label_map', 'label_value', (%d, toUInt64(app_label_value_id_%d)))", labelNameID, appLabel.AppLabelColumnIndex)
break
}
}
}
if !isAppLabel {
labelType = "target"
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.target_label_map', 'label_value', (%d, %d, target_id))", metricID, labelNameID)
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.target_label_map', 'label_value', (%d, %d, toUInt64(target_id)))", metricID, labelNameID)
}
return TagTranslatorStr, labelType, nil
}
Expand All @@ -542,15 +542,15 @@ func GetPrometheusAllTagTranslator(table, orgID string) (string, error) {
appLabelTranslatorSlice := []string{}
for _, appLabel := range appLabels {
if labelNameID, ok := trans_prometheus.ORGPrometheus[orgID].LabelNameToID[appLabel.AppLabelName]; ok {
appLabelTranslator := fmt.Sprintf("'%s',dictGet('flow_tag.app_label_map', 'label_value', (%d, app_label_value_id_%d))", appLabel.AppLabelName, labelNameID, appLabel.AppLabelColumnIndex)
appLabelTranslator := fmt.Sprintf("'%s',dictGet('flow_tag.app_label_map', 'label_value', (%d, toUInt64(app_label_value_id_%d)))", appLabel.AppLabelName, labelNameID, appLabel.AppLabelColumnIndex)
appLabelTranslatorSlice = append(appLabelTranslatorSlice, appLabelTranslator)
}
}
appLabelTranslatorStr = strings.Join(appLabelTranslatorSlice, ",")
}

// targetLabel
targetLabelTranslatorStr := "CAST((splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_names', target_id)), splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_values', target_id))), 'Map(String, String)')"
targetLabelTranslatorStr := "CAST((splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_names', toUInt64(target_id))), splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_values', toUInt64(target_id)))), 'Map(String, String)')"
if appLabelTranslatorStr != "" {
tagTranslatorStr = "toJSONString(mapUpdate(map(" + appLabelTranslatorStr + ")," + targetLabelTranslatorStr + "))"
} else {
Expand Down
8 changes: 4 additions & 4 deletions server/querier/engine/clickhouse/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ func GetPrometheusSingleTagTranslator(tag string, e *CHEngine) (string, string,
if appLabel.AppLabelName == nameNoPreffix {
isAppLabel = true
labelType = "app"
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.app_label_map', 'label_value', (%d, app_label_value_id_%d))", labelNameID, appLabel.AppLabelColumnIndex)
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.app_label_map', 'label_value', (%d, toUInt64(app_label_value_id_%d)))", labelNameID, appLabel.AppLabelColumnIndex)
break
}
}
}
if !isAppLabel {
labelType = "target"
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.target_label_map', 'label_value', (%d, %d, target_id))", metricID, labelNameID)
TagTranslatorStr = fmt.Sprintf("dictGet('flow_tag.target_label_map', 'label_value', (%d, %d, toUInt64(target_id)))", metricID, labelNameID)
}
return TagTranslatorStr, labelType, nil
}
Expand All @@ -191,7 +191,7 @@ func GetPrometheusAllTagTranslator(e *CHEngine) (string, string, error) {
appLabelTranslatorSlice := []string{}
for _, appLabel := range appLabels {
if labelNameID, ok := trans_prometheus.ORGPrometheus[e.ORGID].LabelNameToID[appLabel.AppLabelName]; ok {
appLabelTranslator := fmt.Sprintf("'%s',dictGet('flow_tag.app_label_map', 'label_value', (%d, app_label_value_id_%d))", appLabel.AppLabelName, labelNameID, appLabel.AppLabelColumnIndex)
appLabelTranslator := fmt.Sprintf("'%s',dictGet('flow_tag.app_label_map', 'label_value', (%d, toUInt64(app_label_value_id_%d)))", appLabel.AppLabelName, labelNameID, appLabel.AppLabelColumnIndex)
appLabelTranslatorSlice = append(appLabelTranslatorSlice, appLabelTranslator)
labelFastTranslatorSlice = append(labelFastTranslatorSlice, fmt.Sprintf("app_label_value_id_%d", appLabel.AppLabelColumnIndex))
}
Expand All @@ -200,7 +200,7 @@ func GetPrometheusAllTagTranslator(e *CHEngine) (string, string, error) {
}

// targetLabel
targetLabelTranslatorStr := "CAST((splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_names', target_id)), splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_values', target_id))), 'Map(String, String)')"
targetLabelTranslatorStr := "CAST((splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_names', toUInt64(target_id))), splitByString(', ', dictGet('flow_tag.prometheus_target_label_layout_map', 'target_label_values', toUInt64(target_id)))), 'Map(String, String)')"
if appLabelTranslatorStr != "" {
tagTranslatorStr = "toJSONString(mapUpdate(map(" + appLabelTranslatorStr + ")," + targetLabelTranslatorStr + "))"
} else {
Expand Down

0 comments on commit e23b3f3

Please sign in to comment.