fix: avoid pipeline builder panic when first op is disabled (#3500)

* fix: avoid pipeline builder panic if first op is disabled

* chore: use pipeline builder test to trigger getOperator panic

---------

Co-authored-by: Nityananda Gohain <nityanandagohain@gmail.com>
This commit is contained in:
Raj Kamal Singh 2023-09-07 17:47:09 +05:30 committed by GitHub
parent 921fca5e67
commit f450d71a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -58,7 +58,7 @@ func getOperators(ops []model.PipelineOperator) []model.PipelineOperator {
filteredOp := []model.PipelineOperator{}
for i, operator := range ops {
if operator.Enabled {
if i > 0 {
if len(filteredOp) > 0 {
filteredOp[len(filteredOp)-1].Output = operator.ID
}
filteredOp = append(filteredOp, operator)

View File

@ -163,6 +163,29 @@ var prepareProcessorTestData = []struct {
},
},
},
{
Name: "first op disabled",
Operators: []model.PipelineOperator{
{
ID: "move_filename",
Output: "move_function",
Enabled: false,
Name: "move_filename",
},
{
ID: "move_function",
Enabled: true,
Name: "move_function",
},
},
Output: []model.PipelineOperator{
{
ID: "move_function",
Enabled: true,
Name: "move_function",
},
},
},
}
func TestPreparePipelineProcessor(t *testing.T) {

View File

@ -231,8 +231,8 @@ func (tb *LogPipelinesTestBed) PostPipelinesToQSExpectingStatusCode(
if response.StatusCode != expectedStatusCode {
tb.t.Fatalf(
"Received response status %d after posting log pipelines. Expected: %d",
response.StatusCode, expectedStatusCode,
"Received response status %d after posting log pipelines. Expected: %d\nResponse body:%s\n",
response.StatusCode, expectedStatusCode, string(responseBody),
)
}