mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 22:39:01 +08:00
Fix: resource filters should work in logs pipelines (#3889)
* chore: add test validating resource based filters work in logs pipelines * fix: get resource filters working in logs pipelines
This commit is contained in:
parent
050b866173
commit
3e65543b5f
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
@ -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 ""
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user