-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
discovery: use thanos resolver for endpoint groups #7565
Merged
MichaHoffmann
merged 1 commit into
main
from
mhoffmann-use-thanos-resolver-for-endpoint-groups
Jul 31, 2024
Merged
Changes from all commits
Commits
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 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 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 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,97 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package dns | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"time" | ||
|
||
grpcresolver "google.golang.org/grpc/resolver" | ||
) | ||
|
||
var ( | ||
_ grpcresolver.Builder = &builder{} | ||
_ grpcresolver.Resolver = &resolver{} | ||
) | ||
|
||
type builder struct { | ||
resolveInterval time.Duration | ||
provider *Provider | ||
} | ||
|
||
func RegisterGRPCResolver(provider *Provider, interval time.Duration) { | ||
grpcresolver.Register(&builder{ | ||
resolveInterval: interval, | ||
provider: provider, | ||
}) | ||
} | ||
|
||
func (b *builder) Scheme() string { return "thanos" } | ||
|
||
func (b *builder) Build(t grpcresolver.Target, cc grpcresolver.ClientConn, _ grpcresolver.BuildOptions) (grpcresolver.Resolver, error) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
r := &resolver{ | ||
provider: b.provider, | ||
target: t.Endpoint(), | ||
ctx: ctx, | ||
cancel: cancel, | ||
cc: cc, | ||
interval: b.resolveInterval, | ||
} | ||
r.wg.Add(1) | ||
go r.run() | ||
|
||
return r, nil | ||
} | ||
|
||
type resolver struct { | ||
provider *Provider | ||
|
||
target string | ||
ctx context.Context | ||
cancel context.CancelFunc | ||
cc grpcresolver.ClientConn | ||
interval time.Duration | ||
|
||
wg sync.WaitGroup | ||
} | ||
|
||
func (r *resolver) Close() { | ||
r.cancel() | ||
r.wg.Wait() | ||
} | ||
|
||
func (r *resolver) ResolveNow(_ grpcresolver.ResolveNowOptions) {} | ||
MichaHoffmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func (r *resolver) resolve() error { | ||
ctx, cancel := context.WithTimeout(r.ctx, r.interval) | ||
defer cancel() | ||
return r.provider.Resolve(ctx, []string{r.target}) | ||
} | ||
|
||
func (r *resolver) addresses() []string { | ||
return r.provider.AddressesForHost(r.target) | ||
} | ||
|
||
func (r *resolver) run() { | ||
defer r.wg.Done() | ||
for { | ||
if err := r.resolve(); err != nil { | ||
r.cc.ReportError(err) | ||
} else { | ||
state := grpcresolver.State{} | ||
for _, addr := range r.addresses() { | ||
raddr := grpcresolver.Address{Addr: addr} | ||
state.Addresses = append(state.Addresses, raddr) | ||
} | ||
_ = r.cc.UpdateState(state) | ||
} | ||
select { | ||
case <-r.ctx.Done(): | ||
return | ||
case <-time.After(r.interval): | ||
} | ||
} | ||
} |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is a breaking change; its so that people can chose to keep previous behavior by adding "dns:///" prefix or opt into thanos resolver by adding "thanos:///" prefix; alternatively we could snoop if thanos:/// is added and if not add dns:/// or just add "thanos:///" by default, in theory it should be not noticeable mostly. I like it better to state the resolver explicitely here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the main difference between the Thanos DNS resolver and the default DNS resolver we are using?
Trying to understand if it is a big difference. If it is, then I think the detection is needed and if no prefix is added we can still default to
dns://
. If there is no big difference I think I am fine either wayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thanos one understands our "dnssrv+" stuff while the dns one does not. Otherwise it should be roughly the same.