Skip to content

Conversation

deepskyblue86
Copy link
Member

What type of PR is this?

/kind feature

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:
Have get_dynamic_field being const, so it can be used as a regular getter.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@poiana
Copy link
Contributor

poiana commented Jun 26, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepskyblue86
Once this PR has been reviewed and has the lgtm label, please assign ekoops for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@poiana poiana requested review from hbrueckner and mstemm June 26, 2025 13:50
@poiana poiana added the size/S label Jun 26, 2025
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.35%. Comparing base (c4ea330) to head (ee14b3e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2511   +/-   ##
=======================================
  Coverage   78.35%   78.35%           
=======================================
  Files         281      281           
  Lines       31689    31689           
  Branches     4643     4643           
=======================================
+ Hits        24830    24831    +1     
+ Misses       6859     6858    -1     
Flag Coverage Δ
libsinsp 78.35% <100.00%> (+<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.

@FedeDP
Copy link
Contributor

FedeDP commented Jun 26, 2025

/milestone 0.22.0

@poiana poiana added this to the 0.22.0 milestone Jun 26, 2025
}

std::vector<void*> m_fields;
mutable std::vector<void*> m_fields;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason behind this mutable here?

Copy link
Contributor

Choose a reason for hiding this comment

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

We return a pointer to an item inside m_fields, but if the vector is too small, we resize it first (see _access_dynamic_field() above)

Copy link
Member Author

Choose a reason for hiding this comment

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

get_dynamic_field calls _access_dynamic_field.
Dynamic fields are lazily constructed there, and inserted into m_fields.
Without the mutable we can't make the thing const.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about providing a separate const accessor to the field? In general, I would avoid using mutable as I think it is just a way of hiding non-constness.

Copy link
Member Author

Choose a reason for hiding this comment

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

That won't work, unless we make the field loading non-lazy, and I assume it was done like that on purpose (performance reasons? avoiding allocations until the field gets accessed?).
If you think of it as an internal cache, we're not really breaking the "OOP" constness of the class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we e.g. return nullptr from the const accessor (and handle it in a higher layer by returning the default value)?

This would make it even lazier, if anything (the field would get allocated on write, not on read). I have a vague uneasy feeling about mutable (something something thread safety), but if the nullptr approach doesn't work for whatever reason, I guess this is the way to go

@leogr
Copy link
Member

leogr commented Sep 24, 2025

/milestone 0.23.0

@poiana poiana modified the milestones: 0.22.0, 0.23.0 Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

6 participants