Skip to content

cleanup(sinsp)!: clarify get_thread_ref vs find_thread#2694

Merged
poiana merged 2 commits intofalcosecurity:masterfrom
gnosek:get-thread-ref
Oct 24, 2025
Merged

cleanup(sinsp)!: clarify get_thread_ref vs find_thread#2694
poiana merged 2 commits intofalcosecurity:masterfrom
gnosek:get-thread-ref

Conversation

@gnosek
Copy link
Copy Markdown
Contributor

@gnosek gnosek commented Oct 15, 2025

What type of PR is this?

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

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

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

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

get_thread_ref potentially looks up a thread in /proc, which comes with extra dependencies (usergroup_manager, transitively via threadinfo), but in the majority of cases, it does not (query_os_if_not_found is usually false). In this case, it's equivalent to find_thread, so replace these uses with find_thread and make get_thread_ref always do a /proc lookup (if needed).

Also, rename get_thread_ref to get_thread, to force a compilation error (otherwise the query_os_if_not_found parameter could be mistaken for lookup_only if the latter had a default specified).

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 15, 2025

Codecov Report

❌ Patch coverage is 98.03922% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.62%. Comparing base (a1fb4a4) to head (6b06550).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/sinsp_filtercheck_thread.cpp 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2694      +/-   ##
==========================================
- Coverage   77.62%   77.62%   -0.01%     
==========================================
  Files         294      294              
  Lines       31971    31947      -24     
  Branches     4721     4712       -9     
==========================================
- Hits        24817    24798      -19     
+ Misses       7154     7149       -5     
Flag Coverage Δ
libsinsp 77.62% <98.03%> (-0.01%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

When query_os_if_not_found is false, get_thread_ref does the same thing
as find_thread. Remove this indirection and call find_thread directly,
whenever possible.

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
All the remaining uses of get_thread_ref want a proc lookup so remove
the now redundant parameter.

The method is renamed to get_thread to force a compile error when
updating to a newer libs version, due to the two bool parameters
with defaults that could be confused and end up with different
semantics (the value of query_os_if_not_found would now become
the value of lookup_only).

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
@terror96
Copy link
Copy Markdown
Contributor

/milestone 0.23.0

@gnosek
Copy link
Copy Markdown
Contributor Author

gnosek commented Oct 16, 2025

Note: I hoped this would let me do some bigger cleanups later. Sadly, I underestimated the level to which all the components are entangled and I will have to keep the usergroup_manager reference inside the thread_manager no matter what, so this PR is not really a prerequisite to anything else and now stands on its own. I still feel it's nice to have just one way to do a non-/proc thread lookup rather than two though :)

@ekoops ekoops modified the milestones: 0.23.0, next-driver, 0.22.0 Oct 16, 2025
Copy link
Copy Markdown
Contributor

@ekoops ekoops left a comment

Choose a reason for hiding this comment

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

Great improvement! In the future, we could also think about switching the name of these two: sinsp_thread_manager::get_thread() and sinsp_thread_manager::find_thread(). sinsp_thread_manager::find_thread() is just a simple getter, while sinsp_thread_manager::get_thread() can do proc scanning, so their current name are a bit misleading.

Anyway,
/approve

@poiana
Copy link
Copy Markdown
Contributor

poiana commented Oct 24, 2025

LGTM label has been added.

DetailsGit tree hash: 1562c85d8d2737d8fe5d8200dfb7b26c7731cf02

@poiana
Copy link
Copy Markdown
Contributor

poiana commented Oct 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops, gnosek

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

The pull request process is described here

Details 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

@github-project-automation github-project-automation bot moved this from Todo to In progress in Falco Roadmap Oct 24, 2025
@poiana poiana merged commit 0376a8f into falcosecurity:master Oct 24, 2025
46 of 47 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Falco Roadmap Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants