Fix: logs pipelines: ensure special characters in pipeline identifiers don't result in bad collector config names (#6259)

* chore: add test validating pipe char in pipeline alias doesnt break collector config

* fix: pipelines collector conf: ensure bad names are not generated
This commit is contained in:
Raj Kamal Singh 2024-10-28 11:46:12 +05:30 committed by GitHub
parent 5891fbc229
commit 94e0423479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 69 additions and 1 deletions

View File

@ -366,3 +366,65 @@ func TestPipelineRouterWorksEvenIfFirstOpIsDisabled(t *testing.T) {
}, result[0].Attributes_string,
)
}
func TestPipeCharInAliasDoesntBreakCollectorConfig(t *testing.T) {
require := require.New(t)
testPipelines := []Pipeline{
{
OrderId: 1,
Name: "test | pipeline",
Alias: "test|pipeline",
Enabled: true,
Filter: &v3.FilterSet{
Operator: "AND",
Items: []v3.FilterItem{
{
Key: v3.AttributeKey{
Key: "method",
DataType: v3.AttributeKeyDataTypeString,
Type: v3.AttributeKeyTypeTag,
},
Operator: "=",
Value: "GET",
},
},
},
Config: []PipelineOperator{
{
OrderId: 1,
ID: "add",
Type: "add",
Field: "attributes.test",
Value: "val",
Enabled: true,
Name: "test add",
},
},
},
}
result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
testPipelines,
[]model.SignozLog{
makeTestSignozLog(
"test log body",
map[string]any{
"method": "GET",
},
),
},
)
require.Nil(err)
require.Equal(0, len(collectorWarnAndErrorLogs))
require.Equal(1, len(result))
require.Equal(
map[string]string{
"method": "GET",
"test": "val",
}, result[0].Attributes_string,
)
}

View File

@ -2,6 +2,7 @@ package logparsingpipeline
import (
"fmt"
"regexp"
"slices"
"strings"
@ -17,8 +18,13 @@ const (
NOOP = "noop"
)
// To ensure names used in generated collector config are never judged invalid,
// only alphabets, digits and `-` are used when translating pipeline identifiers
var badCharsForCollectorConfName = regexp.MustCompile("[^a-zA-Z0-9-]")
func CollectorConfProcessorName(p Pipeline) string {
return constants.LogsPPLPfx + p.Alias
normalizedAlias := badCharsForCollectorConfName.ReplaceAllString(p.Alias, "-")
return constants.LogsPPLPfx + normalizedAlias
}
func PreparePipelineProcessor(pipelines []Pipeline) (map[string]interface{}, []string, error) {