[CODE HEALTH] Fix clang-tidy warnings in base2 exponential histogram aggregation#3997
Conversation
aad04da to
54475cb
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses clang-tidy warnings in the SDK’s base2 exponential histogram aggregation implementation and tightens CI’s clang-tidy warning thresholds accordingly.
Changes:
- Adjusts
GetScaleReductionarithmetic to avoidint32_toverflow in the bucket-span computation. - Makes scale decrements explicit where
scale_is adjusted byuint32_treductions (Downscale/Merge/Diff). - Lowers clang-tidy GitHub Actions
warning_limitvalues to reflect the reduced warning count and adds an Unreleased changelog entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc |
Arithmetic/casting changes intended to eliminate clang-tidy warnings in scale-reduction and scale-update paths. |
CHANGELOG.md |
Adds an Unreleased entry for this code health change. |
.github/workflows/clang-tidy.yaml |
Reduces clang-tidy warning limits in the CI matrix to “ratchet” the baseline downward. |
54475cb to
ccdaf85
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses clang-tidy findings in the SDK’s base2 exponential histogram aggregation by making integer arithmetic conversions explicit and preventing edge-case overflow in scale-reduction calculations, and then ratchets the CI warning limits accordingly.
Changes:
- Prevent potential
int32_toverflow inGetScaleReductionby widening the span computation/comparison toint64_t. - Make
scale_ -= <uint32_t>updates explicit by casting the RHS toint32_tinDownscale,Merge, andDiffto satisfy narrowing-conversion checks. - Lower clang-tidy CI
warning_limitthresholds to reflect the reduced warning count, and add a changelog entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc |
Adjusts arithmetic types/casts to eliminate clang-tidy warnings and avoid theoretical overflow in bucket-span calculations. |
CHANGELOG.md |
Adds an Unreleased entry documenting the code health fix. |
.github/workflows/clang-tidy.yaml |
Lowers warning limits for two matrix presets to match the new measured warning counts. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3997 +/- ##
==========================================
+ Coverage 90.18% 90.33% +0.16%
==========================================
Files 230 230
Lines 7299 7299
==========================================
+ Hits 6582 6593 +11
+ Misses 717 706 -11
🚀 New features to boost your workflow:
|
…aggregation Clear the seven clang-tidy warnings reported under open-telemetry#3979 in sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc: * GetScaleReduction (L35): widen the loop condition to int64_t so that end_index - start_index + 1 cannot overflow int32_t at max_scale_=20 with extreme-span histograms, and so bugprone-misplaced-widening-cast stops firing. * Downscale (L215): wrap point_data_.scale_ -= by with static_cast<int32_t>(point_data_.scale_ - by). * Merge (L327-329) and Diff (L412-413): same static_cast<int32_t> wrap on the five remaining int32_t -= uint32_t sites that land back into the scale_ int32_t field. Behaviour is preserved: all nine existing Base2Exponential* cases in sdk/test/metrics/aggregation_test.cc pass before and after the change. The MergeCountInvariant test in particular exercises the scale-reduction branch this PR touches. Decrement the clang-tidy warning_limit by 7 for both all-options-abiv1-preview and all-options-abiv2-preview matrix entries to ratchet the limit down to the new measured count. Resolves open-telemetry#3979. Part of open-telemetry#2053. Signed-off-by: thc1006 <[email protected]>
ccdaf85 to
d06a138
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses clang-tidy warnings in the SDK’s base2 exponential histogram aggregation implementation by making integer widening/narrowing explicit and overflow-safe, and then ratchets the clang-tidy CI warning limits to reflect the reduced warning count.
Changes:
- Adjust
GetScaleReduction’s span comparison to useint64_tarithmetic to avoidint32_toverflow and satisfybugprone-misplaced-widening-cast. - Make
scale_updates explicitly subtract in the signed domain (static_cast<int32_t>(...)) acrossDownscale,Merge, andDiffto resolve narrowing-conversion warnings. - Add a focused unit test to exercise the
Diff()downscaling path; update clang-tidy workflow warning limits and changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc |
Fixes clang-tidy warnings by widening span arithmetic and ensuring signed-domain subtraction for scale_. |
sdk/test/metrics/aggregation_test.cc |
Adds a test that forces Diff() to take the scale-reduction/downscale branch. |
CHANGELOG.md |
Records the code-health change in the Unreleased section. |
.github/workflows/clang-tidy.yaml |
Lowers clang-tidy warning_limit values to reflect the new measured warning count. |
dbarker
left a comment
There was a problem hiding this comment.
Looks reasonable. Thanks for the warning fixes and test case!
…aggregation (open-telemetry#3997) Signed-off-by: thc1006 <[email protected]>
Fixes #3979
Contributes to #2053
Changes
GetScaleReduction, widen the loop condition toint64_tso thatend_index - start_index + 1cannot overflowint32_tatmax_scale_ = 20with extreme-span histograms, and sobugprone-misplaced-widening-caststops firing.Downscale, wrap thepoint_data_.scale_ -= byassignment withstatic_cast<int32_t>(point_data_.scale_ - by)so theint32_t - uint32_tarithmetic result is explicitly narrowed back toint32_t.MergeandDiff, apply the samestatic_cast<int32_t>(...)wrap tothe five remaining
scale_ -= scale_reductionsites.clang-tidy.yamlwarning_limitby 7 for bothall-options-abiv1-previewandall-options-abiv2-previewmatrixentries to ratchet the limit down to the new measured count.
The arithmetic is behaviour-preserving: in the six
scale_ -= uint32_tsites,the existing code already relies on two's-complement wrap-around through the
unsigned intermediate, and
static_cast<int32_t>reproduces the same bitpattern. In
GetScaleReduction, theint64_twidening gives the samenumeric result on values that fit in
int32_tbut also handles thetheoretical edge case at
max_scale_ = 20where the bucket range can spannear
INT32_MAX.Existing
Base2ExponentialHistogramAggregation*cases insdk/test/metrics/aggregation_test.cccover all modified paths; inparticular
MergeCountInvariantusesmax_buckets_ = 5with five-bucketdelta cycles to deliberately exceed the limit and trigger the scale-reduction
branch in
Merge(which callsGetScaleReductionand then the threescale_ -= scale_reductionassignments). TheDiffpath is covered by thescale-mismatched calls in the other Base2 tests.
Fixes the following warnings:
opentelemetry-cpp/sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc (7 warnings)
bugprone-misplaced-widening-castcppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionsFor significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes