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

refactor(userspace/falco): re-design stats writer and make it thread-safe #2109

Merged
merged 9 commits into from Aug 26, 2022

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind cleanup

/kind design

Any specific area of the project related to this PR?

/area engine

What this PR does / why we need it:

As for the requirements of #2074, this PR refactors the stats writer of Falco to make it thread-safe. The class has been re-designed as a whole with a multi-producer single-consumer model with a worker and a queue (similar to what we have in the output framework). Moreover, this approach should also perform a little better because during the event processing loop we now push on the queue instead of writing on the file buffer (it just happens once in a while when the periodic timeout ticks, so it's not a big deal). This design also make it easier to add new stats field if needed in the future.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

refactor(userspace/falco): re-design stats writer and make it thread-safe

@jasondellaluce
Copy link
Contributor Author

/milestone 0.33.0

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

Very nice and clean PR! Thank you Jason!
I'll wait for approval until 0.32.1 is out :)

This new model uses an async worker and a concurrent queue to handle
stats writing. This ensures better performance, because the live event
processing loop will just need to do a push on the queue instead of writing
to a file (only when the timer triggers), and should be thread-safe by design.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…ction

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

SGMT, just the copyright year to be updated :)

userspace/falco/stats_writer.cpp Outdated Show resolved Hide resolved
userspace/falco/stats_writer.h Outdated Show resolved Hide resolved
jasondellaluce and others added 2 commits August 26, 2022 11:36
Co-authored-by: Leonardo Grasso <me@leonardograsso.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Co-authored-by: Leonardo Grasso <me@leonardograsso.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana poiana added the lgtm label Aug 26, 2022
@poiana
Copy link

poiana commented Aug 26, 2022

LGTM label has been added.

Git tree hash: e61f31be02c7064be6b4fa5fbd89818ee880587c

@poiana
Copy link

poiana commented Aug 26, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, jasondellaluce

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [FedeDP,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

Thank you

@poiana poiana merged commit 574a4b9 into master Aug 26, 2022
@poiana poiana deleted the refactor/stats-writer branch August 26, 2022 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants