Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
ignore exposed ports during explicit discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Höglin committed Jan 28, 2020
1 parent a378fe4 commit 4e85bad
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ type scrapeTask struct {

// collectPorts builds a map of ports collected from container exposed ports and/or from ports defined
// as container labels
func collectPorts(task swarm.Task, serviceIDMap map[string]swarm.Service) map[int]struct{} {
func collectPorts(task swarm.Task, serviceIDMap map[string]swarm.Service, discoveryType string) map[int]struct{} {

ports := make(map[int]struct{})

Expand All @@ -180,9 +180,13 @@ func collectPorts(task swarm.Task, serviceIDMap map[string]swarm.Service) map[in
}
}

// collects exposed ports
for _, port := range serviceIDMap[task.ServiceID].Spec.EndpointSpec.Ports {
ports[int(port.TargetPort)] = struct{}{}
// collects exposed ports, but only if we use implicit discovery
if discoveryType == implicit {
for _, port := range serviceIDMap[task.ServiceID].Spec.EndpointSpec.Ports {
ports[int(port.TargetPort)] = struct{}{}
}
} else {
logger.Debugf("Exposed ports on Service %s ignored by Prometheus", task.ServiceID)
}

return ports
Expand Down Expand Up @@ -270,7 +274,7 @@ func discoverSwarm(prometheusContainerID string, outputFile string, discoveryTyp
}
}

ports := collectPorts(task, serviceIDMap)
ports := collectPorts(task, serviceIDMap, discoveryType)
containerIPs, taskNetworks := collectIPs(task)
var taskEndpoints []string

Expand Down

0 comments on commit 4e85bad

Please sign in to comment.