-
Notifications
You must be signed in to change notification settings - Fork 425
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
[Code health] Perform cppcheck cleanup #3150
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3150 +/- ##
==========================================
+ Coverage 87.86% 87.86% +0.01%
==========================================
Files 195 195
Lines 6151 6153 +2
==========================================
+ Hits 5404 5406 +2
Misses 747 747
|
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.
LGTM, thanks for the contribution.
Please add a separate PR for the CI alone, which can be merged right away in the main branch. Comment out the last step, to not fail the build on errors, this will be enforced when cleanup is completed.
This will allow us reviewers to actually see the current cppcheck errors in the log, which will facilitate review, as we won't have to ask "why ?" or "what was the error ?" on various lines fixed.
After CI is merged, this PR will contain only the cleanup fixes then.
Comments on actual code cleanup to follow.
@@ -27,7 +27,7 @@ inline nostd::shared_ptr<Baggage> GetBaggage(const context::Context &context) no | |||
} | |||
|
|||
inline context::Context SetBaggage(context::Context &context, | |||
nostd::shared_ptr<Baggage> baggage) noexcept | |||
const nostd::shared_ptr<Baggage> &baggage) noexcept |
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.
Providing details because this is not trivial, as justification, for all reviewers:
- ABI change (the prototype is different)
- on a helper API
- which is inlined anyway, expanded in the caller compile unit
Hence:
- there is no ABI change overall, as no API implemented by the SDK is touched
Approved, this is safe IMO.
: head_{nostd::shared_ptr<DataList>{new DataList(keys_and_values)}} | ||
{} |
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.
Approved as ABI safe, implementation change only.
: head_{nostd::shared_ptr<DataList>{new DataList(key, value)}} | ||
{} |
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.
Approved as ABI safe, implementation change only.
@@ -32,7 +32,7 @@ class OPENTELEMETRY_EXPORT GlobalTextMapPropagator | |||
return nostd::shared_ptr<TextMapPropagator>(GetPropagator()); | |||
} | |||
|
|||
static void SetGlobalPropagator(nostd::shared_ptr<TextMapPropagator> prop) noexcept | |||
static void SetGlobalPropagator(const nostd::shared_ptr<TextMapPropagator> &prop) noexcept |
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.
Helper inlined.
Approved as ABI safe.
static void SetRuntimeContextStorage( | ||
const nostd::shared_ptr<RuntimeContextStorage> &storage) noexcept |
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.
Helper inlined.
Approved as ABI safe.
@@ -19,9 +19,9 @@ namespace logs | |||
class EventId | |||
{ | |||
public: | |||
EventId(int64_t id, nostd::string_view name) noexcept : id_{id} | |||
EventId(int64_t id, nostd::string_view name) noexcept | |||
: id_{id}, name_{nostd::unique_ptr<char[]>{new char[name.length() + 1]}} |
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.
ABI safe, internal implementation change.
@@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT Provider | |||
/** | |||
* Changes the singleton LoggerProvider. | |||
*/ | |||
static void SetLoggerProvider(nostd::shared_ptr<LoggerProvider> tp) noexcept | |||
static void SetLoggerProvider(const nostd::shared_ptr<LoggerProvider> &tp) noexcept |
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.
Helper inlined.
Approved as ABI safe.
@@ -60,7 +60,7 @@ class OPENTELEMETRY_EXPORT Provider | |||
/** | |||
* Changes the singleton EventLoggerProvider. | |||
*/ | |||
static void SetEventLoggerProvider(nostd::shared_ptr<EventLoggerProvider> tp) noexcept | |||
static void SetEventLoggerProvider(const nostd::shared_ptr<EventLoggerProvider> &tp) noexcept |
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.
Helper inlined.
Approved as ABI safe.
@@ -38,7 +38,7 @@ class Provider | |||
/** | |||
* Changes the singleton MeterProvider. | |||
*/ | |||
static void SetMeterProvider(nostd::shared_ptr<MeterProvider> tp) noexcept | |||
static void SetMeterProvider(const nostd::shared_ptr<MeterProvider> &tp) noexcept |
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.
Helper inlined.
Approved as ABI safe.
@@ -20,7 +20,7 @@ class DynamicLibraryHandle; | |||
class Span final : public trace::Span | |||
{ | |||
public: | |||
Span(std::shared_ptr<trace::Tracer> &&tracer, nostd::shared_ptr<trace::Span> span) noexcept | |||
Span(std::shared_ptr<trace::Tracer> &&tracer, const nostd::shared_ptr<trace::Span> &span) noexcept |
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 changing the span constructor does not change the object layout or virtual table, should be ok.
This plugin class in particular is not inherited from in the SDK, changing the constructor is ok.
Approved as ABI safe.
Beside, plugin/tracer.h is not used as far as I know.
@chusitoo The CI is now merged to main, please merge main into this PR to resolve the conflicts. |
@@ -309,6 +307,7 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient | |||
std::shared_ptr<opentelemetry::ext::http::client::Session> CreateSession( | |||
nostd::string_view url) noexcept override; | |||
|
|||
// cppcheck-suppress [virtualCallInConstructor] |
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.
Please remove the suppression.
Instead, if this still raises a warning in cppcheck, we need to find where from, and fix the caller code.
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.
Please note that this and all other suppressions of [virtualCallInConstructor]
are false positives no longer reported in v2.14+, as alluded to in the changelog summary.
I will revert, as requested. As a future improvement, using a more updated version of cppcheck (built from source) should mitigate these warnings.
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.
@marcalff I am noticing that the changes I had put in circular_buffer.h to suppress both [arithOperationsOnVoidPointer]
are no longer reported in v2.16, so I am wondering if all these false positives waiting to be addressed should be documented somewhere. I think this would be beneficial to avoid repeat investigation when the fix is updating the scanner 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.
Thanks for the changes and the details.
@marcalff I am noticing that the changes I had put in circular_buffer.h to suppress both
[arithOperationsOnVoidPointer]
are no longer reported in v2.16, so I am wondering if all these false positives waiting to be addressed should be documented somewhere. I think this would be beneficial to avoid repeat investigation when the fix is updating the scanner version.
A possible solution is to list these in this PR comments
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 suggestion, thanks!
To summarize the 9 outstanding false positives currently being reported by cppcheck v2.13, can be mitigated by using a newer release, more precisely:
v2.14 fixes
- ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h:310:8: style: Virtual function 'CancelAllSessions' is called from destructor '~HttpClient()' at line 206. Dynamic binding is not used. [virtualCallInConstructor]
- sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h:88:8: style: Virtual function 'Shutdown' is called from destructor '~BatchLogRecordProcessor()' at line 325. Dynamic binding is not used. [virtualCallInConstructor]
- sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h:46:8: style: Virtual function 'ForceFlush' is called from destructor '~MultiLogRecordProcessor()' at line 33. Dynamic binding is not used. [virtualCallInConstructor]
- sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h:56:8: style: Virtual function 'Shutdown' is called from destructor '~MultiLogRecordProcessor()' at line 34. Dynamic binding is not used. [virtualCallInConstructor]
- sdk/include/opentelemetry/sdk/trace/batch_span_processor.h:86:8: style: Virtual function 'Shutdown' is called from destructor '~BatchSpanProcessor()' at line 322. Dynamic binding is not used. [virtualCallInConstructor]
- sdk/include/opentelemetry/sdk/trace/multi_span_processor.h:124:8: style: Virtual function 'Shutdown' is called from destructor '~MultiSpanProcessor()' at line 140. Dynamic binding is not used. [virtualCallInConstructor]
- sdk/include/opentelemetry/sdk/trace/simple_processor.h:77:8: style: Virtual function 'Shutdown' is called from destructor '~SimpleSpanProcessor()' at line 88. Dynamic binding is not used. [virtualCallInConstructor]
v2.16 fixes
- sdk/include/opentelemetry/sdk/common/circular_buffer.h:188:16: portability: 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]
- sdk/include/opentelemetry/sdk/common/circular_buffer.h:190:50: portability: 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]
sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h
Outdated
Show resolved
Hide resolved
sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h
Outdated
Show resolved
Hide resolved
sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h
Outdated
Show resolved
Hide resolved
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.
Thanks for the cleanup.
All the code under api/ looks good to me, but I would like to have a second opinion (@lalitb , @ThomsonTan , @esigo) due to the risk of breaking the ABI.
See new comments for non api code.
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.
LGTM, excellent cleanup.
@lalitb , @ThomsonTan , @esigo,
Please double check the code under api/
in particular, due to the risk of breaking the ABI.
I left comments to indicate why I think each change is safe.
Fixes #2297
Changes
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes