Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 65 by accepting a list of LISTENER_ADDRESS separated by comma #70

Merged
merged 1 commit into from
May 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,51 +197,55 @@ func (s *serve) RemoveNodeHandler(w http.ResponseWriter, req *http.Request) {

func (s *serve) InitialConfig() error {
if len(os.Getenv("LISTENER_ADDRESS")) > 0 {
logPrintf("Requesting services from Docker Flow Swarm Listener")
addr := os.Getenv("LISTENER_ADDRESS")
if !strings.HasPrefix(addr, "http") {
addr = fmt.Sprintf("http://%s:8080", addr)
}

addr = fmt.Sprintf("%s/v1/docker-flow-swarm-listener/get-services", addr)
timeout := time.Duration(listenerTimeout)
client := http.Client{Timeout: timeout}
resp, err := client.Get(addr)
if err != nil {
return err
}
body, _ := ioutil.ReadAll(resp.Body)
logPrintf("Processing: %s", string(body))
data := []map[string]string{}
json.Unmarshal(body, &data)
for _, row := range data {
if scrape, err := s.getScrapeFromMap(row); err == nil {
s.scrapes[scrape.ServiceName] = scrape
addrs := strings.Split(os.Getenv("LISTENER_ADDRESS"), ",")
for _, addr := range addrs {
addr = strings.TrimSpace(addr)

if !strings.HasPrefix(addr, "http") {
addr = fmt.Sprintf("http://%s:8080", addr)
}
if alert, err := s.getAlertFromMap(row, ""); err == nil {
s.alerts[alert.AlertNameFormatted] = alert

logPrintf("Requesting services from %s", addr)

addr = fmt.Sprintf("%s/v1/docker-flow-swarm-listener/get-services", addr)
timeout := time.Duration(listenerTimeout)
client := http.Client{Timeout: timeout}
resp, err := client.Get(addr)
if err != nil {
return err
}
for i := 1; i <= 10; i++ {
suffix := fmt.Sprintf(".%d", i)
if alert, err := s.getAlertFromMap(row, suffix); err == nil {
body, _ := ioutil.ReadAll(resp.Body)
logPrintf("Processing: %s", string(body))
data := []map[string]string{}
json.Unmarshal(body, &data)
for _, row := range data {
if scrape, err := s.getScrapeFromMap(row); err == nil {
s.scrapes[scrape.ServiceName] = scrape
}
if alert, err := s.getAlertFromMap(row, ""); err == nil {
s.alerts[alert.AlertNameFormatted] = alert
} else {
break
}
for i := 1; i <= 10; i++ {
suffix := fmt.Sprintf(".%d", i)
if alert, err := s.getAlertFromMap(row, suffix); err == nil {
s.alerts[alert.AlertNameFormatted] = alert
} else {
break
}
}
}
}

scrapeVariablesFromEnv := s.getScrapeVariablesFromEnv()
if len(scrapeVariablesFromEnv) > 0 {
scrape, err := s.parseScrapeFromEnvMap(scrapeVariablesFromEnv)
if err != nil {
return err
}
for _, row := range scrape {
s.scrapes[row.ServiceName] = row
scrapeVariablesFromEnv := s.getScrapeVariablesFromEnv()
if len(scrapeVariablesFromEnv) > 0 {
scrape, err := s.parseScrapeFromEnvMap(scrapeVariablesFromEnv)
if err != nil {
return err
}
for _, row := range scrape {
s.scrapes[row.ServiceName] = row
}
}
}

}

// Get Nodes
Expand Down