Skip to content

Conversation

@Sanchit2662
Copy link

@Sanchit2662 Sanchit2662 commented Feb 2, 2026

Summary

This PR fixes silent error handling in the Badger-based sampling store.

In internal/storage/v1/badger/samplingstore/storage.go, the write methods InsertThroughput() and InsertProbabilitiesAndQPS() capture errors from Badger transactions but always return nil. This causes write failures to be silently ignored.

As a result, components relying on persisted sampling data (such as adaptive sampling) may assume writes succeeded even when Badger rejected them due to disk pressure, corruption, or transaction failures.

Currently, transaction errors are captured but discarded:

err = s.store.Update(...)
return nil // error not propagated

This hides storage failures from callers and reduces visibility into persistence issues.


Fix

This PR ensures transaction errors are returned to callers instead of being dropped.

Changes:

  • InsertThroughput() now returns the transaction error
  • InsertProbabilitiesAndQPS() now returns the transaction error

This aligns write behavior with expected error propagation and with patterns used in other storage backends.


Why This Matters

Prevents silent write failures
Improves reliability of adaptive sampling
Surfaces real storage issues to callers

The change is minimal and does not alter storage logic—only error propagation.


Verification

  • make fmt — passed
  • make lint — passed
  • go test ./internal/storage/v1/badger/... — all tests pass

Checklist

Signed-off-by: Sanchit2662 <sanchit2662@gmail.com>
@Sanchit2662 Sanchit2662 requested a review from a team as a code owner February 2, 2026 19:48
@dosubot dosubot bot added area/storage storage/badger Issues related to badger storage labels Feb 2, 2026
Copy link
Member

Choose a reason for hiding this comment

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

this would be cleaner

Suggested change
return s.store.Update(func(txn *badger.Txn) error {

Comment on lines 49 to 52
Copy link
Member

Choose a reason for hiding this comment

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

this is currently leaking into outer scope for no reason

Suggested change
if err := txn.SetEntry(entriesToStore[i]); err != nil {
return err
}

Copy link
Member

Choose a reason for hiding this comment

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

same comments as above

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.54%. Comparing base (823608a) to head (9b6334c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7965      +/-   ##
==========================================
- Coverage   95.57%   95.54%   -0.03%     
==========================================
  Files         316      316              
  Lines       16763    16763              
==========================================
- Hits        16021    16017       -4     
- Misses        579      582       +3     
- Partials      163      164       +1     
Flag Coverage Δ
badger_v1 9.16% <100.00%> (ø)
badger_v2 1.89% <0.00%> (ø)
cassandra-4.x-v1-manual 13.36% <0.00%> (ø)
cassandra-4.x-v2-auto 1.88% <0.00%> (ø)
cassandra-4.x-v2-manual 1.88% <0.00%> (ø)
cassandra-5.x-v1-manual 13.36% <0.00%> (ø)
cassandra-5.x-v2-auto 1.88% <0.00%> (ø)
cassandra-5.x-v2-manual 1.88% <0.00%> (ø)
clickhouse 1.97% <0.00%> (ø)
elasticsearch-6.x-v1 17.20% <0.00%> (ø)
elasticsearch-7.x-v1 17.23% <0.00%> (ø)
elasticsearch-8.x-v1 17.38% <0.00%> (ø)
elasticsearch-8.x-v2 1.89% <0.00%> (ø)
elasticsearch-9.x-v2 1.89% <0.00%> (ø)
grpc_v1 8.41% <0.00%> (ø)
grpc_v2 1.89% <0.00%> (ø)
kafka-3.x-v2 1.89% <0.00%> (ø)
memory_v2 1.89% <0.00%> (ø)
opensearch-1.x-v1 17.27% <0.00%> (ø)
opensearch-2.x-v1 17.27% <0.00%> (ø)
opensearch-2.x-v2 1.89% <0.00%> (ø)
opensearch-3.x-v2 1.89% <0.00%> (ø)
query 1.89% <0.00%> (ø)
tailsampling-processor 0.54% <0.00%> (ø)
unittests 94.23% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Signed-off-by: Sanchit2662 <sanchit2662@gmail.com>
@Sanchit2662
Copy link
Author

Hi @yurishkuro ,
Thanks for the review! I've addressed the feedback , simplified both methods to return s.store.Update(...) directly and scoped the err variable inline within the loop.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in the Badger sampling store where transaction errors were being silently discarded instead of being returned to callers. The methods InsertThroughput() and InsertProbabilitiesAndQPS() were capturing errors from Badger transactions but always returning nil, causing write failures to be invisible to components relying on persisted sampling data.

Changes:

  • Modified InsertThroughput() to return the transaction error instead of discarding it
  • Modified InsertProbabilitiesAndQPS() to return the transaction error instead of discarding it

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to 54
return s.store.Update(func(txn *badger.Txn) error {
for i := range entriesToStore {
err = txn.SetEntry(entriesToStore[i])
if err != nil {
if err := txn.SetEntry(entriesToStore[i]); err != nil {
return err
}
}

return nil
})
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The error propagation fix is correct, but there should be test coverage to verify that errors from s.store.Update() are actually returned to the caller. Consider adding a test that simulates a Badger transaction error (e.g., using a closed database or mocked error scenario) to ensure the error is properly propagated.

Copilot uses AI. Check for mistakes.
Comment on lines +108 to 115
return s.store.Update(func(txn *badger.Txn) error {
for i := range entriesToStore {
err = txn.SetEntry(entriesToStore[i])
if err != nil {
if err := txn.SetEntry(entriesToStore[i]); err != nil {
return err
}
}

return nil
})
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The error propagation fix is correct, but there should be test coverage to verify that errors from s.store.Update() are actually returned to the caller. Consider adding a test that simulates a Badger transaction error (e.g., using a closed database or mocked error scenario) to ensure the error is properly propagated.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants