mirror of
https://github.com/SigNoz/signoz.git
synced 2026-02-13 12:52:55 +00:00
Compare commits
2 Commits
config
...
chore/sent
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f82d25cbca | ||
|
|
16e61b45ac |
@@ -692,7 +692,7 @@ function QueryBuilderSearchV2(
|
||||
operatorOptions = QUERY_BUILDER_OPERATORS_BY_TYPES[
|
||||
currentFilterItem.key
|
||||
.dataType as keyof typeof QUERY_BUILDER_OPERATORS_BY_TYPES
|
||||
].map((operator) => ({
|
||||
]?.map((operator) => ({
|
||||
label: operator,
|
||||
value: operator,
|
||||
}));
|
||||
|
||||
@@ -167,6 +167,22 @@ func jsonFilterEnrich(filter v3.FilterItem) v3.FilterItem {
|
||||
// check if the value is a int, float, string, bool
|
||||
valueType := ""
|
||||
switch filter.Value.(type) {
|
||||
// even the filter value is an array the actual type of the value is string.
|
||||
case []interface{}:
|
||||
// check first value type in array and use that
|
||||
if len(filter.Value.([]interface{})) > 0 {
|
||||
firstVal := filter.Value.([]interface{})[0]
|
||||
switch firstVal.(type) {
|
||||
case uint8, uint16, uint32, uint64, int, int8, int16, int32, int64:
|
||||
valueType = "int64"
|
||||
case float32, float64:
|
||||
valueType = "float64"
|
||||
case bool:
|
||||
valueType = "bool"
|
||||
default:
|
||||
valueType = "string"
|
||||
}
|
||||
}
|
||||
case uint8, uint16, uint32, uint64, int, int8, int16, int32, int64:
|
||||
valueType = "int64"
|
||||
case float32, float64:
|
||||
|
||||
@@ -563,6 +563,50 @@ var testJSONFilterEnrichData = []struct {
|
||||
Value: 10.0,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "check IN",
|
||||
Filter: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.attr",
|
||||
DataType: v3.AttributeKeyDataTypeUnspecified,
|
||||
Type: v3.AttributeKeyTypeUnspecified,
|
||||
},
|
||||
Operator: "IN",
|
||||
Value: []interface{}{"hello", "world"},
|
||||
},
|
||||
Result: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.attr",
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeUnspecified,
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "IN",
|
||||
Value: []interface{}{"hello", "world"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "check NOT_IN",
|
||||
Filter: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.attr",
|
||||
DataType: v3.AttributeKeyDataTypeUnspecified,
|
||||
Type: v3.AttributeKeyTypeUnspecified,
|
||||
},
|
||||
Operator: "NOT_IN",
|
||||
Value: []interface{}{10, 20},
|
||||
},
|
||||
Result: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.attr",
|
||||
DataType: v3.AttributeKeyDataTypeInt64,
|
||||
Type: v3.AttributeKeyTypeUnspecified,
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "NOT_IN",
|
||||
Value: []interface{}{10, 20},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestJsonEnrich(t *testing.T) {
|
||||
|
||||
@@ -183,6 +183,71 @@ var testGetJSONFilterData = []struct {
|
||||
},
|
||||
Filter: "lower(body) like lower('%message%') AND JSON_EXISTS(body, '$.\"message\"')",
|
||||
},
|
||||
{
|
||||
Name: "test json in array string",
|
||||
FilterItem: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.name",
|
||||
DataType: "string",
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "in",
|
||||
Value: []interface{}{"hello", "world"},
|
||||
},
|
||||
Filter: "lower(body) like lower('%name%') AND JSON_EXISTS(body, '$.\"name\"') AND JSON_VALUE(body, '$.\"name\"') IN ['hello','world']",
|
||||
},
|
||||
{
|
||||
Name: "test json in array number",
|
||||
FilterItem: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.value",
|
||||
DataType: "int64",
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "in",
|
||||
Value: []interface{}{10, 11},
|
||||
},
|
||||
Filter: "lower(body) like lower('%value%') AND JSON_EXISTS(body, '$.\"value\"') AND JSONExtract(JSON_VALUE(body, '$.\"value\"'), 'Int64') IN [10,11]",
|
||||
},
|
||||
{
|
||||
Name: "test json in array mixed data- allow",
|
||||
FilterItem: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.value",
|
||||
DataType: "int64",
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "in",
|
||||
Value: []interface{}{11, "11"},
|
||||
},
|
||||
Filter: "lower(body) like lower('%value%') AND JSON_EXISTS(body, '$.\"value\"') AND JSONExtract(JSON_VALUE(body, '$.\"value\"'), 'Int64') IN [11,11]",
|
||||
},
|
||||
{
|
||||
Name: "test json in array mixed data- fail",
|
||||
FilterItem: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.value",
|
||||
DataType: "int64",
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "in",
|
||||
Value: []interface{}{11, "11", "hello"},
|
||||
},
|
||||
Error: true,
|
||||
},
|
||||
{
|
||||
Name: "test json in array mixed data- allow",
|
||||
FilterItem: v3.FilterItem{
|
||||
Key: v3.AttributeKey{
|
||||
Key: "body.value",
|
||||
DataType: "string",
|
||||
IsJSON: true,
|
||||
},
|
||||
Operator: "in",
|
||||
Value: []interface{}{"hello", 11},
|
||||
},
|
||||
Filter: "lower(body) like lower('%value%') AND JSON_EXISTS(body, '$.\"value\"') AND JSON_VALUE(body, '$.\"value\"') IN ['hello','11']",
|
||||
},
|
||||
}
|
||||
|
||||
func TestGetJSONFilter(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user