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

x-pack/filebeat/input/{cel,httpjson,http_endpoint}: prevent complete loss of long request trace data #37836

Merged
merged 1 commit into from
Feb 3, 2024

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Feb 2, 2024

Proposed commit message

The lumberjack logger drops lines that are longer than the max size, so truncate bodies that are near the limit to ensure that at least some logging data is retained. Also truncate requests that are too long, including in http_endpoint.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@efd6 efd6 added enhancement Filebeat Filebeat backport-skip Skip notification from the automated backport with mergify Team:Security-Service Integrations Security Service Integrations Team 8.13-candidate labels Feb 2, 2024
@efd6 efd6 self-assigned this Feb 2, 2024
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Feb 2, 2024
Comment on lines +180 to +182
// Limit request logging body size to 10kiB.
const maxBodyLen = 10 * (1 << 10)
httplog.LogRequest(h.reqLogger, r, maxBodyLen, extra...)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The question is whether this should be configurable or whether this is enough.

Copy link
Member

Choose a reason for hiding this comment

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

Let's go with what you have. If it's too limiting we can add a new control on the wall later.

y4emM6_ci14ycF1WqK7zw4PJ30uib7gQCnNGaxtXnjY-2232382363

@efd6 efd6 marked this pull request as ready for review February 2, 2024 06:50
@efd6 efd6 requested a review from a team as a code owner February 2, 2024 06:50
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2024-02-02T04:37:52.828+0000

  • Duration: 134 min 8 sec

Test stats 🧪

Test Results
Failed 0
Passed 3251
Skipped 176
Total 3427

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. I left a few comments, but I don't feel the need to re-review unless you want me to.

@@ -174,7 +180,8 @@ func logRequest(log *zap.Logger, req *http.Request, extra ...zapcore.Field) (_ *
errorsMessages = append(errorsMessages, fmt.Sprintf("failed to read request body: %s", err))
} else {
reqParts = append(reqParts,
zap.ByteString("http.request.body.content", body),
zap.ByteString("http.request.body.content", body[:max(0, min(len(body), maxBodyLen))]),
Copy link
Member

Choose a reason for hiding this comment

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

Does this need the max() call? I think the purpose is to protect against negative maxBodyLen values, but didn't trace if those are possible.

If yes, then it seems like the same protection is needed at L114.

Copy link
Contributor Author

@efd6 efd6 Feb 2, 2024

Choose a reason for hiding this comment

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

This is a residue. Will remove. The max calls are done at the call site now.

@@ -71,6 +71,7 @@ func (t *valueTpl) Unpack(in string) error {
"mul": mul,
"now": now,
"parseDate": parseDate,
"parseDateInTZ": parseDateInTZ,
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it should be done in a separate PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😆 Yeah, noodling while making this change and accidentally committed this.

Comment on lines +180 to +182
// Limit request logging body size to 10kiB.
const maxBodyLen = 10 * (1 << 10)
httplog.LogRequest(h.reqLogger, r, maxBodyLen, extra...)
Copy link
Member

Choose a reason for hiding this comment

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

Let's go with what you have. If it's too limiting we can add a new control on the wall later.

y4emM6_ci14ycF1WqK7zw4PJ30uib7gQCnNGaxtXnjY-2232382363

…loss of long request trace data

The lumberjack logger drops lines that are longer than the max size, so
truncate bodies that are near the limit to ensure that at least some
logging data is retained. Also truncate requests that are too long,
including in http_endpoint.
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

cc @efd6

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2024-02-02T20:40:31.611+0000

  • Duration: 138 min 49 sec

Test stats 🧪

Test Results
Failed 0
Passed 3251
Skipped 176
Total 3427

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@efd6 efd6 merged commit 6d4f1e6 into elastic:main Feb 3, 2024
27 of 31 checks passed
Scholar-Li pushed a commit to Scholar-Li/beats that referenced this pull request Feb 5, 2024
…loss of long request trace data (elastic#37836)

The lumberjack logger drops lines that are longer than the max size, so
truncate bodies that are near the limit to ensure that at least some
logging data is retained. Also truncate requests that are too long,
including in http_endpoint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.13-candidate backport-skip Skip notification from the automated backport with mergify enhancement Filebeat Filebeat Team:Security-Service Integrations Security Service Integrations Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Filebeat] http trace logger - truncate response bodies larger than request.tracer.maxsize
3 participants