Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: typecase support added for float to int (#5408)

Nityananda Gohain1b0ec8ac4332
diff --git a/pkg/query-service/utils/format.go b/pkg/query-service/utils/format.go
index 481590e761..bd7db15e6b 100644
--- a/pkg/query-service/utils/format.go
+++ b/pkg/query-service/utils/format.go
@@ -91,6 +91,10 @@ func ValidateAndCastValue(v interface{}, dataType v3.AttributeKeyDataType) (inte
return x, nil
case int, int64:
return x, nil
+ case float32:
+ return int64(x), nil
+ case float64:
+ return int64(x), nil
case string:
int64val, err := strconv.ParseInt(x, 10, 64)
if err != nil {
diff --git a/pkg/query-service/utils/format_test.go b/pkg/query-service/utils/format_test.go
index 2c7aab1e6d..3a2a7f1265 100644
--- a/pkg/query-service/utils/format_test.go
+++ b/pkg/query-service/utils/format_test.go
@@ -275,6 +275,24 @@ var testValidateAndCastValueData = []struct {
want: nil,
wantErr: true,
},
+ {
+ name: "v3.AttributeKeyDataTypeInt64: valid float32",
+ args: args{
+ v: float32(1000),
+ dataType: v3.AttributeKeyDataTypeInt64,
+ },
+ want: int64(1000),
+ wantErr: false,
+ },
+ {
+ name: "v3.AttributeKeyDataTypeInt64: valid float64",
+ args: args{
+ v: float64(1000),
+ dataType: v3.AttributeKeyDataTypeInt64,
+ },
+ want: int64(1000),
+ wantErr: false,
+ },
}
// Test cases for ValidateAndCastValue function in pkg/query-service/utils/format.go