Skip to content

Commit

Permalink
Add support for retrieving scheme from consul
Browse files Browse the repository at this point in the history
  • Loading branch information
geobeau committed Sep 10, 2020
1 parent a7bd7ea commit 37ec19a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cmd/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type esnode struct {
ip string
port int
cluster string
scheme string
}

func contains(a []string, x string) bool {
Expand Down Expand Up @@ -52,6 +53,18 @@ func clusterNameFromTags(serviceTags []string) string {
return ""
}

func schemeFromTags(serviceTags []string) string {
scheme := "http"
for _, tag := range serviceTags {
if tag == "https" {
scheme = tag
break
}
}

return scheme
}

func discoverNodesForService(serviceName string) ([]esnode, error) {
start := time.Now()

Expand Down Expand Up @@ -82,6 +95,7 @@ func discoverNodesForService(serviceName string) ([]esnode, error) {
name: svc.Node,
ip: svc.Address,
port: svc.ServicePort,
scheme: schemeFromTags(svc.ServiceTags),
cluster: clusterNameFromTags(svc.ServiceTags),
})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/probing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func probeElasticsearchNode(node *esnode, updateProbingPeriod time.Duration) err
Timeout: updateProbingPeriod - 2*time.Second,
}

probingURL := fmt.Sprintf("http://%v:%v/_cat/indices?v", node.ip, node.port)
probingURL := fmt.Sprintf("%v://%v:%v/_cat/indices?v", node.scheme, node.ip, node.port)
log.Debug("Start probing ", node.name)

start := time.Now()
Expand Down

0 comments on commit 37ec19a

Please sign in to comment.