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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat: json filter bool support (#3544)
Nityananda Gohained809474d629
diff --git a/pkg/query-service/app/logs/v3/json_filter.go b/pkg/query-service/app/logs/v3/json_filter.goindex f15b101a8c..345da5a013 100644--- a/pkg/query-service/app/logs/v3/json_filter.go+++ b/pkg/query-service/app/logs/v3/json_filter.go@@ -12,24 +12,29 @@ const (STRING = "String"INT64 = "Int64"FLOAT64 = "Float64"+ BOOL = "Bool"ARRAY_STRING = "Array(String)"ARRAY_INT64 = "Array(Int64)"ARRAY_FLOAT64 = "Array(Float64)"+ ARRAY_BOOL = "Array(Bool)")var dataTypeMapping = map[string]string{"string": STRING,"int64": INT64,"float64": FLOAT64,+ "bool": BOOL,"array(string)": ARRAY_STRING,"array(int64)": ARRAY_INT64,"array(float64)": ARRAY_FLOAT64,+ "array(bool)": ARRAY_BOOL,}var arrayValueTypeMapping = map[string]string{"array(string)": "string","array(int64)": "int64","array(float64)": "float64",+ "array(bool)": "bool",}var jsonLogOperators = map[v3.FilterOperator]string{@@ -74,7 +79,7 @@ func getJSONFilterKey(key v3.AttributeKey, isArray bool) (string, error) {// for non arraykeyname := fmt.Sprintf("JSON_VALUE(%s, '$.%s')", keyArr[0], strings.Join(keyArr[1:], "."))- if dataType != "String" {+ if dataType != STRING {keyname = fmt.Sprintf("JSONExtract(%s, '%s')", keyname, dataType)}diff --git a/pkg/query-service/app/logs/v3/json_filter_test.go b/pkg/query-service/app/logs/v3/json_filter_test.goindex 6509bf5d16..455d705b1d 100644--- a/pkg/query-service/app/logs/v3/json_filter_test.go+++ b/pkg/query-service/app/logs/v3/json_filter_test.go@@ -74,6 +74,16 @@ var testGetJSONFilterKeyData = []struct {IsArray: true,ClickhouseKey: "JSONExtract(JSON_QUERY(body, '$.nested_num[*].float_nums[*]'), '" + ARRAY_FLOAT64 + "')",},+ {+ Name: "Array Bool",+ Key: v3.AttributeKey{+ Key: "body.boolarray[*]",+ DataType: "array(bool)",+ IsJSON: true,+ },+ IsArray: true,+ ClickhouseKey: "JSONExtract(JSON_QUERY(body, '$.boolarray[*]'), '" + ARRAY_BOOL + "')",+ },{Name: "String",Key: v3.AttributeKey{@@ -104,6 +114,16 @@ var testGetJSONFilterKeyData = []struct {IsArray: false,ClickhouseKey: "JSONExtract(JSON_VALUE(body, '$.fraction'), '" + FLOAT64 + "')",},+ {+ Name: "Bool",+ Key: v3.AttributeKey{+ Key: "body.boolkey",+ DataType: "bool",+ IsJSON: true,+ },+ IsArray: false,+ ClickhouseKey: "JSONExtract(JSON_VALUE(body, '$.boolkey'), '" + BOOL + "')",+ },}func TestGetJSONFilterKey(t *testing.T) {@@ -165,6 +185,19 @@ var testGetJSONFilterData = []struct {},Filter: "NOT has(JSONExtract(JSON_QUERY(body, '$.nested_num[*].float_nums[*]'), '" + ARRAY_FLOAT64 + "'), 2.200000)",},+ {+ Name: "Array membership bool",+ FilterItem: v3.FilterItem{+ Key: v3.AttributeKey{+ Key: "body.bool[*]",+ DataType: "array(bool)",+ IsJSON: true,+ },+ Operator: "has",+ Value: true,+ },+ Filter: "has(JSONExtract(JSON_QUERY(body, '$.bool[*]'), '" + ARRAY_BOOL + "'), true)",+ },{Name: "eq operator",FilterItem: v3.FilterItem{@@ -204,6 +237,19 @@ var testGetJSONFilterData = []struct {},Filter: "JSONExtract(JSON_VALUE(body, '$.status'), '" + FLOAT64 + "') = 1.100000",},+ {+ Name: "eq operator bool",+ FilterItem: v3.FilterItem{+ Key: v3.AttributeKey{+ Key: "body.boolkey",+ DataType: "bool",+ IsJSON: true,+ },+ Operator: "=",+ Value: true,+ },+ Filter: "JSONExtract(JSON_VALUE(body, '$.boolkey'), '" + BOOL + "') = true",+ },{Name: "greater than operator",FilterItem: v3.FilterItem{diff --git a/pkg/query-service/model/v3/v3.go b/pkg/query-service/model/v3/v3.goindex a8c03066b8..039ea1c672 100644--- a/pkg/query-service/model/v3/v3.go+++ b/pkg/query-service/model/v3/v3.go@@ -242,6 +242,7 @@ const (AttributeKeyDataTypeArrayString AttributeKeyDataType = "array(string)"AttributeKeyDataTypeArrayInt64 AttributeKeyDataType = "array(int64)"AttributeKeyDataTypeArrayFloat64 AttributeKeyDataType = "array(float64)"+ AttributeKeyDataTypeArrayBool AttributeKeyDataType = "array(bool)")func (q AttributeKeyDataType) Validate() error {@@ -297,7 +298,7 @@ func (a AttributeKey) CacheKey() string {func (a AttributeKey) Validate() error {switch a.DataType {- case AttributeKeyDataTypeBool, AttributeKeyDataTypeInt64, AttributeKeyDataTypeFloat64, AttributeKeyDataTypeString, AttributeKeyDataTypeArrayFloat64, AttributeKeyDataTypeArrayString, AttributeKeyDataTypeArrayInt64, AttributeKeyDataTypeUnspecified:+ case AttributeKeyDataTypeBool, AttributeKeyDataTypeInt64, AttributeKeyDataTypeFloat64, AttributeKeyDataTypeString, AttributeKeyDataTypeArrayFloat64, AttributeKeyDataTypeArrayString, AttributeKeyDataTypeArrayInt64, AttributeKeyDataTypeArrayBool, AttributeKeyDataTypeUnspecified:breakdefault:return fmt.Errorf("invalid attribute dataType: %s", a.DataType)