-
Notifications
You must be signed in to change notification settings - Fork 905
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
Improve class initialization #3074
Improve class initialization #3074
Conversation
This PR may bring feature or behavior changes in the Falco engine and may require the engine version to be bumped. Please double check userspace/engine/falco_engine_version.h file. See versioning for FALCO_ENGINE_VERSION. /hold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
Yes this is also in line with some feedback @federico-sysdig gave in some libs PRs.
LGTM label has been added. Git tree hash: bba4873503e26fad06b18b25ae3b2f332aa9f89e
|
/unhold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like these kinds of cleanups. I left a few comments on how it can be done to further simplify the implementation.
userspace/falco/versions_info.cpp
Outdated
: falco_version(FALCO_VERSION) | ||
, engine_version(FALCO_ENGINE_VERSION) | ||
, libs_version(FALCOSECURITY_LIBS_VERSION) | ||
, plugin_api_version(inspector->get_plugin_api_version()) | ||
, driver_api_version(get_driver_api_version(inspector)) | ||
, driver_schema_version(get_driver_schema_version(inspector)) | ||
, default_driver_version(DRIVER_VERSION) | ||
|
||
{ | ||
falco_version = FALCO_VERSION; | ||
engine_version = FALCO_ENGINE_VERSION; | ||
libs_version = FALCOSECURITY_LIBS_VERSION; | ||
plugin_api_version = inspector->get_plugin_api_version(); | ||
driver_api_version = get_driver_api_version(inspector); | ||
driver_schema_version = get_driver_schema_version(inspector); | ||
default_driver_version = DRIVER_VERSION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here 4 data members are initialized to a constant, thus they could/should have been initialized right at the declaration site (falco_version
, engine_version
, libs_version
, and default_driver_version
).
Note that the 4 SMF's, copy/move constructors + copy/move assignments, are generated by the compiler and an explicit default definition can/should be avoided.
struct versions_info
{
/**
* @brief Construct a versions info by using an inspector to obtain
* versions about the drivers and the loaded plugins.
*/
explicit versions_info(const std::shared_ptr<sinsp>&);
/**
* @brief Encode the versions info as a JSON object
*/
nlohmann::json as_json() const;
std::string falco_version = FALCO_VERSION;
std::string engine_version = FALCO_ENGINE_VERSION;
std::string libs_version = FALCOSECURITY_LIBS_VERSION;
std::string plugin_api_version;
std::string driver_api_version;
std::string driver_schema_version;
std::string default_driver_version = DRIVER_VERSION;
std::unordered_map<std::string, std::string> plugin_versions;
};
Note:
This is not related to this PR, but passing objects by shared_ptr
when only the object is used, as we do for inspector
in the constructor of versions_info
, is overkill and should be avoided by passing a reference or a raw pointer. In this case the need comes from the two functions get_driver_api_version
and get_driver_schema_version
which take inspector
as a smart pointer, again, without any real need to do so. Again, overkill for readability and, sometimes, performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, would this something to be done in a follow up PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, would this something to be done in a follow up PR ?
The note on the changing the parameter shared_ptr<sinsp>
to a reference or a pointer? Yes, I'd say it can be addressed later.
userspace/falco/stats_writer.cpp
Outdated
: m_initialized(false), m_total_samples(0) | ||
: m_initialized(false) | ||
, m_total_samples(0) | ||
, m_config(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here, m_initialized
and m_total_samples
can be more simply initialized at the declaration site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a PR that does this on a more global scale ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, but you can get warmed up here, if you care.
/milestone 0.38.0 |
99b6571
to
3a021d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: 11f862a17bdc9e18fd9eb9c62a37538613199ccf
|
…n list Reported by cppcheck Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch> # Conflicts: # userspace/engine/falco_common.h
The implementation provides more or less the same implementation and thus it makes more sense to base it on std::runtime_error. Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch>
Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch>
Signed-off-by: Samuel Gaist <samuel.gaist@idiap.ch>
3a021d1
to
2b76feb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: 9df54a0b87e02fa96709e32dd3608a7d3f3525d0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, incertum, sgaist 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 |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area engine
What this PR does / why we need it:
This PR refactors member variables initialization so that they are done in the constructor initialization list.
They were detected by cppcheck.
Which issue(s) this PR fixes:
Fixes #3073
Special notes for your reviewer:
Does this PR introduce a user-facing change?: