Skip to content

Commit f085b6b

Browse files
author
semyon-slepov
committed
Make context variable for DNS discovery
1 parent b8c9783 commit f085b6b

5 files changed

+10
-4
lines changed

config.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type eureka struct {
3939
PreferSameZone bool // default false
4040
RegisterWithEureka bool // default false
4141
Retries int // default 3
42+
ServerContext string // default "eureka/v2"
4243
}
4344

4445
// ReadConfig from a file location. Minimal error handling. Just bails and passes up
@@ -67,4 +68,7 @@ func (c *Config) fillDefaults() {
6768
if c.Eureka.PollIntervalSeconds == 0 {
6869
c.Eureka.PollIntervalSeconds = 30
6970
}
71+
if c.Eureka.ServerContext == "" {
72+
c.Eureka.ServerContext = "eureka/v2"
73+
}
7074
}

connection.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (e *EurekaConnection) SelectServiceURL() string {
2020
e.discoveryTtl = make(chan struct{}, 1)
2121
}
2222
if e.DNSDiscovery && len(e.discoveryTtl) == 0 {
23-
servers, ttl, err := discoverDNS(e.DiscoveryZone, e.ServicePort)
23+
servers, ttl, err := discoverDNS(e.DiscoveryZone, e.ServicePort, e.ServerContext)
2424
if err != nil {
2525
return choice(e.ServiceUrls)
2626
}
@@ -68,6 +68,7 @@ func NewConnFromConfig(conf Config) (c EurekaConnection) {
6868
log.Warning("UseDNSForServiceUrls is an experimental option")
6969
c.DNSDiscovery = true
7070
c.DiscoveryZone = conf.Eureka.DNSDiscoveryZone
71+
c.ServerContext = conf.Eureka.ServerContext
7172
}
7273
return c
7374
}

dns_discover.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const azURL = "http://169.254.169.254/latest/meta-data/placement/availability-zo
1414

1515
var ErrNotInAWS = fmt.Errorf("Not in AWS")
1616

17-
func discoverDNS(domain string, port int) (servers []string, ttl time.Duration, err error) {
17+
func discoverDNS(domain string, port int, context string) (servers []string, ttl time.Duration, err error) {
1818
r, _ := region()
1919

2020
// all DNS queries must use the FQDN
@@ -35,7 +35,7 @@ func discoverDNS(domain string, port int) (servers []string, ttl time.Duration,
3535
}
3636
for _, instance := range instances {
3737
// format the service URL
38-
servers = append(servers, fmt.Sprintf("http://%s:%d/eureka/v2", instance, port))
38+
servers = append(servers, fmt.Sprintf("http://%s:%d/%s", instance, port, context))
3939
}
4040
}
4141
return

dns_discover_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestGetNetflixTestDomain(t *testing.T) {
4646
})
4747
})
4848
Convey("Autodiscover discoverytest.netflix.net.", t, func() {
49-
servers, ttl, err := discoverDNS("discoverytest.netflix.net", 7001)
49+
servers, ttl, err := discoverDNS("discoverytest.netflix.net", 7001, "")
5050
So(ttl, ShouldEqual, 60*time.Second)
5151
So(err, ShouldBeNil)
5252
So(len(servers), ShouldEqual, 6)

struct.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type EurekaConnection struct {
2525
DNSDiscovery bool
2626
DiscoveryZone string
2727
discoveryTtl chan struct{}
28+
ServerContext string
2829
UseJson bool
2930
}
3031

0 commit comments

Comments
 (0)