mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 17:35:53 +08:00
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:
parent
5891fbc229
commit
94e0423479
@ -366,3 +366,65 @@ func TestPipelineRouterWorksEvenIfFirstOpIsDisabled(t *testing.T) {
|
|||||||
}, result[0].Attributes_string,
|
}, 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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package logparsingpipeline
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -17,8 +18,13 @@ const (
|
|||||||
NOOP = "noop"
|
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 {
|
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) {
|
func PreparePipelineProcessor(pipelines []Pipeline) (map[string]interface{}, []string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user