Skip to content

fix(sdk-metrics): repair ExponentialHistogram tests#6565

Merged
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
embrace-io:overbalance/expose-test-bugs
Apr 8, 2026
Merged

fix(sdk-metrics): repair ExponentialHistogram tests#6565
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
embrace-io:overbalance/expose-test-bugs

Conversation

@overbalance
Copy link
Copy Markdown
Contributor

@overbalance overbalance commented Apr 7, 2026

Summary

Fixes several bugs in the ExponentialHistogramAccumulation test suite. Two test cases were defined inside the body of another it() block, which Mocha silently ignores, making them dead code:

  • handles permutations of [1, 1/2, 1/4] with maxSize: 2
  • handles ascending sequences

These tests have been moved to the correct describe('record', ...) scope so they actually run. Once exposed, four bugs surfaced:

  1. maxFill was reset instead of tracked. Every non-zero bucket reset maxFill to 0 instead of recording the index:

    - maxFill = 0;
    + maxFill = i;
  2. maxFill >= maxSize / 2 fails for some parameter combos. After downscaling, positive.length can be less than maxSize (e.g., 2 buckets when maxSize=3). The midpoint check should compare against the actual bucket array length, not the max capacity:

    - assert.ok(maxFill >= maxSize / 2);
    + assert.ok(maxFill >= accumulation.positive.length / 2);
  3. Count assertions only check an upper bound. We record exactly maxSize + 1 values (all positive, no NaN), so both totalCount and accumulation.count must be exactly that:

    - assert.ok(maxSize + 1 >= totalCount);
    - assert.ok(maxSize + 1 >= accumulation.count);
    + assert.strictEqual(totalCount, maxSize + 1);
    + assert.strictEqual(accumulation.count, maxSize + 1);
  4. Sum assertion only checks one direction. The manual sum and accumulation.sum add the same values in the same order, so they are bit-identical:

    - assert.ok(sum >= accumulation.sum);
    + assert.strictEqual(sum, accumulation.sum);

Test plan

  • handles ascending sequences passes across all parameter combinations (maxSize in [3,4,6,9], offset in [-5..5], initScale in [0,4], step in [maxSize..4*maxSize))
  • handles permutations of [1, 1/2, 1/4] with maxSize: 2 passes
  • All 30 ExponentialHistogram tests pass

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.75%. Comparing base (d583a22) to head (fc365dc).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6565   +/-   ##
=======================================
  Coverage   95.75%   95.75%           
=======================================
  Files         371      371           
  Lines       12514    12514           
  Branches     2962     2962           
=======================================
  Hits        11983    11983           
  Misses        531      531           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

overbalance added a commit to embrace-io/opentelemetry-js that referenced this pull request Apr 7, 2026
@overbalance overbalance force-pushed the overbalance/expose-test-bugs branch from 75db0ae to 354ca5d Compare April 7, 2026 05:17
@overbalance overbalance changed the title fix(sdk-metrics): fix bugs in ExponentialHistogram tests fix(sdk-metrics): repair ExponentialHistogram tests Apr 7, 2026
@overbalance overbalance marked this pull request as ready for review April 7, 2026 05:36
@overbalance overbalance requested a review from a team as a code owner April 7, 2026 05:36
Copy link
Copy Markdown
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

Wow great catch. What were you working on where you noticed that?

@pichlermarc pichlermarc added this pull request to the merge queue Apr 8, 2026
Merged via the queue into open-telemetry:main with commit cafaf08 Apr 8, 2026
27 checks passed
@overbalance overbalance deleted the overbalance/expose-test-bugs branch April 8, 2026 15:53
@overbalance
Copy link
Copy Markdown
Contributor Author

@dyladan On my monster mocha -> vitest PR

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