Skip to content

Commit

Permalink
chore: remove workaround for supporting pipeline filters using attrib…
Browse files Browse the repository at this point in the history
…s with . replaced with _ (SigNoz#5405)
  • Loading branch information
raj-k-singh authored Jul 2, 2024
1 parent 3ee5177 commit 161a69f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 108 deletions.
73 changes: 0 additions & 73 deletions pkg/query-service/app/logparsingpipeline/pipelineBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,76 +803,3 @@ func TestContainsFilterIsCaseInsensitive(t *testing.T) {
_, test2Exists := result[0].Attributes_string["test2"]
require.False(test2Exists)
}

func TestTemporaryWorkaroundForSupportingAttribsContainingDots(t *testing.T) {
// TODO(Raj): Remove this after dots are supported

require := require.New(t)

testPipeline := Pipeline{
OrderId: 1,
Name: "pipeline1",
Alias: "pipeline1",
Enabled: true,
Filter: &v3.FilterSet{
Operator: "AND",
Items: []v3.FilterItem{
{
Key: v3.AttributeKey{
Key: "k8s_deployment_name",
DataType: v3.AttributeKeyDataTypeString,
Type: v3.AttributeKeyTypeResource,
},
Operator: "=",
Value: "ingress",
},
},
},
Config: []PipelineOperator{
{
ID: "add",
Type: "add",
Enabled: true,
Name: "add",
Field: "attributes.test",
Value: "test-value",
},
},
}

testLogs := []model.SignozLog{{
Timestamp: uint64(time.Now().UnixNano()),
Body: "test log",
Attributes_string: map[string]string{},
Resources_string: map[string]string{
"k8s_deployment_name": "ingress",
},
SeverityText: entry.Info.String(),
SeverityNumber: uint8(entry.Info),
SpanID: "",
TraceID: "",
}, {
Timestamp: uint64(time.Now().UnixNano()),
Body: "test log",
Attributes_string: map[string]string{},
Resources_string: map[string]string{
"k8s.deployment.name": "ingress",
},
SeverityText: entry.Info.String(),
SeverityNumber: uint8(entry.Info),
SpanID: "",
TraceID: "",
}}

result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
[]Pipeline{testPipeline},
testLogs,
)
require.Nil(err)
require.Equal(0, len(collectorWarnAndErrorLogs), strings.Join(collectorWarnAndErrorLogs, "\n"))
require.Equal(2, len(result))
for _, processedLog := range result {
require.Equal(processedLog.Attributes_string["test"], "test-value")
}
}
56 changes: 21 additions & 35 deletions pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,35 @@ func Parse(filters *v3.FilterSet) (string, error) {
return "", fmt.Errorf("operator not supported")
}

// TODO(Raj): Remove the use of dot replaced alternative when key
// contains underscore after dots are supported in keys
names := []string{getName(v.Key)}
if strings.Contains(v.Key.Key, "_") {
dotKey := v.Key
dotKey.Key = strings.Replace(v.Key.Key, "_", ".", -1)
names = append(names, getName(dotKey))
}

filterParts := []string{}
for _, name := range names {
var filter string
name := getName(v.Key)

switch v.Operator {
// uncomment following lines when new version of expr is used
// case v3.FilterOperatorIn, v3.FilterOperatorNotIn:
// filter = fmt.Sprintf("%s %s list%s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))
var filter string

case v3.FilterOperatorExists, v3.FilterOperatorNotExists:
filter = fmt.Sprintf("%s %s %s", exprFormattedValue(v.Key.Key), logOperatorsToExpr[v.Operator], getTypeName(v.Key.Type))
switch v.Operator {
// uncomment following lines when new version of expr is used
// case v3.FilterOperatorIn, v3.FilterOperatorNotIn:
// filter = fmt.Sprintf("%s %s list%s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))

default:
filter = fmt.Sprintf("%s %s %s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))

if v.Operator == v3.FilterOperatorContains || v.Operator == v3.FilterOperatorNotContains {
// `contains` and `ncontains` should be case insensitive to match how they work when querying logs.
filter = fmt.Sprintf(
"lower(%s) %s lower(%s)",
name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value),
)
}
case v3.FilterOperatorExists, v3.FilterOperatorNotExists:
filter = fmt.Sprintf("%s %s %s", exprFormattedValue(v.Key.Key), logOperatorsToExpr[v.Operator], getTypeName(v.Key.Type))

// Avoid running operators on nil values
if v.Operator != v3.FilterOperatorEqual && v.Operator != v3.FilterOperatorNotEqual {
filter = fmt.Sprintf("%s != nil && %s", name, filter)
}
default:
filter = fmt.Sprintf("%s %s %s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))

if v.Operator == v3.FilterOperatorContains || v.Operator == v3.FilterOperatorNotContains {
// `contains` and `ncontains` should be case insensitive to match how they work when querying logs.
filter = fmt.Sprintf(
"lower(%s) %s lower(%s)",
name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value),
)
}

filterParts = append(filterParts, filter)
// Avoid running operators on nil values
if v.Operator != v3.FilterOperatorEqual && v.Operator != v3.FilterOperatorNotEqual {
filter = fmt.Sprintf("%s != nil && %s", name, filter)
}
}

filter := strings.Join(filterParts, " || ")

// check if the filter is a correct expression language
_, err := expr.Compile(filter)
if err != nil {
Expand Down

0 comments on commit 161a69f

Please sign in to comment.