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(userspace/libsinsp): drop user and group infos embedded in threadinfo #2165

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 19, 2024

What type of PR is this?

/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:

Only store uid, gid and loginuid info.
Storing full info was done to workaround scenarios like:

  • thread X starts with user 1000 "foo"
  • user 1000 gets deleted while thread X runs
  • user 1000 gets recreated with name "bar"
  • extracting user from thread now will give "bar"; with previous impl it would have given "foo".

Basically, we are now respecting what unix expects us to do, since user 1000 will now be mapped to "bar".

Moreover, since threadinfo is used many times, not embedding those bytes saves us lots of memory.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 19, 2024

/milestone 0.20.0

@poiana poiana added this to the 0.20.0 milestone Nov 19, 2024
@poiana poiana added the size/XL label Nov 19, 2024
@FedeDP FedeDP force-pushed the cleanup/drop_user_group_threadinfo branch from 3a9f7b0 to 727fce2 Compare November 19, 2024 12:10
…readinfo.

Only store `uid`, `gid` and `loginuid` info.

Signed-off-by: Federico Di Pierro <[email protected]>
@FedeDP FedeDP force-pushed the cleanup/drop_user_group_threadinfo branch from 727fce2 to 43754ca Compare November 19, 2024 12:19
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 76.31579% with 18 lines in your changes missing coverage. Please review.

Project coverage is 75.06%. Comparing base (facfcc3) to head (0791a6d).
Report is 29 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/threadinfo.cpp 85.10% 7 Missing ⚠️
userspace/libsinsp/parsers.cpp 66.66% 4 Missing ⚠️
userspace/libsinsp/sinsp_filtercheck_user.cpp 55.55% 4 Missing ⚠️
userspace/libsinsp/sinsp_filtercheck_group.cpp 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2165      +/-   ##
==========================================
+ Coverage   74.77%   75.06%   +0.28%     
==========================================
  Files         254      255       +1     
  Lines       33505    33521      +16     
  Branches     5748     5719      -29     
==========================================
+ Hits        25053    25162     +109     
+ Misses       8452     8359      -93     
Flag Coverage Δ
libsinsp 75.06% <76.31%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@FedeDP FedeDP changed the title cleanup(userspace/libsinsp): drop user and group infos embedded in threadinfo wip: cleanup(userspace/libsinsp): drop user and group infos embedded in threadinfo Nov 19, 2024
Copy link

github-actions bot commented Nov 19, 2024

Perf diff from master - unit tests

     3.48%     +1.44%  [.] gzfile_read
     4.96%     +1.13%  [.] sinsp_evt::get_type
     2.52%     +0.91%  [.] sinsp_thread_manager::find_thread
     9.27%     +0.79%  [.] sinsp_parser::reset
     0.26%     +0.70%  [.] std::_Hashtable<long, std::pair<long const, std::shared_ptr<sinsp_threadinfo> >, std::allocator<std::pair<long const, std::shared_ptr<sinsp_threadinfo> > >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::find
     4.64%     +0.67%  [.] next
     1.42%     -0.64%  [.] sinsp_evt::get_syscall_return_value
     2.00%     -0.61%  [.] std::_Hashtable<long, std::pair<long const, std::shared_ptr<sinsp_threadinfo> >, std::allocator<std::pair<long const, std::shared_ptr<sinsp_threadinfo> > >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_find_before_node
     1.45%     -0.60%  [.] 0x00000000000ea3a0
     0.10%     +0.56%  [.] sinsp_split[abi:cxx11]

Heap diff from master - unit tests

peak heap memory consumption: 2.32M
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: 58.87K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            -0.0210         -0.0210           148           145           148           145
BM_sinsp_split_median                                          -0.0202         -0.0203           148           145           148           145
BM_sinsp_split_stddev                                          -0.2528         -0.2524             1             1             1             1
BM_sinsp_split_cv                                              -0.2367         -0.2363             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0068         +0.0068            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_median                +0.0029         +0.0028            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_stddev                +2.9077         +2.9145             0             1             0             1
BM_sinsp_concatenate_paths_relative_path_cv                    +2.8812         +2.8880             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     +0.0392         +0.0392            24            25            24            25
BM_sinsp_concatenate_paths_empty_path_median                   +0.0351         +0.0351            24            25            24            25
BM_sinsp_concatenate_paths_empty_path_stddev                   +0.6269         +0.6275             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +0.5655         +0.5660             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.0114         +0.0114            56            56            56            56
BM_sinsp_concatenate_paths_absolute_path_median                +0.0098         +0.0098            56            56            56            56
BM_sinsp_concatenate_paths_absolute_path_stddev                +1.3622         +1.3625             0             1             0             1
BM_sinsp_concatenate_paths_absolute_path_cv                    +1.3356         +1.3360             0             0             0             0
BM_sinsp_split_container_image_mean                            -0.0082         -0.0082           383           380           383           380
BM_sinsp_split_container_image_median                          -0.0076         -0.0076           384           381           384           381
BM_sinsp_split_container_image_stddev                          +0.4949         +0.4940             2             2             2             2
BM_sinsp_split_container_image_cv                              +0.5073         +0.5064             0             0             0             0

@FedeDP FedeDP changed the title wip: cleanup(userspace/libsinsp): drop user and group infos embedded in threadinfo cleanup(userspace/libsinsp): drop user and group infos embedded in threadinfo Nov 20, 2024
new_child->set_user(new_child->m_user.uid());
new_child->set_loginuser(new_child->m_loginuser.uid());
new_child->set_group(new_child->m_group.gid());
new_child->set_group(new_child->m_gid);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Always group first, since it is used by set_user as gid to be passed to user_group_manager.add_user : https://github.com/falcosecurity/libs/pull/2165/files#diff-f1f5adc2cc836ddaf885f86ded61c940d5c957781ea3ef5cef7f4c6f407054f7R539

Comment on lines 517 to 532
const sinsp_threadinfo::cgroups_t& sinsp_threadinfo::cgroups() const {
return m_cgroups;
}

std::string sinsp_threadinfo::get_comm() const {
return m_comm;
}

std::string sinsp_threadinfo::get_exe() const {
return m_exe;
}

std::string sinsp_threadinfo::get_exepath() const {
return m_exepath;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No changes here.

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 the cleanup!

userspace/libsinsp/threadinfo.cpp Outdated Show resolved Hide resolved
userspace/libsinsp/threadinfo.cpp Outdated Show resolved Hide resolved
userspace/libsinsp/parsers.cpp Outdated Show resolved Hide resolved
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 27, 2024

Thanks @Andreagit97 ! Pushed the changes addressing your review comments!

Andreagit97
Andreagit97 previously approved these changes Nov 27, 2024
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

@Andreagit97
Copy link
Member

ops you missed a replace of set_loginuid

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 27, 2024

yup just saw that ahah

Signed-off-by: Federico Di Pierro <[email protected]>

Co-authored-by: Andrea Terzolo <[email protected]>
@FedeDP FedeDP force-pushed the cleanup/drop_user_group_threadinfo branch from 45cd5af to 0791a6d Compare November 27, 2024 12:21
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 27, 2024

Fixed! Thanks!

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 Nov 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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:

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

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