Skip to content

feat(http): add RetryStrategy and context-driven configuration#317

Merged
moshloop merged 1 commit into
masterfrom
feat/har-capture-and-logger-improvements
May 31, 2026
Merged

feat(http): add RetryStrategy and context-driven configuration#317
moshloop merged 1 commit into
masterfrom
feat/har-capture-and-logger-improvements

Conversation

@moshloop

Copy link
Copy Markdown
Member

What

  • Introduce RetryStrategy callback-based retry mechanism with RetryOnStatus helper
  • Add WithContext and WithLogger methods for context-driven client configuration
  • Implement metadataHARMiddleware for low-cost HAR capture (headers/timing only)
  • Add WriteHARFile to serialize HAR entries to disk
  • Add traceConfigForLevel to derive trace config from logger verbosity levels

Why

  • Supersede legacy exponential-backoff RetryConfig loop with more flexible strategy pattern
  • Enable per-feature HTTP tracing and HAR collection via context objects
  • Deduplicate TraceToStdout calls by merging configs into single middleware
  • Automatically enable tracing from -vvv/-vvvv flags

Notes

  • Breaking change: Client.traceMW and related internals now exposed; existing Trace() and TraceToStdout() calls continue to work but may see different middleware stacking behavior
  • Requires CommonsHTTPContext interface implementation for context objects

Introduce RetryStrategy, a callback-based retry mechanism that supersedes the legacy exponential-backoff RetryConfig loop. The strategy owns the attempt cap and retry decision for each HTTP attempt, supporting custom logic like Retry-After header parsing via the new RetryOnStatus helper.

Add WithContext and WithLogger methods to configure clients from context objects, enabling per-feature HTTP tracing and HAR collection. TraceToStdout now deduplicates multiple calls by merging configs into a single installed middleware instead of stacking.

Add CommonsHTTPContext interface for context objects to provide logger, trace config, and HAR collector. Implement metadataHARMiddleware for low-cost HAR capture (headers/timing only, no bodies). Add WriteHARFile to serialize HAR entries to disk.

Add traceConfigForLevel to derive trace config from logger verbosity levels (Trace1 for headers, Trace2 for bodies), making -vvv/-vvvv flags automatically enable tracing.

Breaking change: Client.traceMW and related internals are now exposed for deduplication logic; existing code using Trace() or TraceToStdout() continues to work but may see different middleware stacking behavior.

Refs: HAR collection, context-driven configuration, improved retry control
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@moshloop, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 43 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9dacfb41-3588-46c1-ac4e-a37ac1e818e1

📥 Commits

Reviewing files that changed from the base of the PR and between 3020004 and d09d72a.

📒 Files selected for processing (6)
  • .gitignore
  • http/client.go
  • http/request.go
  • http/retry_strategy.go
  • http/retry_strategy_test.go
  • http/with_context_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/har-capture-and-logger-improvements
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/har-capture-and-logger-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

Gavel summary

Source Pass Fail Skip Duration
collections 49 0 0 3.2s
files 41 0 0 130ms
github.com/flanksource/commons/certs 4 0 0 320ms
github.com/flanksource/commons/cmd/hx 8 0 0 -
github.com/flanksource/commons/cmd/hx/parse 26 0 0 -
github.com/flanksource/commons/collections/syncmap 10 0 0 -
github.com/flanksource/commons/context 1 0 0 -
github.com/flanksource/commons/duration 2 0 0 -
github.com/flanksource/commons/files 16 0 0 -
github.com/flanksource/commons/har 23 0 0 -
github.com/flanksource/commons/hash 13 0 0 -
github.com/flanksource/commons/http 74 0 2 53.7s
github.com/flanksource/commons/logger 33 0 0 10ms
github.com/flanksource/commons/logger/httpretty/internal/color 15 0 0 -
github.com/flanksource/commons/logger/httpretty/internal/header 1 0 0 -
github.com/flanksource/commons/lookup 7 0 0 20ms
github.com/flanksource/commons/test 5 0 1 110ms
github.com/flanksource/commons/text 1 0 0 -
github.com/flanksource/commons/tokenizer 3 0 0 -
lint: betterleaks 0 0 1 -
lint: eslint 0 0 1 -
lint: golangci-lint 0 0 1 -
lint: jscpd 0 0 1 -
lint: markdownlint 0 0 1 -
lint: pyright 0 0 1 -
lint: ruff 0 0 1 -
lint: vale 0 0 1 -
logger 41 0 0 1ms
set 7 0 0 656.897µs

Totals: 380 passed · 0 failed · 11 skipped · 57.5s

View full results

@moshloop moshloop merged commit ac5f628 into master May 31, 2026
7 of 8 checks passed
@moshloop moshloop deleted the feat/har-capture-and-logger-improvements branch May 31, 2026 10:57
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.52.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant