Replace Delay by RefreshSecond in Eureka
This commit is contained in:
parent
c4529820f2
commit
3a2b421566
5 changed files with 36 additions and 25 deletions
|
@ -434,6 +434,7 @@ func TestDo_globalConfiguration(t *testing.T) {
|
|||
},
|
||||
Endpoint: "eureka Endpoint",
|
||||
Delay: flaeg.Duration(30 * time.Second),
|
||||
RefreshSeconds: flaeg.Duration(30 * time.Second),
|
||||
}
|
||||
config.ECS = &ecs.Provider{
|
||||
BaseProvider: provider.BaseProvider{
|
||||
|
|
|
@ -166,7 +166,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
|
|||
|
||||
// default Eureka
|
||||
var defaultEureka eureka.Provider
|
||||
defaultEureka.Delay = flaeg.Duration(30 * time.Second)
|
||||
defaultEureka.RefreshSeconds = flaeg.Duration(30 * time.Second)
|
||||
|
||||
// default ServiceFabric
|
||||
var defaultServiceFabric servicefabric.Provider
|
||||
|
|
|
@ -201,6 +201,13 @@ func (gc *GlobalConfiguration) SetEffectiveConfiguration(configFile string) {
|
|||
gc.LifeCycle.GraceTimeOut = gc.GraceTimeOut
|
||||
}
|
||||
|
||||
if gc.Eureka != nil {
|
||||
if gc.Eureka.Delay != 0 {
|
||||
log.Warn("Delay has been deprecated -- please use RefreshSeconds")
|
||||
gc.Eureka.RefreshSeconds = gc.Eureka.Delay
|
||||
}
|
||||
}
|
||||
|
||||
if gc.Rancher != nil {
|
||||
// Ensure backwards compatibility for now
|
||||
if len(gc.Rancher.AccessKey) > 0 ||
|
||||
|
|
|
@ -21,7 +21,7 @@ endpoint = "http://my.eureka.server/eureka"
|
|||
# Optional
|
||||
# Default: 30s
|
||||
#
|
||||
delay = "1m"
|
||||
refreshSeconds = "1m"
|
||||
|
||||
# Override default configuration template.
|
||||
# For advanced users :)
|
||||
|
|
|
@ -18,7 +18,8 @@ import (
|
|||
type Provider struct {
|
||||
provider.BaseProvider `mapstructure:",squash" export:"true"`
|
||||
Endpoint string `description:"Eureka server endpoint"`
|
||||
Delay flaeg.Duration `description:"Override default configuration time between refresh" export:"true"`
|
||||
Delay flaeg.Duration `description:"Override default configuration time between refresh (Deprecated)" export:"true"` // Deprecated
|
||||
RefreshSeconds flaeg.Duration `description:"Override default configuration time between refresh" export:"true"`
|
||||
}
|
||||
|
||||
// Provide allows the eureka provider to provide configurations to traefik
|
||||
|
@ -46,27 +47,29 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
|||
Configuration: configuration,
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(time.Duration(p.Delay))
|
||||
safe.Go(func() {
|
||||
for t := range ticker.C {
|
||||
ticker := time.NewTicker(time.Duration(p.RefreshSeconds))
|
||||
pool.Go(func(stop chan bool) {
|
||||
for {
|
||||
select {
|
||||
case t := <-ticker.C:
|
||||
log.Debugf("Refreshing Provider %s", t.String())
|
||||
|
||||
applications, err := client.GetApplications()
|
||||
if err != nil {
|
||||
log.Errorf("Failed to retrieve applications, error: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
configuration, err := p.buildConfiguration(applications)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to refresh Provider configuration, error: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
configurationChan <- types.ConfigMessage{
|
||||
ProviderName: "eureka",
|
||||
Configuration: configuration,
|
||||
}
|
||||
case <-stop:
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue