-
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.85% -0.01%
==========================================
Files 195 195
Lines 6151 6153 +2
==========================================
+ Hits 5404 5405 +1
- Misses 747 748 +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.
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.
value_ = value; | ||
} | ||
|
||
DataList(const DataList &other) |
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.
Ok to have a copy constructor, this clears the cppcheck warning, and is safer in case of refactoring.
I suspect this code to be unreachable.
@@ -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.
inline context::Context SetSpan(context::Context &context, | ||
const nostd::shared_ptr<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.
Helper inlined.
Approved as ABI safe.
@chusitoo The CI is now merged to main, please merge main into this PR to resolve the conflicts. |
.github/workflows/cppcheck.yml
Outdated
@@ -73,4 +58,5 @@ jobs: | |||
set +e | |||
COUNT=`grep -c -E "\[.+\]" cppcheck.log` | |||
echo "cppcheck reported ${COUNT} warning(s)" | |||
if [ $COUNT -ne 0 ] ; then exit 1 ; fi | |||
# TODO: uncomment to enforce failing the build | |||
# if [ $COUNT -ne 0 ] ; then exit 1 ; fi |
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 this check be re-enabled now?
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.
Yes, please do.
If there are unresolved warnings left, it is ok to test with some margin, say count > 5
.
The point is to prevent new errors to come in with more merges, while giving us time to resolve possibly more complex issues in follow up PRs and ultimately have count > 0
.
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.
|
||
return opentelemetry::sdk::common::ExportResult::kFailure; | ||
const auto result = opentelemetry::sdk::common::ExportResult::kFailure; | ||
result_callback(result); |
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 and in other places, the call to result_callback() has moved a bit.
Could you provide more details ?
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.
Absolutely. The scan reports an [accessMoved] warning here
This is due to the move that happens higher in OtlpHttpClient::Export()
on L753 which seems as though it is likely undefined behavior calling it from that point on.
Since the moved from result_callback
appears to be used only to consume the result from createSession()
, my solution was to move the invocation closer to the call sites where it's been moved to, just before the function returns the actual result.
@@ -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.
@@ -85,6 +85,7 @@ class BatchLogRecordProcessor : public LogRecordProcessor | |||
* | |||
* NOTE: Timeout functionality not supported yet. | |||
*/ | |||
// 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.
Remove the suppression, and identify/fix callers.
@@ -43,6 +43,7 @@ class MultiLogRecordProcessor : public LogRecordProcessor | |||
* @param timeout that the forceflush is required to finish within. | |||
* @return a result code indicating whether it succeeded, failed or timed out | |||
*/ | |||
// 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.
Remove the suppression, and identify/fix callers.
@@ -53,6 +54,7 @@ class MultiLogRecordProcessor : public LogRecordProcessor | |||
* shutdown before giving up and returning failure. | |||
* @return true if the shutdown succeeded, false otherwise | |||
*/ | |||
// 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.
Remove the suppression, and identify/fix callers.
@@ -83,6 +83,7 @@ class BatchSpanProcessor : public SpanProcessor | |||
* | |||
* NOTE: Timeout functionality not supported yet. | |||
*/ | |||
// 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.
Remove the suppression, and identify/fix callers.
@@ -121,6 +121,7 @@ class MultiSpanProcessor : public SpanProcessor | |||
return result; | |||
} | |||
|
|||
// 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.
Remove the suppression, and identify/fix callers.
@@ -74,6 +74,7 @@ class SimpleSpanProcessor : public SpanProcessor | |||
return true; | |||
} | |||
|
|||
// 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.
Remove the suppression, and identify/fix callers.
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.
Fixes #2297
Changes
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes