-
Notifications
You must be signed in to change notification settings - Fork 2.2k
store: support hedged requests #7860
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
Merged
GiedriusS
merged 12 commits into
thanos-io:main
from
milinddethe15:support-hedged-requests
Nov 14, 2024
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3520b2f
support hedged requests in store
milinddethe15 f6c255e
Merge branch 'main' into support-hedged-requests
milinddethe15 e6b2a73
hedged roundtripper with tdigest for dynamic delay
milinddethe15 825d456
Merge branch 'main' into support-hedged-requests
milinddethe15 59c5a80
refactor struct and fix lint
milinddethe15 2ac08a8
Improve hedging implementation
milinddethe15 2a3b2cc
Improved hedging implementation
milinddethe15 f29b99b
Merge branch 'main' into support-hedged-requests
milinddethe15 c3895b2
Update store doc
milinddethe15 2790ab9
Merge branch 'main' into support-hedged-requests
milinddethe15 29fb0e4
fix white space
milinddethe15 753db7f
add enabled field
milinddethe15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (c) The Thanos Authors. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| package exthttp | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/caio/go-tdigest" | ||
| "github.com/cristalhq/hedgedhttp" | ||
| ) | ||
|
|
||
| type CustomBucketConfig struct { | ||
| HedgingConfig HedgingConfig `yaml:"hedging_config"` | ||
| } | ||
|
|
||
| type HedgingConfig struct { | ||
| UpTo uint `yaml:"up_to"` | ||
| Quantile float64 `yaml:"quantile"` | ||
| } | ||
|
|
||
| var CustomBktConfig = CustomBucketConfig{ | ||
GiedriusS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| HedgingConfig: HedgingConfig{ | ||
| Quantile: 0.9, | ||
| }, | ||
| } | ||
|
|
||
| type hedgingRoundTripper struct { | ||
| Transport http.RoundTripper | ||
| TDigest *tdigest.TDigest | ||
| mu sync.RWMutex | ||
| } | ||
|
|
||
| func (hrt *hedgingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| start := time.Now() | ||
| resp, err := hrt.Transport.RoundTrip(req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| duration := float64(time.Since(start).Milliseconds()) | ||
| hrt.mu.Lock() | ||
| err = hrt.TDigest.Add(duration) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| hrt.mu.Unlock() | ||
| return resp, err | ||
| } | ||
|
|
||
| func (hrt *hedgingRoundTripper) nextFn() (int, time.Duration) { | ||
| hrt.mu.Lock() | ||
GiedriusS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| defer hrt.mu.Unlock() | ||
|
|
||
| delayMs := hrt.TDigest.Quantile(CustomBktConfig.HedgingConfig.Quantile) | ||
| delay := time.Duration(delayMs) * time.Millisecond | ||
| upto := int(CustomBktConfig.HedgingConfig.UpTo) | ||
| return upto, delay | ||
| } | ||
|
|
||
| func WrapHedgedRoundTripper(rt http.RoundTripper) http.RoundTripper { | ||
| td, err := tdigest.New() | ||
| if err != nil { | ||
| panic("Failed to initialize T-Digest") | ||
GiedriusS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| hrt := &hedgingRoundTripper{ | ||
| Transport: rt, | ||
| TDigest: td, | ||
| } | ||
| cfg := hedgedhttp.Config{ | ||
| Transport: hrt, | ||
| Upto: int(CustomBktConfig.HedgingConfig.UpTo), | ||
| Next: hrt.nextFn, | ||
| } | ||
| hedgedrt, err := hedgedhttp.New(cfg) | ||
| if err != nil { | ||
| panic("Failed to create hedged transport") | ||
GiedriusS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return hedgedrt | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.