introduce new way of getting process name in loki source windows event #2631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description
This PR further reduces the CPU usage of the loki.source.windows component by 70%.
The previous approach was iterating over all processes to find the one corresponding to the received event by comparing the PIDs to retrieve the process name.
The new approach uses the Windows API to query the process name directly using the PID. It also returns directly the names "System" and "Idle Process" which are guaranteed to always have the same PIDs on all Windows machines.
Which issue(s) this PR fixes
Fixes #2615
Notes to the Reviewer
The change was tested by running both the old function and the new function side by side and comparing the results with at least 1_000_000 prod events. No discrepancies were found between the two versions.
Profiles showed an improvement of more than 70% compared to the version on main.
Additional manual tests were done locally to test different types of events.
PR Checklist