Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: return warning logs too from collector simulator #3888

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/query-service/app/logparsingpipeline/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ type PipelinesPreviewRequest struct {
}

type PipelinesPreviewResponse struct {
OutputLogs []model.SignozLog `json:"logs"`
OutputLogs []model.SignozLog `json:"logs"`
CollectorLogs []string `json:"collectorLogs"`
}

func (ic *LogParsingPipelineController) PreviewLogsPipelines(
ctx context.Context,
request *PipelinesPreviewRequest,
) (*PipelinesPreviewResponse, *model.ApiError) {
result, _, err := SimulatePipelinesProcessing(
result, collectorLogs, err := SimulatePipelinesProcessing(
ctx, request.Pipelines, request.Logs,
)

Expand All @@ -149,7 +150,8 @@ func (ic *LogParsingPipelineController) PreviewLogsPipelines(
}

return &PipelinesPreviewResponse{
OutputLogs: result,
OutputLogs: result,
CollectorLogs: collectorLogs,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ func TestNoCollectorErrorsFromProcessorsForMismatchedLogs(t *testing.T) {
for _, testCase := range testCases {
testPipelines := []Pipeline{makeTestPipeline([]PipelineOperator{testCase.Operator})}

result, collectorErrorLogs, err := SimulatePipelinesProcessing(
result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
testPipelines,
[]model.SignozLog{testCase.NonMatchingLog},
)
require.Nil(err)
require.Equal(0, len(collectorErrorLogs), strings.Join(collectorErrorLogs, "\n"))
require.Equal(0, len(collectorWarnAndErrorLogs), strings.Join(collectorWarnAndErrorLogs, "\n"))
require.Equal(1, len(result))
}
}
2 changes: 1 addition & 1 deletion pkg/query-service/app/logparsingpipeline/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func SimulatePipelinesProcessing(
pipelines []Pipeline,
logs []model.SignozLog,
) (
output []model.SignozLog, collectorErrorLogs []string, apiErr *model.ApiError,
output []model.SignozLog, collectorWarnAndErrorLogs []string, apiErr *model.ApiError,
) {

if len(pipelines) < 1 {
Expand Down
16 changes: 8 additions & 8 deletions pkg/query-service/app/logparsingpipeline/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestPipelinePreview(t *testing.T) {
},
)

result, collectorErrorLogs, err := SimulatePipelinesProcessing(
result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
testPipelines,
[]model.SignozLog{
Expand All @@ -114,7 +114,7 @@ func TestPipelinePreview(t *testing.T) {
)

require.Nil(err)
require.Equal(0, len(collectorErrorLogs))
require.Equal(0, len(collectorWarnAndErrorLogs))
require.Equal(2, len(result))

// matching log should have been modified as expected.
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestGrokParsingPreview(t *testing.T) {
"method": "GET",
},
)
result, collectorErrorLogs, err := SimulatePipelinesProcessing(
result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
testPipelines,
[]model.SignozLog{
Expand All @@ -199,7 +199,7 @@ func TestGrokParsingPreview(t *testing.T) {
)

require.Nil(err)
require.Equal(0, len(collectorErrorLogs))
require.Equal(0, len(collectorWarnAndErrorLogs))
require.Equal(1, len(result))
processed := result[0]

Expand Down Expand Up @@ -280,7 +280,7 @@ func TestTraceParsingPreview(t *testing.T) {
TraceFlags: 0,
}

result, collectorErrorLogs, err := SimulatePipelinesProcessing(
result, collectorWarnAndErrorLogs, err := SimulatePipelinesProcessing(
context.Background(),
testPipelines,
[]model.SignozLog{
Expand All @@ -289,7 +289,7 @@ func TestTraceParsingPreview(t *testing.T) {
)
require.Nil(err)
require.Equal(1, len(result))
require.Equal(0, len(collectorErrorLogs))
require.Equal(0, len(collectorWarnAndErrorLogs))
processed := result[0]

require.Equal(testTraceId, processed.TraceID)
Expand All @@ -301,7 +301,7 @@ func TestTraceParsingPreview(t *testing.T) {

// trace parser should work even if parse_from value is empty
testPipelines[0].Config[0].SpanId.ParseFrom = ""
result, collectorErrorLogs, err = SimulatePipelinesProcessing(
result, collectorWarnAndErrorLogs, err = SimulatePipelinesProcessing(
context.Background(),
testPipelines,
[]model.SignozLog{
Expand All @@ -310,7 +310,7 @@ func TestTraceParsingPreview(t *testing.T) {
)
require.Nil(err)
require.Equal(1, len(result))
require.Equal(0, len(collectorErrorLogs))
require.Equal(0, len(collectorWarnAndErrorLogs))
require.Equal("", result[0].SpanID)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/query-service/collectorsimulator/collectorsimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ func (l *CollectorSimulator) Shutdown(ctx context.Context) (
simulationErrs = append(simulationErrs, reportedErr.Error())
}

collectorErrorLogs, err := os.ReadFile(l.collectorLogsOutputFilePath)
collectorWarnAndErrorLogs, err := os.ReadFile(l.collectorLogsOutputFilePath)
if err != nil {
return nil, model.InternalError(fmt.Errorf(
"could not read collector logs from tmp file: %w", err,
))
}
if len(collectorErrorLogs) > 0 {
errorLines := strings.Split(string(collectorErrorLogs), "\n")
if len(collectorWarnAndErrorLogs) > 0 {
errorLines := strings.Split(string(collectorWarnAndErrorLogs), "\n")
simulationErrs = append(simulationErrs, errorLines...)
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func generateSimulationConfig(
metrics:
level: none
logs:
level: error
level: warn
output_paths: ["%s"]
`, receiverId, exporterId, collectorLogsOutputPath)

Expand Down
Loading