-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(v2): add metastore dns discovery (#3606)
- Loading branch information
1 parent
fff4231
commit 81ab235
Showing
10 changed files
with
126 additions
and
30 deletions.
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
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,76 @@ | ||
package discovery | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/grafana/dskit/dns" | ||
"github.com/hashicorp/raft" | ||
"sync" | ||
) | ||
|
||
type DNSDiscovery struct { | ||
logger log.Logger | ||
addr string | ||
provider *dns.Provider | ||
m sync.Mutex | ||
upd Updates | ||
resolved []Server | ||
} | ||
|
||
func NewDNSDiscovery(l log.Logger, addr string, p *dns.Provider) *DNSDiscovery { | ||
d := &DNSDiscovery{ | ||
logger: log.With(l, "addr", addr, "component", "dns-discovery"), | ||
addr: addr, | ||
provider: p, | ||
} | ||
|
||
return d | ||
} | ||
|
||
func (d *DNSDiscovery) Subscribe(updates Updates) { | ||
d.m.Lock() | ||
d.upd = updates | ||
d.m.Unlock() | ||
d.resolve() | ||
} | ||
|
||
func (d *DNSDiscovery) Rediscover() { | ||
d.resolve() | ||
} | ||
|
||
func (d *DNSDiscovery) Close() { | ||
|
||
} | ||
|
||
func (d *DNSDiscovery) resolve() { | ||
err := d.provider.Resolve(context.Background(), []string{d.addr}) | ||
if err != nil { | ||
level.Error(d.logger).Log("msg", "failed to resolve DNS", "addr", d.addr, "err", err) | ||
return | ||
} | ||
addrs := d.provider.Addresses() | ||
if len(addrs) == 0 { | ||
level.Error(d.logger).Log("msg", "failed to resolve DNS", "addr", d.addr, "err", "no addresses") | ||
return | ||
} | ||
level.Debug(d.logger).Log("msg", "resolved DNS", "addr", d.addr, "addrs", fmt.Sprintf("%+v", addrs)) | ||
|
||
servers := make([]Server, 0, len(addrs)) | ||
for _, peer := range addrs { | ||
servers = append(servers, Server{ | ||
Raft: raft.Server{ | ||
Suffrage: raft.Voter, | ||
ID: raft.ServerID(peer), | ||
Address: raft.ServerAddress(peer), | ||
}, | ||
}) | ||
} | ||
d.m.Lock() | ||
defer d.m.Unlock() | ||
d.resolved = servers | ||
if d.upd != nil { | ||
d.upd.Servers(servers) | ||
} | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.