mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 20:05:58 +08:00
chore: remove workaround for supporting pipeline filters using attribs with . replaced with _ (#5405)
This commit is contained in:
parent
3ee51770fd
commit
161a69fbe9
@ -803,76 +803,3 @@ func TestContainsFilterIsCaseInsensitive(t *testing.T) {
|
|||||||
_, test2Exists := result[0].Attributes_string["test2"]
|
_, test2Exists := result[0].Attributes_string["test2"]
|
||||||
require.False(test2Exists)
|
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -53,49 +53,35 @@ func Parse(filters *v3.FilterSet) (string, error) {
|
|||||||
return "", fmt.Errorf("operator not supported")
|
return "", fmt.Errorf("operator not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(Raj): Remove the use of dot replaced alternative when key
|
name := getName(v.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{}
|
var filter string
|
||||||
for _, name := range names {
|
|
||||||
var filter string
|
|
||||||
|
|
||||||
switch v.Operator {
|
switch v.Operator {
|
||||||
// uncomment following lines when new version of expr is used
|
// uncomment following lines when new version of expr is used
|
||||||
// case v3.FilterOperatorIn, v3.FilterOperatorNotIn:
|
// case v3.FilterOperatorIn, v3.FilterOperatorNotIn:
|
||||||
// filter = fmt.Sprintf("%s %s list%s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))
|
// filter = fmt.Sprintf("%s %s list%s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))
|
||||||
|
|
||||||
case v3.FilterOperatorExists, v3.FilterOperatorNotExists:
|
case v3.FilterOperatorExists, v3.FilterOperatorNotExists:
|
||||||
filter = fmt.Sprintf("%s %s %s", exprFormattedValue(v.Key.Key), logOperatorsToExpr[v.Operator], getTypeName(v.Key.Type))
|
filter = fmt.Sprintf("%s %s %s", exprFormattedValue(v.Key.Key), logOperatorsToExpr[v.Operator], getTypeName(v.Key.Type))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
filter = fmt.Sprintf("%s %s %s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))
|
filter = fmt.Sprintf("%s %s %s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))
|
||||||
|
|
||||||
if v.Operator == v3.FilterOperatorContains || v.Operator == v3.FilterOperatorNotContains {
|
if v.Operator == v3.FilterOperatorContains || v.Operator == v3.FilterOperatorNotContains {
|
||||||
// `contains` and `ncontains` should be case insensitive to match how they work when querying logs.
|
// `contains` and `ncontains` should be case insensitive to match how they work when querying logs.
|
||||||
filter = fmt.Sprintf(
|
filter = fmt.Sprintf(
|
||||||
"lower(%s) %s lower(%s)",
|
"lower(%s) %s lower(%s)",
|
||||||
name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value),
|
name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// Avoid running operators on nil values
|
|
||||||
if v.Operator != v3.FilterOperatorEqual && v.Operator != v3.FilterOperatorNotEqual {
|
|
||||||
filter = fmt.Sprintf("%s != nil && %s", name, filter)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// check if the filter is a correct expression language
|
||||||
_, err := expr.Compile(filter)
|
_, err := expr.Compile(filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user