add backoff to marathon provider

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-04-15 18:59:51 +02:00
parent 23d3c512c2
commit 36338b4928
No known key found for this signature in database
GPG key ID: D808B4C167352E59
4 changed files with 48 additions and 33 deletions

View file

@ -6,7 +6,7 @@ zk:
ZK_ID: 1 ZK_ID: 1
master: master:
image: mesosphere/mesos-master:0.26.0-0.2.145.ubuntu1404 image: mesosphere/mesos-master:0.28.1-2.0.20.ubuntu1404
net: host net: host
environment: environment:
MESOS_ZK: zk://127.0.0.1:2181/mesos MESOS_ZK: zk://127.0.0.1:2181/mesos
@ -17,7 +17,7 @@ master:
MESOS_WORK_DIR: /var/lib/mesos MESOS_WORK_DIR: /var/lib/mesos
slave: slave:
image: mesosphere/mesos-slave:0.26.0-0.2.145.ubuntu1404 image: mesosphere/mesos-slave:0.28.1-2.0.20.ubuntu1404
net: host net: host
pid: host pid: host
privileged: true privileged: true
@ -34,10 +34,19 @@ slave:
- /lib/x86_64-linux-gnu/libsystemd-journal.so.0:/lib/x86_64-linux-gnu/libsystemd-journal.so.0 - /lib/x86_64-linux-gnu/libsystemd-journal.so.0:/lib/x86_64-linux-gnu/libsystemd-journal.so.0
marathon: marathon:
image: mesosphere/marathon:v0.13.0 image: mesosphere/marathon:v1.1.1
net: host net: host
environment: environment:
MARATHON_MASTER: zk://127.0.0.1:2181/mesos MARATHON_MASTER: zk://127.0.0.1:2181/mesos
MARATHON_ZK: zk://127.0.0.1:2181/marathon MARATHON_ZK: zk://127.0.0.1:2181/marathon
MARATHON_HOSTNAME: 127.0.0.1 MARATHON_HOSTNAME: 127.0.0.1
command: --event_subscriber http_callback command: --event_subscriber http_callback
traefik:
image: traefik
command: -c /dev/null --web --logLevel=DEBUG --marathon --marathon.domain marathon.localhost --marathon.endpoint http://172.17.0.1:8080 --marathon.watch
ports:
- "8000:80"
- "8081:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock

View file

@ -1,12 +1,11 @@
traefik: traefik:
image: traefik image: traefik
command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG command: -c /dev/null --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
ports: ports:
- "80:80" - "80:80"
- "8080:8080" - "8080:8080"
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
whoami1: whoami1:
image: emilevauge/whoami image: emilevauge/whoami

View file

@ -26,6 +26,6 @@
"labels": { "labels": {
"traefik.weight": "1", "traefik.weight": "1",
"traefik.protocole": "http", "traefik.protocole": "http",
"traefik.frontend.rule" : "Headers:Host,test.localhost" "traefik.frontend.rule" : "Host:test.marathon.localhost"
} }
} }

View file

@ -10,10 +10,12 @@ import (
"crypto/tls" "crypto/tls"
"github.com/BurntSushi/ty/fun" "github.com/BurntSushi/ty/fun"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/cenkalti/backoff"
"github.com/containous/traefik/safe" "github.com/containous/traefik/safe"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
"github.com/gambol99/go-marathon" "github.com/gambol99/go-marathon"
"net/http" "net/http"
"time"
) )
// Marathon holds configuration of the Marathon provider. // Marathon holds configuration of the Marathon provider.
@ -41,29 +43,31 @@ type lightMarathonClient interface {
// Provide allows the provider to provide configurations to traefik // Provide allows the provider to provide configurations to traefik
// using the given configuration channel. // using the given configuration channel.
func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error { func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
config := marathon.NewDefaultConfig() operation := func() error {
config.URL = provider.Endpoint config := marathon.NewDefaultConfig()
config.EventsTransport = marathon.EventsTransportSSE config.URL = provider.Endpoint
if provider.Basic != nil { config.EventsTransport = marathon.EventsTransportSSE
config.HTTPBasicAuthUser = provider.Basic.HTTPBasicAuthUser if provider.Basic != nil {
config.HTTPBasicPassword = provider.Basic.HTTPBasicPassword config.HTTPBasicAuthUser = provider.Basic.HTTPBasicAuthUser
} config.HTTPBasicPassword = provider.Basic.HTTPBasicPassword
config.HTTPClient = &http.Client{ }
Transport: &http.Transport{ config.HTTPClient = &http.Client{
TLSClientConfig: provider.TLS, Transport: &http.Transport{
}, TLSClientConfig: provider.TLS,
} },
client, err := marathon.NewClient(config) }
if err != nil { client, err := marathon.NewClient(config)
log.Errorf("Failed to create a client for marathon, error: %s", err) if err != nil {
return err log.Errorf("Failed to create a client for marathon, error: %s", err)
} return err
provider.marathonClient = client }
update := make(marathon.EventsChannel, 5) provider.marathonClient = client
if provider.Watch { update := make(marathon.EventsChannel, 5)
if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil { if provider.Watch {
log.Errorf("Failed to register for events, %s", err) if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil {
} else { log.Errorf("Failed to register for events, %s", err)
return err
}
pool.Go(func(stop chan bool) { pool.Go(func(stop chan bool) {
for { for {
select { select {
@ -82,12 +86,15 @@ func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage,
} }
}) })
} }
return nil
} }
configuration := provider.loadMarathonConfig() notify := func(err error, time time.Duration) {
configurationChan <- types.ConfigMessage{ log.Errorf("Marathon connection error %+v, retrying in %s", err, time)
ProviderName: "marathon", }
Configuration: configuration, err := backoff.RetryNotify(operation, backoff.NewExponentialBackOff(), notify)
if err != nil {
log.Fatalf("Cannot connect to Marathon server %+v", err)
} }
return nil return nil
} }