mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 13:46:00 +08:00
fix: [alerts] [ch-query] added aliases in metric query result (#1760)
* fix: [alerts] [ch-query] added aliases in metric query result * fix: added more column type support for target in ch query * fix: added error handling when data type is unexpected in metric result Co-authored-by: Pranay Prateek <pranay@signoz.io>
This commit is contained in:
parent
0cbba071ea
commit
2771d2e774
@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.signoz.io/signoz/ee/query-service/model"
|
"go.signoz.io/signoz/ee/query-service/model"
|
||||||
|
baseconst "go.signoz.io/signoz/pkg/query-service/constants"
|
||||||
basemodel "go.signoz.io/signoz/pkg/query-service/model"
|
basemodel "go.signoz.io/signoz/pkg/query-service/model"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils"
|
"go.signoz.io/signoz/pkg/query-service/utils"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -91,6 +92,32 @@ func (r *ClickhouseReader) GetMetricResultEE(ctx context.Context, query string)
|
|||||||
metricPoint.Timestamp = v.UnixMilli()
|
metricPoint.Timestamp = v.UnixMilli()
|
||||||
case *float64:
|
case *float64:
|
||||||
metricPoint.Value = *v
|
metricPoint.Value = *v
|
||||||
|
case **float64:
|
||||||
|
// ch seems to return this type when column is derived from
|
||||||
|
// SELECT count(*)/ SELECT count(*)
|
||||||
|
floatVal := *v
|
||||||
|
if floatVal != nil {
|
||||||
|
metricPoint.Value = *floatVal
|
||||||
|
}
|
||||||
|
case *float32:
|
||||||
|
float32Val := float32(*v)
|
||||||
|
metricPoint.Value = float64(float32Val)
|
||||||
|
case *uint8, *uint64, *uint16, *uint32:
|
||||||
|
if _, ok := baseconst.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
metricPoint.Value = float64(reflect.ValueOf(v).Elem().Uint())
|
||||||
|
} else {
|
||||||
|
groupBy = append(groupBy, fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint()))
|
||||||
|
groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint())
|
||||||
|
}
|
||||||
|
case *int8, *int16, *int32, *int64:
|
||||||
|
if _, ok := baseconst.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
metricPoint.Value = float64(reflect.ValueOf(v).Elem().Int())
|
||||||
|
} else {
|
||||||
|
groupBy = append(groupBy, fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Int()))
|
||||||
|
groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Int())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
zap.S().Errorf("invalid var found in metric builder query result", v, colName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Strings(groupBy)
|
sort.Strings(groupBy)
|
||||||
|
@ -2916,6 +2916,32 @@ func (r *ClickHouseReader) GetMetricResult(ctx context.Context, query string) ([
|
|||||||
metricPoint.Timestamp = v.UnixMilli()
|
metricPoint.Timestamp = v.UnixMilli()
|
||||||
case *float64:
|
case *float64:
|
||||||
metricPoint.Value = *v
|
metricPoint.Value = *v
|
||||||
|
case **float64:
|
||||||
|
// ch seems to return this type when column is derived from
|
||||||
|
// SELECT count(*)/ SELECT count(*)
|
||||||
|
floatVal := *v
|
||||||
|
if floatVal != nil {
|
||||||
|
metricPoint.Value = *floatVal
|
||||||
|
}
|
||||||
|
case *float32:
|
||||||
|
float32Val := float32(*v)
|
||||||
|
metricPoint.Value = float64(float32Val)
|
||||||
|
case *uint8, *uint64, *uint16, *uint32:
|
||||||
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
metricPoint.Value = float64(reflect.ValueOf(v).Elem().Uint())
|
||||||
|
} else {
|
||||||
|
groupBy = append(groupBy, fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint()))
|
||||||
|
groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint())
|
||||||
|
}
|
||||||
|
case *int8, *int16, *int32, *int64:
|
||||||
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
metricPoint.Value = float64(reflect.ValueOf(v).Elem().Int())
|
||||||
|
} else {
|
||||||
|
groupBy = append(groupBy, fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Int()))
|
||||||
|
groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Int())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
zap.S().Errorf("invalid var found in metric builder query result", v, colName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Strings(groupBy)
|
sort.Strings(groupBy)
|
||||||
|
@ -190,3 +190,8 @@ const (
|
|||||||
"CAST((attributes_float64_key, attributes_float64_value), 'Map(String, Float64)') as attributes_float64," +
|
"CAST((attributes_float64_key, attributes_float64_value), 'Map(String, Float64)') as attributes_float64," +
|
||||||
"CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string "
|
"CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string "
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ReservedColumnTargetAliases identifies result value from a user
|
||||||
|
// written clickhouse query. The column alias indcate which value is
|
||||||
|
// to be considered as final result (or target)
|
||||||
|
var ReservedColumnTargetAliases = map[string]bool{"result": true, "res": true, "value": true}
|
||||||
|
@ -422,25 +422,40 @@ func (r *ThresholdRule) runChQuery(ctx context.Context, db clickhouse.Conn, quer
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *float64:
|
case *float64:
|
||||||
if colName == "res" || colName == "value" {
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
sample.Point.V = *v
|
sample.Point.V = *v
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
lbls.Set(colName, fmt.Sprintf("%f", *v))
|
lbls.Set(colName, fmt.Sprintf("%f", *v))
|
||||||
}
|
}
|
||||||
case *uint64:
|
case **float64:
|
||||||
intv := *v
|
// ch seems to return this type when column is derived from
|
||||||
if colName == "res" || colName == "value" {
|
// SELECT count(*)/ SELECT count(*)
|
||||||
sample.Point.V = float64(intv)
|
floatVal := *v
|
||||||
} else {
|
if floatVal != nil {
|
||||||
lbls.Set(colName, fmt.Sprintf("%d", intv))
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
sample.Point.V = *floatVal
|
||||||
|
} else {
|
||||||
|
lbls.Set(colName, fmt.Sprintf("%f", *floatVal))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case *uint8:
|
case *float32:
|
||||||
intv := *v
|
float32Val := float32(*v)
|
||||||
if colName == "res" || colName == "value" {
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
sample.Point.V = float64(intv)
|
sample.Point.V = float64(float32Val)
|
||||||
} else {
|
} else {
|
||||||
lbls.Set(colName, fmt.Sprintf("%d", intv))
|
lbls.Set(colName, fmt.Sprintf("%f", float32Val))
|
||||||
|
}
|
||||||
|
case *uint8, *uint64, *uint16, *uint32:
|
||||||
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
sample.Point.V = float64(reflect.ValueOf(v).Elem().Uint())
|
||||||
|
} else {
|
||||||
|
lbls.Set(colName, fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint()))
|
||||||
|
}
|
||||||
|
case *int8, *int16, *int32, *int64:
|
||||||
|
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok {
|
||||||
|
sample.Point.V = float64(reflect.ValueOf(v).Elem().Int())
|
||||||
|
} else {
|
||||||
|
lbls.Set(colName, fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Int()))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
zap.S().Errorf("ruleId:", r.ID(), "\t error: invalid var found in query result", v, columnNames[i])
|
zap.S().Errorf("ruleId:", r.ID(), "\t error: invalid var found in query result", v, columnNames[i])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user