Skip to content

aws_dynamodb_batcher: encapsulate throttling logic in pinClock - #4749

Open
Leward wants to merge 2 commits into
dynamo_batcher_impr_3from
dynamo_batcher_impr_4
Open

aws_dynamodb_batcher: encapsulate throttling logic in pinClock#4749
Leward wants to merge 2 commits into
dynamo_batcher_impr_3from
dynamo_batcher_impr_4

Conversation

@Leward

@Leward Leward commented Aug 31, 2026

Copy link
Copy Markdown

Introduced the pinClock struct to standardize throttling duration tracking and warning rate-limiting for global and per-shard logic. Updated related tests accordingly.

Introduced the `pinClock` struct to standardize throttling duration tracking and warning rate-limiting for global and per-shard logic. Updated related tests accordingly.
Comment on lines +614 to +633
at: now.Add(5*time.Minute - time.Second),
wantSince: 5*time.Minute - time.Second,
wantWarn: false,
},
{
name: "check at warn threshold triggers warning",
at: now.Add(5 * time.Minute),
wantSince: 5 * time.Minute,
wantWarn: true,
},
{
name: "immediate check within interval is rate-limited",
at: now.Add(5*time.Minute + time.Second),
wantSince: 5*time.Minute + time.Second,
wantWarn: false,
},
{
name: "check after interval triggers next warning",
at: now.Add(10 * time.Minute),
wantSince: 10 * time.Minute,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The new table hardcodes 5 * time.Minute / 10 * time.Minute for the warn threshold and the rate-limit interval instead of deriving them from the package constants throttlePinWarnAfter and throttlePinWarnInterval (batcher.go#L29-L32), which the neighbouring tests in this same file already use (batcher_test.go#L676-L678).

This violates the project Go style rule in CLAUDE.mdgodev Magic Numbers: "Name all numeric constants. Every literal number in logic must have a clear meaning through a named constant or variable."

It also makes the test silently stop asserting what it claims: if throttlePinWarnAfter is lowered to, say, 2 minutes, the "check before warn threshold returns duration without warning" case at now+4m59s would then be past the threshold and the case would no longer be testing the sub-threshold path (it would fail or pass for the wrong reason depending on the interval).

Suggested fix: express the at/wantSince values in terms of throttlePinWarnAfter and throttlePinWarnInterval (e.g. throttlePinWarnAfter - time.Second, throttlePinWarnAfter, throttlePinWarnAfter + throttlePinWarnInterval) so the table tracks the constants.

@Leward
Leward requested a review from squiidz August 31, 2026 19:47
}

// check records the start of a throttling event or checks if a warning is due.
// Returns the total duration spent continuously throttled and whether a log warning should be emitted.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Godoc line exceeds the 80-character wrap limit (minor)

This line is ~103 characters. The project Go patterns (.claude/agents/godev.md, Documentation section) state: "Godoc must wrap at 80 characters per line." Every other comment block in this file wraps at ~75 columns, including the new pinClock field docs directly above.

Suggested fix: re-wrap the // Returns the total duration… sentence across two lines so it stays under 80 columns.

Context:

// check records the start of a throttling event or checks if a warning is due.
// Returns the total duration spent continuously throttled and whether a log warning should be emitted.
func (c *pinClock) check(now time.Time) (since time.Duration, shouldWarn bool) {

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.

1 participant