Skip to content

Conversation

@dbarker
Copy link
Member

@dbarker dbarker commented Jun 24, 2025

Contributes to #2053

Changes

Fix some clang-tidy warnings:

  • metric sdk (aggregation)
  • logs sdk (processors and tests)
  • otlp file client
  • otlp http client
  • misc-unused-using-decls warnings
  • performance-avoid-endl warnings
  • cppcoreguidelines-avoid-const-or-ref-data-members warnings for const data members

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@netlify
Copy link

netlify bot commented Jun 24, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 4480f10
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/685a1a79b429e40008eb19b0

@codecov
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 89.95%. Comparing base (1d41125) to head (4480f10).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...k/src/metrics/aggregation/lastvalue_aggregation.cc 50.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3493      +/-   ##
==========================================
+ Coverage   89.92%   89.95%   +0.03%     
==========================================
  Files         219      219              
  Lines        7042     7039       -3     
==========================================
- Hits         6332     6331       -1     
+ Misses        710      708       -2     
Files with missing lines Coverage Δ
...ry/sdk/metrics/aggregation/lastvalue_aggregation.h 0.00% <ø> (ø)
...elemetry/sdk/metrics/aggregation/sum_aggregation.h 0.00% <ø> (ø)
sdk/src/logs/batch_log_record_processor.cc 83.12% <100.00%> (ø)
sdk/src/logs/multi_log_record_processor.cc 88.06% <100.00%> (+0.37%) ⬆️
sdk/src/logs/simple_log_record_processor.cc 100.00% <100.00%> (ø)
sdk/src/metrics/aggregation/sum_aggregation.cc 93.34% <ø> (+3.02%) ⬆️
sdk/src/metrics/state/metric_collector.cc 93.23% <ø> (ø)
...k/src/metrics/aggregation/lastvalue_aggregation.cc 81.67% <50.00%> (-1.14%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbarker dbarker changed the title Fix clang tidy warnings part 1 [CodeHealth] Fix clang-tidy warnings part 1 Jun 24, 2025
{
LastValuePointData merge_data = nostd::get<LastValuePointData>(ToPoint());
return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(merge_data)));
return std::unique_ptr<Aggregation>(new LongLastValueAggregation(merge_data));
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes:

warning: std::move of the variable 'merge_data' of the trivially-copyable type 'LastValuePointData' has no effect [performance-move-const-arg]

Copy link
Member

Choose a reason for hiding this comment

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

I bellieve it's a mistake of clang. But it's OK to copy LastValuePointData because it's small and will not cost a lot.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. The class is trivially copyable, but we could consider disabling this warning with clang-tidy and keep the std::move. I'd prefer to keep the warning enabled and remove the moves that don't have any effect.

{
public:
DoubleLastValueAggregation();
DoubleLastValueAggregation(LastValuePointData &&);
Copy link
Member Author

Choose a reason for hiding this comment

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

LastValuePointData is trivially-copyable and std::move has no effect.

public:
explicit OtlpFileOstreamBackend(const std::reference_wrapper<std::ostream> &os) : os_(os) {}

~OtlpFileOstreamBackend() override {}
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes

warning: class 'OtlpFileOstreamBackend' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

{
public:
LongSumAggregation(bool is_monotonic);
LongSumAggregation(SumPointData &&);
Copy link
Member Author

Choose a reason for hiding this comment

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

SumPointData is trivially-copyable and std::move has no effect.

@dbarker dbarker marked this pull request as ready for review June 24, 2025 03:58
@dbarker dbarker requested a review from a team as a code owner June 24, 2025 03:58
{
LastValuePointData merge_data = nostd::get<LastValuePointData>(ToPoint());
return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(merge_data)));
return std::unique_ptr<Aggregation>(new LongLastValueAggregation(merge_data));
Copy link
Member

Choose a reason for hiding this comment

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

I bellieve it's a mistake of clang. But it's OK to copy LastValuePointData because it's small and will not cost a lot.

Copy link
Member

@marcalff marcalff left a 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 cleanup.

@marcalff marcalff merged commit 016155f into open-telemetry:main Jun 24, 2025
70 checks passed
@dbarker dbarker deleted the fix_clang_tidy_warnings_part_1 branch July 10, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants