Skip to content

Commit d214741

Browse files
author
Damian Turczyński
authored
Merge pull request #65 from semyonslepov/master
Make server application context variable for DNS discovery
2 parents b8c9783 + ac72d73 commit d214741

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type eureka struct {
3434
ServerDNSName string // default ""
3535
ServiceUrls []string // default []
3636
ServerPort int // default 7001
37+
ServerURLBase string // default "eureka/v2"
3738
PollIntervalSeconds int // default 30
3839
EnableDelta bool // TODO: Support querying for deltas
3940
PreferSameZone bool // default false
@@ -67,4 +68,7 @@ func (c *Config) fillDefaults() {
6768
if c.Eureka.PollIntervalSeconds == 0 {
6869
c.Eureka.PollIntervalSeconds = 30
6970
}
71+
if len(c.Eureka.ServerURLBase) == 0 {
72+
c.Eureka.ServerURLBase = "eureka/v2"
73+
}
7074
}

connection.go

Lines changed: 2 additions & 1 deletion
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.ServerURLBase)
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.ServerURLBase = conf.Eureka.ServerURLBase
7172
}
7273
return c
7374
}

dns_discover.go

Lines changed: 2 additions & 2 deletions
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, urlBase 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, urlBase))
3939
}
4040
}
4141
return

dns_discover_test.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var EurekaURLSlugs = map[string]string{
1818
type EurekaConnection struct {
1919
ServiceUrls []string
2020
ServicePort int
21+
ServerURLBase string
2122
Timeout time.Duration
2223
PollInterval time.Duration
2324
PreferSameZone bool

0 commit comments

Comments
 (0)