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

cleanup(sinsp): move engine/platform selection code to libsinsp #1401

Merged
merged 24 commits into from
Oct 30, 2023

Conversation

gnosek
Copy link
Contributor

@gnosek gnosek commented Oct 10, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap-engine-udig

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

This PR continues the work of decoupling libscap from platform code. The motivation is to (eventually):

  • move all the parsing/data structure heavy code to C++
  • strip down libscap to the bare essentials for getting events
  • remove code duplication for platform data structures (scap_threadinfo vs sinsp_threadinfo etc.)
  • kill uthash :)

Baby steps though, this PR moves the code responsible for engine/platform selection to libsinsp (in particular, sinsp::open_* methods). All the platform code still lives in libscap for the time being.

I'm planning some follow up PRs (though this one feels okay as a standalone submission too):

  • make sinsp own the m_platform pointer (remove it from scap_t)
  • make savefile code independent of platform specifics (delegate platform data save/load to platforms)
  • build a C++ interface to the platform code
  • move over the platform code to sinsp (with no substantial modifications)
  • actually rewrite into C++; this is probably going to take a while :)

All but the last one are more or less done, for the actual rewrite I have some sketches but not yet finished code as I'd rather avoid rebasing the inevitable giant patch set over and over :)

In the end, I see the platform class as owning ~all the syscall parser code, with e.g. container/k8s support building on top of that. It's going to substantially change the center of gravity of libsinsp, which would become a pipeline for events into various "plugins" (using the term very loosely), but also enables us to e.g. support non-Linux OSes cleanly.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

This PR does not affect any sinsp APIs but does affect scap. Not sure whether we consider this an API change: does anybody use raw libscap in the real world?

Does this PR introduce a user-facing change?:

BREAKING CHANGE: scap_init (and related functions) no longer initialize the platform
BREAKING CHANGE: scap_mode_t and its values are now renamed to sinsp_mode_t and SINSP_MODE_*

@gnosek gnosek force-pushed the platform-sinsp-selection branch from b6d9147 to fab324f Compare October 10, 2023 19:45
@gnosek gnosek changed the title cleanup(sinsp): move engine/platform selection code to libsinsp wip: cleanup(sinsp): move engine/platform selection code to libsinsp Oct 11, 2023
@gnosek gnosek force-pushed the platform-sinsp-selection branch 6 times, most recently from 053a960 to 4401d55 Compare October 12, 2023 14:08
@gnosek gnosek changed the title wip: cleanup(sinsp): move engine/platform selection code to libsinsp cleanup(sinsp): move engine/platform selection code to libsinsp Oct 12, 2023
@FedeDP
Copy link
Contributor

FedeDP commented Oct 17, 2023

/milestone 0.14.0

@poiana poiana added this to the 0.14.0 milestone Oct 17, 2023
cmake/modules/engine_config.cmake Show resolved Hide resolved
userspace/libsinsp/sinsp.cpp Outdated Show resolved Hide resolved
userspace/libsinsp/sinsp.cpp Outdated Show resolved Hide resolved
@leogr
Copy link
Member

leogr commented Oct 17, 2023

This PR does not affect any sinsp APIs but does affect scap. Not sure whether we consider this an API change: does anybody use raw libscap in the real world?

I don't know, but I would still signal it as a breaking change in the release-note block
(we use ! or BREAKING CHANGE: as per https://www.conventionalcommits.org/en/v1.0.0/#specification point 13).

@gnosek gnosek force-pushed the platform-sinsp-selection branch from 4401d55 to ce02d53 Compare October 17, 2023 10:52
@gnosek gnosek force-pushed the platform-sinsp-selection branch from ce02d53 to aeda51d Compare October 17, 2023 10:53
AS of now, libscap doesn't know anything about selecting engines
or platforms and defers this to sinsp (or the consumer, when using
scap directly)

Signed-off-by: Grzegorz Nosek <[email protected]>
They are handled by the (Linux) platform, not the engine

Signed-off-by: Grzegorz Nosek <[email protected]>
Andreagit97
Andreagit97 previously approved these changes Oct 30, 2023
Copy link
Member

@Andreagit97 Andreagit97 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 for this!
/approve

@poiana
Copy link
Contributor

poiana commented Oct 30, 2023

LGTM label has been added.

Git tree hash: c01b0b03d91d8676f419a92de9db6efa494604b4

libscap doesn't need it any more and sinsp can pass it to the only
place that needs it (sinsp::open_common) directly.

Note: we could just also set m_mode in the individual sinsp::open_*
methods but this way we save a tiny bit of code duplication.

Signed-off-by: Grzegorz Nosek <[email protected]>
It matches the new role of the function better

Signed-off-by: Grzegorz Nosek <[email protected]>
userspace/libsinsp/sinsp.h Outdated Show resolved Hide resolved
switch(mode)
{
case SCAP_MODE_PLUGIN:
platform = scap_generic_alloc_platform(::on_new_entry_from_proc, this);
Copy link
Member

Choose a reason for hiding this comment

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

Amazing thank you!

scap_mode_t is now named sinsp_mode_t to reflect that it's not used
in libscap at all, and all the enum values are renamed from SCAP_MODE_*
to SINSP_MODE_*

Signed-off-by: Grzegorz Nosek <[email protected]>
@Andreagit97
Copy link
Member

if the CI becomes green we are good to go IMO

@gnosek gnosek force-pushed the platform-sinsp-selection branch from af92f50 to 7a197f5 Compare October 30, 2023 10:04
@gnosek
Copy link
Contributor Author

gnosek commented Oct 30, 2023

the s390x build only took a bit over two and a half hours :D

Copy link
Member

@Andreagit97 Andreagit97 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 Oct 30, 2023
@poiana
Copy link
Contributor

poiana commented Oct 30, 2023

LGTM label has been added.

Git tree hash: 140f211f7235ebd1299c012fbbb667eeb0f697b6

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
Copy link
Contributor

poiana commented Oct 30, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, gnosek

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 [Andreagit97,FedeDP,gnosek]

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

@poiana poiana merged commit cbab0d8 into falcosecurity:master Oct 30, 2023
21 checks passed
@gnosek gnosek deleted the platform-sinsp-selection branch October 30, 2023 20:28
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.

7 participants