Skip to content
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

Disable "taking" from reservoir if there is no capacity, regardless of borrow value #3684

Merged
merged 4 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108)

### Fixed

- Prevent taking from reservoir in AWS XRay Remote Sampler when there is zero capacity in `go.opentelemetry.io/contrib/samplers/aws/xray`. (#3684)

## [1.16.0-rc.2/0.41.0-rc.2/0.10.0-rc.2] - 2023-03-23

### Added
Expand Down
4 changes: 4 additions & 0 deletions samplers/aws/xray/internal/reservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (r *reservoir) take(now time.Time, borrowed bool, itemCost float64) bool {
r.mu.Lock()
defer r.mu.Unlock()

if r.capacity == 0 {
return false
}

if r.lastTick.IsZero() {
r.lastTick = now

Expand Down
24 changes: 24 additions & 0 deletions samplers/aws/xray/internal/reservoir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ func TestConsumeFromReservoir(t *testing.T) {
assert.Equal(t, r.quotaBalance, 7.0)
}

func TestZeroCapacityFailBorrow(t *testing.T) {
clock := &mockClock{
nowTime: 1500000000,
}

r := &reservoir{
quota: 0,
capacity: 0,
}

// start with no quota balance
assert.Equal(t, r.quotaBalance, 0.0)
// attempt to borrow from reservoir, and should fail since there is no capacity
assert.False(t, r.take(clock.now(), true, 1.0))

// increase the clock by 5
clock.nowTime = 1500000005

// validate there is still no quota balance
assert.Equal(t, r.quotaBalance, 0.0)
// again, attempt to borrow from reservoir, and should fail since there is no capacity
assert.False(t, r.take(clock.now(), true, 1.0))
}

func TestResetQuotaUsageRotation(t *testing.T) {
clock := &mockClock{
nowTime: 1500000000,
Expand Down
1 change: 1 addition & 0 deletions samplers/aws/xray/internal/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func TestConsumeFromReservoirSample(t *testing.T) {
RuleName: "r1",
},
reservoir: &reservoir{
capacity: 10,
quota: 10,
expiresAt: time.Unix(1500000060, 0),
},
Expand Down