Logging
This commit is contained in:
parent
ee13d570d8
commit
85e1af878a
8 changed files with 288 additions and 47 deletions
24
marathon.go
24
marathon.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
import (
|
||||
"github.com/gambol99/go-marathon"
|
||||
"log"
|
||||
"github.com/leekchan/gtf"
|
||||
"bytes"
|
||||
"github.com/BurntSushi/toml"
|
||||
|
@ -47,24 +46,25 @@ var MarathonFuncMap = template.FuncMap{
|
|||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
}
|
||||
|
||||
func (provider *MarathonProvider) Provide(configurationChan chan <- *Configuration) {
|
||||
config := marathon.NewDefaultConfig()
|
||||
config.URL = provider.Endpoint
|
||||
config.EventsInterface = provider.NetworkInterface
|
||||
if client, err := marathon.NewClient(config); err != nil {
|
||||
log.Println("Failed to create a client for marathon, error: %s", err)
|
||||
log.Error("Failed to create a client for marathon, error: %s", err)
|
||||
return
|
||||
} else {
|
||||
provider.marathonClient = client
|
||||
update := make(marathon.EventsChannel, 5)
|
||||
if (provider.Watch) {
|
||||
if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil {
|
||||
log.Println("Failed to register for subscriptions, %s", err)
|
||||
log.Error("Failed to register for subscriptions, %s", err)
|
||||
} else {
|
||||
go func() {
|
||||
for {
|
||||
event := <-update
|
||||
log.Println("Marathon event receveived", event)
|
||||
log.Debug("Marathon event receveived", event)
|
||||
configuration := provider.loadMarathonConfig()
|
||||
if (configuration != nil) {
|
||||
configurationChan <- configuration
|
||||
|
@ -84,30 +84,30 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
|||
|
||||
applications, err := provider.marathonClient.Applications(nil)
|
||||
if (err != nil) {
|
||||
log.Println("Failed to create a client for marathon, error: %s", err)
|
||||
log.Error("Failed to create a client for marathon, error: %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
tasks, err := provider.marathonClient.AllTasks()
|
||||
if (err != nil) {
|
||||
log.Println("Failed to create a client for marathon, error: %s", err)
|
||||
log.Error("Failed to create a client for marathon, error: %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
//filter tasks
|
||||
filteredTasks := fun.Filter(func(task marathon.Task) bool {
|
||||
if (len(task.Ports) == 0) {
|
||||
log.Println("Filtering marathon task without port", task.AppID)
|
||||
log.Debug("Filtering marathon task without port", task.AppID)
|
||||
return false
|
||||
}
|
||||
application := getApplication(task, applications.Apps)
|
||||
_, err := strconv.Atoi(application.Labels["traefik.port"])
|
||||
if (len(application.Ports) > 1 && err != nil) {
|
||||
log.Println("Filtering marathon task with more than 1 port and no traefik.port label", task.AppID)
|
||||
log.Debug("Filtering marathon task with more than 1 port and no traefik.port label", task.AppID)
|
||||
return false
|
||||
}
|
||||
if (application.Labels["traefik.enable"] == "false") {
|
||||
log.Println("Filtering disabled marathon task", task.AppID)
|
||||
log.Debug("Filtering disabled marathon task", task.AppID)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -140,7 +140,7 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
|||
gtf.Inject(MarathonFuncMap)
|
||||
tmpl, err := template.New(provider.Filename).Funcs(MarathonFuncMap).ParseFiles(provider.Filename)
|
||||
if err != nil {
|
||||
log.Println("Error reading file:", err)
|
||||
log.Error("Error reading file:", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -148,12 +148,12 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
|||
|
||||
err = tmpl.Execute(&buffer, templateObjects)
|
||||
if err != nil {
|
||||
log.Println("Error with docker template:", err)
|
||||
log.Error("Error with docker template:", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := toml.Decode(buffer.String(), configuration); err != nil {
|
||||
log.Println("Error creating marathon configuration:", err)
|
||||
log.Error("Error creating marathon configuration:", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue