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

fix(sumologicexporter): don't send null logs #236

Merged
merged 2 commits into from
Sep 20, 2021

Conversation

pmalek-sumo
Copy link
Contributor

To prevent sending null logs check if the body is not empty before attaching it like in the attached screenshot:

image

@pmalek-sumo pmalek-sumo self-assigned this Sep 17, 2021
@pmalek-sumo pmalek-sumo requested a review from a team as a code owner September 17, 2021 11:16
@github-actions github-actions bot added the go label Sep 17, 2021
@pmalek-sumo pmalek-sumo force-pushed the sumologicexporter-dont-send-null-log branch from a258b33 to 7303bbf Compare September 17, 2021 11:20
Copy link
Contributor

@kasia-kujawa kasia-kujawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the test case with sending null logs be added to unit tests? If yes, I recommend to add this.

@pmalek-sumo
Copy link
Contributor Author

Can the test case with sending null logs be added to unit tests? If yes, I recommend to add this.

I wanted to do this but it seems that it's non trivial to make the exporter send the empty logs due to logic in appendAndSend, i.e. the provided body there is empty (which is ok) and we cannot really configure MaxRequestBodySize to force the flush (in order to check the asserts in tests).

I'm open to ideas to actually add a test for that.

ref:

func (s *sender) appendAndSend(
ctx context.Context,
line string,
pipeline PipelineType,
body *strings.Builder,
flds fields,
) (appendResponse, error) {
var errors []error
ar := newAppendResponse()
if body.Len() > 0 && body.Len()+len(line) >= s.config.MaxRequestBodySize {
ar.sent = true
if err := s.send(ctx, pipeline, strings.NewReader(body.String()), flds); err != nil {
errors = append(errors, err)
}
body.Reset()
}
if body.Len() > 0 {
// Do not add newline if the body is empty
if _, err := body.WriteString("\n"); err != nil {
errors = append(errors, err)
ar.appended = false
}
}
if ar.appended {
// Do not append new line if separator was not appended
if _, err := body.WriteString(line); err != nil {
errors = append(errors, err)
ar.appended = false
}
}
if len(errors) > 0 {
return ar, consumererror.Combine(errors)
}
return ar, nil
}

@pmalek-sumo pmalek-sumo force-pushed the sumologicexporter-dont-send-null-log branch from 76e03f6 to 9690129 Compare September 17, 2021 18:13
@pmalek-sumo pmalek-sumo force-pushed the sumologicexporter-dont-send-null-log branch from 9690129 to 0dd4536 Compare September 17, 2021 18:27
@pmalek-sumo pmalek-sumo enabled auto-merge (squash) September 20, 2021 08:30
@pmalek-sumo pmalek-sumo merged commit 13856ee into main Sep 20, 2021
@pmalek-sumo pmalek-sumo deleted the sumologicexporter-dont-send-null-log branch September 20, 2021 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants