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

[auditbeat] - Migration of system/package module to flatbuffers #34817

Merged
merged 19 commits into from Apr 5, 2023

Conversation

ShourieG
Copy link
Contributor

@ShourieG ShourieG commented Mar 13, 2023

Type of change

  • Enhancement

What does this PR do?

This PR is responsible for migrating the storage encoding of packages in auditbeat system/package module from traditional
gob encoding to flatbuffers encoding. This change also makes sure that existing gob encoded packages for users are seamlessly migrated to flatbuffer encoding without loss of any data.

Why is it important?

This migration greatly improves the performance of the system/package module and brings it upto modern standards.
Benchmark tests will soon be added to record performance.

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 .

Related issues

@ShourieG ShourieG requested a review from a team as a code owner March 13, 2023 15:16
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 13, 2023
@ShourieG ShourieG self-assigned this Mar 13, 2023
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 13, 2023
@botelastic
Copy link

botelastic bot commented Mar 13, 2023

This pull request doesn't have a Team:<team> label.

@mergify
Copy link
Contributor

mergify bot commented Mar 13, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @ShourieG? 🙏.
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

@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 13, 2023

💚 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: 2023-04-04T09:24:12.355+0000

  • Duration: 42 min 30 sec

Test stats 🧪

Test Results
Failed 0
Passed 602
Skipped 81
Total 683

💚 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!)

x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/package.fbs Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/faltbuffers.go Outdated Show resolved Hide resolved
@ShourieG ShourieG requested a review from a team as a code owner March 14, 2023 11:47
@ShourieG ShourieG requested review from rdner and leehinman and removed request for a team March 14, 2023 11:47
@ShourieG
Copy link
Contributor Author

ShourieG commented Mar 20, 2023

@efd6 addressed all the issues, added support for errors in the package flatbuff and also added a pool poison test.

@ShourieG
Copy link
Contributor Author

Updated the PR with the recommended changes @efd6

x-pack/auditbeat/module/system/package/flatbuff.go Outdated Show resolved Hide resolved
summary:string;
url:string;
type:string;
error:string;
Copy link
Member

Choose a reason for hiding this comment

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

What is the persisted error needed for?

Copy link
Member

Choose a reason for hiding this comment

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

I tracked this down. When a package is removed the same data that was original detected (including the errors) are transmitted in the removal event.

Copy link
Member

Choose a reason for hiding this comment

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

Correction... so the error field is not exported. And to quote the encoding/gob docs, "Structs encode and decode only exported fields."

This means that the error is not serialized by encoding/gob and the value is not persisted. So this will have a slightly different behavior than we had before. But originally this was designed to persist the error, and there were some issues with serialization (see #18536) so it was changed. Given that the original design was to include the error let's keep it in the flatbuffer schema.

x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/flatbuff.go Outdated Show resolved Hide resolved
@ShourieG
Copy link
Contributor Author

@andrewkroh reworked the bucket migration process to have it migrate to a new bucket during metricset init

@ShourieG ShourieG added the backport-v8.7.0 Automated backport with mergify label Mar 30, 2023
x-pack/auditbeat/module/system/package/flatbuffers.go Outdated Show resolved Hide resolved

// Initialize the Bolt DB.
if ds.db == nil {
var err error
Copy link
Member

Choose a reason for hiding this comment

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

This code is repeated a lot. How about adding a boltDatastore.init() error method.

x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
summary:string;
url:string;
type:string;
error:string;
Copy link
Member

Choose a reason for hiding this comment

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

Correction... so the error field is not exported. And to quote the encoding/gob docs, "Structs encode and decode only exported fields."

This means that the error is not serialized by encoding/gob and the value is not persisted. So this will have a slightly different behavior than we had before. But originally this was designed to persist the error, and there were some issues with serialization (see #18536) so it was changed. Given that the original design was to include the error let's keep it in the flatbuffer schema.

x-pack/auditbeat/module/system/package/package.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/flatbuffers.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/flatbuffers_test.go Outdated Show resolved Hide resolved
x-pack/auditbeat/module/system/package/flatbuffers.go Outdated Show resolved Hide resolved
@andrewkroh
Copy link
Member

While I was reviewing I was making changes in my local copy to test some ideas. I’m going to push to push that commit into your branch so you can see it. I think it better expresses some of the thoughts I had in my review. You don’t have to keep the commit (we can rebase to remove it).

Use a bolt write transaction to perform the entire schema migration
such that failures result in a full rollback. The transaction also
prevents any accidently concurrent migration issues.

I added a test case for the migration that works on a boltdb file
that contains package.v1 data from homebrew.

Any test cases involving encoding/gob encoding were removed. We
only care that we can continue to decode the old gob data.

I also addressed all golangci-lint warnings.
@ShourieG
Copy link
Contributor Author

ShourieG commented Apr 4, 2023

@andrewkroh I went through the changes you made and they look really good, and the migration occurring inside of a bolt transaction solves the multiple instance issue. I think we can move ahead with your suggested changes.

@ShourieG ShourieG removed the backport-v8.7.0 Automated backport with mergify label Apr 4, 2023
@mergify
Copy link
Contributor

mergify bot commented Apr 4, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @ShourieG? 🙏.
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

@ShourieG ShourieG merged commit 804e9c5 into elastic:main Apr 5, 2023
25 checks passed
@ShourieG ShourieG deleted the auditbeat/flat_buffers branch April 5, 2023 10:16
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* initial working commit

* flatbuffers migration now working with tests

* updated changelog

* removed comments

* resolved PR suggetions and updated license

* updated notice

* updated tests, added benchmarks, renamed files

* updated tests & added error storage in schema

* license issue fixed

* updated according to PR suggestions

* refactored package migration based on bucket version and is now done during metric set initialization

* Perform migration inside of a bolt transaction, fix linter warnings

Use a bolt write transaction to perform the entire schema migration
such that failures result in a full rollback. The transaction also
prevents any accidently concurrent migration issues.

I added a test case for the migration that works on a boltdb file
that contains package.v1 data from homebrew.

Any test cases involving encoding/gob encoding were removed. We
only care that we can continue to decode the old gob data.

I also addressed all golangci-lint warnings.

---------

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
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