Skip to content

Implement Distributed Deadline Propagation (Context-Aware Headers)#53

Merged
cinar merged 2 commits intomainfrom
feature/distributed-deadline-propagation
Apr 11, 2026
Merged

Implement Distributed Deadline Propagation (Context-Aware Headers)#53
cinar merged 2 commits intomainfrom
feature/distributed-deadline-propagation

Conversation

@cinar
Copy link
Copy Markdown
Owner

@cinar cinar commented Apr 11, 2026

Implement Distributed Deadline Propagation (Context-Aware Headers)

Overview

This PR implements Distributed Deadline Propagation as specified in issue #44. It adds mechanisms to propagate context deadlines to downstream services and provides early abort functionality for requests with insufficient remaining time.

Implementation Details

  • MinDeadlineThreshold: Added configuration to Config and Option to define a minimum threshold for starting an attempt.
  • Deadline Middleware: Implemented deadlineMiddleware that checks the remaining context time and returns context.DeadlineExceeded if below the threshold.
  • Header Injection: Added InjectDeadlineHeader in propagation.go with support for both standard integer milliseconds and gRPC-compatible timeout formatting.
  • Terminal Errors: Updated shouldRetry to treat context.DeadlineExceeded and context.Canceled as terminal errors.
  • Example: Added examples/deadline/main.go demonstrating the feature.

Verification

  • Added comprehensive unit tests in deadline_propagation_test.go covering early abort, dynamic recalculation, and header injection.
  • Verified all tests pass with >90% coverage in the core package.
  • Manually verified the behavior using the new example.

fixes #44

cinar added 2 commits April 11, 2026 08:34
This PR implements Distributed Deadline Propagation as specified in issue #44. It adds mechanisms to propagate context deadlines to downstream services and provides early abort functionality for requests with insufficient remaining time.

- **MinDeadlineThreshold**: Added configuration to `Config` and `Option` to define a minimum threshold for starting an attempt.
- **Deadline Middleware**: Implemented `deadlineMiddleware` that checks the remaining context time and returns `context.DeadlineExceeded` if below the threshold.
- **Header Injection**: Added `InjectDeadlineHeader` in `propagation.go` with support for both standard integer milliseconds and gRPC-compatible timeout formatting.
- **Terminal Errors**: Updated `shouldRetry` to treat `context.DeadlineExceeded` and `context.Canceled` as terminal errors.
- **Example**: Added `examples/deadline/main.go` demonstrating the feature.

- Added comprehensive unit tests in `deadline_propagation_test.go` covering early abort, dynamic recalculation, and header injection.
- Verified all tests pass with >90% coverage in the core package.
- Manually verified the behavior using the new example.

fixes #44
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.89%. Comparing base (55c53ad) to head (0526183).

Files with missing lines Patch % Lines
options.go 60.00% 1 Missing and 1 partial ⚠️
propagation.go 91.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   91.86%   91.89%   +0.03%     
==========================================
  Files          13       14       +1     
  Lines         897      938      +41     
==========================================
+ Hits          824      862      +38     
- Misses         45       46       +1     
- Partials       28       30       +2     

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

@cinar cinar merged commit 8c23e7e into main Apr 11, 2026
4 checks passed
@cinar cinar deleted the feature/distributed-deadline-propagation branch April 11, 2026 15:39
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.

Feature: Distributed Deadline Propagation (Context-Aware Headers)

2 participants