Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support in operator for json search #6689

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/query-service/app/logs/v3/enrich_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ 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"
}
} else {
valueType = "string"
}
case uint8, uint16, uint32, uint64, int, int8, int16, int32, int64:
valueType = "int64"
case float32, float64:
Expand Down
44 changes: 44 additions & 0 deletions pkg/query-service/app/logs/v3/enrich_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/query-service/app/logs/v4/json_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ var testGetJSONFilterData = []struct {
},
Filter: "lower(body) like lower('%message%') AND JSON_EXISTS(body, '$.\"message\"')",
},
{
Name: "exists",
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']",
},
}
nityanandagohain marked this conversation as resolved.
Show resolved Hide resolved

func TestGetJSONFilter(t *testing.T) {
Expand Down
Loading