Skip to content

Commit

Permalink
Fix: resource filters should work in logs pipelines (SigNoz#3889)
Browse files Browse the repository at this point in the history
* chore: add test validating resource based filters work in logs pipelines

* fix: get resource filters working in logs pipelines
  • Loading branch information
raj-k-singh committed Nov 3, 2023
1 parent 050b866 commit 3e65543
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
59 changes: 59 additions & 0 deletions pkg/query-service/app/logparsingpipeline/pipelineBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,62 @@ func TestNoCollectorErrorsFromProcessorsForMismatchedLogs(t *testing.T) {
require.Equal(1, len(result))
}
}

func TestResourceFiltersWork(t *testing.T) {
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: "service",
DataType: v3.AttributeKeyDataTypeString,
Type: v3.AttributeKeyTypeResource,
},
Operator: "=",
Value: "nginx",
},
},
},
Config: []PipelineOperator{
{
ID: "add",
Type: "add",
Enabled: true,
Name: "add",
Field: "attributes.test",
Value: "test-value",
},
},
}

testLog := model.SignozLog{
Timestamp: uint64(time.Now().UnixNano()),
Body: "test log",
Attributes_string: map[string]string{},
Resources_string: map[string]string{
"service": "nginx",
},
SeverityText: entry.Info.String(),
SeverityNumber: uint8(entry.Info),
SpanID: "",
TraceID: "",
}

result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
[]Pipeline{testPipeline},
[]model.SignozLog{testLog},
)
require.Nil(err)
require.Equal(0, len(collectorWarnAndErrorLogs), strings.Join(collectorWarnAndErrorLogs, "\n"))
require.Equal(1, len(result))

require.Equal(result[0].Attributes_string["test"], "test-value")
}
6 changes: 3 additions & 3 deletions pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ var logOperatorsToExpr = map[v3.FilterOperator]string{

func getName(v v3.AttributeKey) string {
if v.Type == v3.AttributeKeyTypeTag {
return "attributes." + v.Key
return "attributes?." + v.Key
} else if v.Type == v3.AttributeKeyTypeResource {
return "resources." + v.Key
return "resource?." + v.Key
}
return v.Key
}
Expand All @@ -41,7 +41,7 @@ func getTypeName(v v3.AttributeKeyType) string {
if v == v3.AttributeKeyTypeTag {
return "attributes"
} else if v == v3.AttributeKeyTypeResource {
return "resources"
return "resource"
}
return ""
}
Expand Down

0 comments on commit 3e65543

Please sign in to comment.