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

[winlogbeat] performance improvment; avoid rendering event message twice #39544

Merged
merged 7 commits into from
May 15, 2024

Conversation

intxgo
Copy link
Contributor

@intxgo intxgo commented May 14, 2024

Proposed commit message

The change increases events-per-second throughput by about 30%.

I have improved the throughput by using a fixed buffer size at first attempt of message parsing.

I thought about adding a config parameter to control the size of the initial buffer but after some research I believe it's not needed. I use the size 16KB already existing in our code base. It's relatively small, but the majority of windows event log messages are even much smaller. Historically the event log was designed to store only a message templates to be filled in with actual strings or values from external resources when viewing.

This PR does not pose a regression risk, related to #35437 The former code was prone to error, on certain Windows releases, by using the out parameter BufferUsed instead of relying only on C-style string format when handling the output. The documentation of this parameter is a bit vague, in practice it's only needed when ERROR_INSUFFICIENT_BUFFER is returned.

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.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Setup a reasonably large VM, for example 8 CPU, 32 GB RAM. Prepare an event log with thousands of entries (or just create empty event log and prepare a tool to quickly produce events).
Prepare winlogbeat.yaml config pointing to the event log, use file output. Configure http statistics endpoint to periodically check the progress. Run winlogbeat.exe with the same config, on the same machine, before and after the change or run them side-by-side. Observe the increased events-per-second throughput.

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 14, 2024
@mergify mergify bot assigned intxgo May 14, 2024
Copy link
Contributor

mergify bot commented May 14, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @intxgo? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@intxgo intxgo force-pushed the winlogbeat-perf-improvement branch from 8ef40e1 to 58762e8 Compare May 14, 2024 08:29
@intxgo intxgo added Team:Security-Windows Platform Windows Platform Team in Security Solution and removed needs_team Indicates that the issue/PR needs a Team:* label labels May 14, 2024
@intxgo intxgo added backport-v8.13.0 Automated backport with mergify backport-v8.14.0 Automated backport with mergify backport-v8.8.0 Automated backport with mergify backport-v8.9.0 Automated backport with mergify backport-v8.10.0 Automated backport with mergify backport-v8.11.0 Automated backport with mergify backport-v8.12.0 Automated backport with mergify labels May 14, 2024
@intxgo intxgo marked this pull request as ready for review May 14, 2024 13:20
@intxgo intxgo requested a review from a team as a code owner May 14, 2024 13:20
@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform)

@intxgo intxgo changed the title [wineventlog] performance improvment; avoid rendering message twice [wineventlog] performance improvment; avoid rendering event message twice May 14, 2024
@intxgo intxgo changed the title [wineventlog] performance improvment; avoid rendering event message twice [winlogbeat] performance improvment; avoid rendering event message twice May 14, 2024
@intxgo intxgo removed backport-v8.8.0 Automated backport with mergify backport-v8.9.0 Automated backport with mergify backport-v8.10.0 Automated backport with mergify backport-v8.11.0 Automated backport with mergify backport-v8.12.0 Automated backport with mergify backport-v8.13.0 Automated backport with mergify labels May 14, 2024
@intxgo intxgo added the backport-v8.13.0 Automated backport with mergify label May 14, 2024
@gabriellandau
Copy link

The concept SGTM. I've used this pattern elsewhere with Win32/Native APIs - nice perf boost. I'm not qualified to review the golang, however.

@marc-gr
Copy link
Contributor

marc-gr commented May 14, 2024

LGTM, I wonder if it is feasible to craft an .evtx with such an event to be included in tests

@intxgo
Copy link
Contributor Author

intxgo commented May 15, 2024

LGTM, I wonder if it is feasible to craft an .evtx with such an event to be included in tests

We already have unit tests with evtx files, but they don't test these methods because these require publisher metadata.

@intxgo intxgo enabled auto-merge (squash) May 15, 2024 10:29
@intxgo intxgo merged commit d2ebffe into elastic:main May 15, 2024
18 checks passed
mergify bot pushed a commit that referenced this pull request May 15, 2024
…ice (#39544)

* wineventlog performance improvment; avoid rendering message twice

* ignore missing or mismatched parameter values

* add comment

* changelog

* actually increase the buffer

(cherry picked from commit d2ebffe)
mergify bot pushed a commit that referenced this pull request May 15, 2024
…ice (#39544)

* wineventlog performance improvment; avoid rendering message twice

* ignore missing or mismatched parameter values

* add comment

* changelog

* actually increase the buffer

(cherry picked from commit d2ebffe)
v1v added a commit to v1v/beats that referenced this pull request May 15, 2024
…-actions

* upstream/main: (313 commits)
  github-action: delete opentelemetry workflow (elastic#39559)
  updatecli: move to the .github folder and support for signed commits (elastic#39472)
  Osquerybeat: Add action responses data stream (elastic#39143)
  [winlogbeat] performance improvment; avoid rendering event message twice (elastic#39544)
  Fix the AWS SDK dependencies issue causing the "not found, ResolveEndpointV2" error (elastic#39454)
  x-pack/filebeat/input/cel: add http metrics collection (elastic#39503)
  build(deps): bump github.com/elastic/elastic-agent-libs from 0.9.4 to 0.9.7 (elastic#39424)
  Remove unused env vars from pipelines (elastic#39534)
  [BK] - Remove osx steps from branch execution (elastic#39552)
  [BK] - Remove certain steps from running for Branches (elastic#39533)
  Allow dependabot report BK status checks (elastic#39540)
  Remove hardcoded module definitions in CI (elastic#39506)
  Explicitly set DOCKER_PULL, RACE_DETECTOR and TEST_COVERAGE for pipelines (elastic#39510)
  Fixed pipelines formatting (elastic#39513)
  Update filebeat pipeline to match Jenkins steps (elastic#39261)
  Add error check to groupToEvents so we don't blindly add error values (elastic#39404)
  Remove fields not needed for session view in add_session_view processor (elastic#39500)
  `aws-s3` input: Split S3 poller and SQS reader into explicit input objects (elastic#39353)
  ci(jenkins): remove post-build notifications (elastic#39483)
  [DOCS] Add the `read_pipeline` cluster privilege for winlogbeat and the `auto_configure` index privilege to beats documentation (elastic#38534)
  ...
intxgo added a commit that referenced this pull request May 16, 2024
…ice (#39544) (#39573)

* wineventlog performance improvment; avoid rendering message twice

* ignore missing or mismatched parameter values

* add comment

* changelog

* actually increase the buffer

(cherry picked from commit d2ebffe)

Co-authored-by: Leszek Kubik <39905449+intxgo@users.noreply.github.com>
intxgo added a commit that referenced this pull request May 16, 2024
…ice (#39544) (#39572)

* wineventlog performance improvment; avoid rendering message twice

* ignore missing or mismatched parameter values

* add comment

* changelog

* actually increase the buffer

(cherry picked from commit d2ebffe)

Co-authored-by: Leszek Kubik <39905449+intxgo@users.noreply.github.com>
@intxgo intxgo deleted the winlogbeat-perf-improvement branch June 14, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.13.0 Automated backport with mergify backport-v8.14.0 Automated backport with mergify enhancement Team:Security-Windows Platform Windows Platform Team in Security Solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[winlogbeat] Throughput degradation
5 participants