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/libsinsp): catch filter field-operator compatibility at compile-time instead of run-time #1857

Merged
merged 8 commits into from
May 16, 2024

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind bug

/kind cleanup

Any specific area of the project related to this PR?

/area libsinsp

Does this PR require a change in the driver versions?

What this PR does / why we need it:

This attempts solving an historical bug in the filtering code area of libsinsp. When using a comparison operator with a field type with which it's not compatible (e.g. doing fd.num contains 5, where fd.num is a numeric field on which the container operator can't be applied), we used to throw an exception only when the filter was evaluated at run-time. This is problematic, because if no event never reaches that specific check for evaluation (due to the boolean expression of the filter), then it becomes totally unpredictable to understand if the check is valid or now -- rather, we'd discover it from an non-deterministic unexpected exception.

This PR attempts solving the problem as follows:

  • Splitting the source code responsible of implementing the comparison operators in its own unit filter_compare.cpp, whereas they used to inappropriately be in sinsp_filtercheck.cpp. Git blame has been preserved wherever possible
  • The validity checks done at comparison time has been split in flt_is_comparable_* functions that are invoked for compile-time checking by the sinsp filter compiler

I paid extra attention in respecting the type-operator grid currently supported (whether by mistake or intentionally).

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

refactor(userspace/libsinsp): catch filter field-operator compatibility at compile-time instead of run-time

@jasondellaluce
Copy link
Contributor Author

/milestone 0.17.0

@poiana poiana added this to the 0.17.0 milestone May 9, 2024
@jasondellaluce jasondellaluce force-pushed the experiment/comp-check-filter-load-time branch 4 times, most recently from e84f822 to 3993021 Compare May 9, 2024 10:52
@jasondellaluce jasondellaluce force-pushed the experiment/comp-check-filter-load-time branch from d0a8d67 to edf3d29 Compare May 14, 2024 11:20
@LucaGuerra LucaGuerra modified the milestones: 0.17.0, next-driver May 15, 2024
test_filter_compile(factory, "c.buffer bstartswith abc_1", true);
}

TEST(sinsp_filter_compiler, operators_field_types_compatibility)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for this! <3

Copy link
Contributor

@LucaGuerra LucaGuerra left a comment

Choose a reason for hiding this comment

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

LGTM

@poiana
Copy link
Contributor

poiana commented May 16, 2024

LGTM label has been added.

Git tree hash: c52d4694549ab29673fd85f521eedbb154abdc40

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

poiana commented May 16, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, jasondellaluce, LucaGuerra

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,LucaGuerra,jasondellaluce]

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 0b18e73 into master May 16, 2024
38 of 40 checks passed
@poiana poiana deleted the experiment/comp-check-filter-load-time branch May 16, 2024 13:32
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.

4 participants