Skip to content

Commit

Permalink
Yet More Plumbing for multi-host setup.
Browse files Browse the repository at this point in the history
- Move peers from flags to args in the app
- Allow users to specify peers as IPs and hostname, both with and without ports
- Allos users to specify peers on ./scope launch, and plumb that through entrypoint.sh and run-app
  • Loading branch information
Tom Wilkie committed Jun 1, 2015
1 parent 2e8df4a commit a93f641
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
5 changes: 2 additions & 3 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

Expand All @@ -24,12 +23,12 @@ func main() {
var (
defaultProbes = []string{fmt.Sprintf("localhost:%d", xfer.ProbePort), fmt.Sprintf("scope.weave.local:%d", xfer.ProbePort)}
logfile = flag.String("log", "stderr", "stderr, syslog, or filename")
probes = flag.String("probes", strings.Join(defaultProbes, ","), "list of probe endpoints, comma separated")
batch = flag.Duration("batch", 1*time.Second, "batch interval")
window = flag.Duration("window", 15*time.Second, "window")
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
)
flag.Parse()
probes := append(defaultProbes, flag.Args()...)

switch *logfile {
case "stderr":
Expand Down Expand Up @@ -62,7 +61,7 @@ func main() {
c := xfer.NewCollector(*batch)
defer c.Stop()

r := NewResolver(strings.Split(*probes, ","), c.AddAddress)
r := NewResolver(probes, c.AddAddress)
defer r.Stop()

lifo := NewReportLIFO(c, *window)
Expand Down
40 changes: 32 additions & 8 deletions app/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package main
import (
"log"
"net"
"strconv"
"strings"
"time"

"github.com/weaveworks/scope/xfer"
)

var (
Expand Down Expand Up @@ -42,11 +46,22 @@ func NewResolver(peers []string, add func(string)) Resolver {
func prepareNames(strs []string) []peer {
var results []peer
for _, s := range strs {
hostname, port, err := net.SplitHostPort(s)
if err != nil {
log.Printf("invalid address %s: %v", s, err)
continue
var (
hostname string
port string
err error
)

if strings.Contains(s, ":") {
hostname, port, err = net.SplitHostPort(s)
if err != nil {
log.Printf("invalid address %s: %v", s, err)
continue
}
} else {
hostname, port = s, strconv.Itoa(xfer.ProbePort)
}

results = append(results, peer{hostname, port})
}
return results
Expand All @@ -67,10 +82,19 @@ func (r Resolver) loop() {

func (r Resolver) resolveHosts() {
for _, peer := range r.peers {
addrs, err := lookupIP(peer.hostname)
if err != nil {
log.Printf("lookup %s: %v", peer.hostname, err)
continue
var (
addrs []net.IP
err error
)

if addr := net.ParseIP(peer.hostname); addr != nil {
addrs = []net.IP{addr}
} else {
addrs, err = lookupIP(peer.hostname)
if err != nil {
log.Printf("lookup %s: %v", peer.hostname, err)
continue
}
}

for _, addr := range addrs {
Expand Down
8 changes: 8 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ if [ -n "$DNS_SERVER" -a -n "$SEARCHPATH" ]; then
echo "nameserver $DNS_SERVER" >>/etc/resolv.conf
fi

# End of the command line can optionally be some
# addresses of probes to connect to, for people not
# using Weave DNS. We stick these in /etc/weave/probes
# for the run-app script to pick up.
MANUAL_PROBES=$@
mkdir -p /etc/weave
echo "$MANUAL_PROBES" >/etc/weave/probes

exec /sbin/runsvdir /etc/service
2 changes: 1 addition & 1 deletion docker/run-app
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

exec /home/weave/app
exec /home/weave/app $(cat /etc/weave/probes)
1 change: 0 additions & 1 deletion scope
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ container_ip() {
case "$COMMAND" in

launch)
[ $# -eq 0 ] || usage
check_not_running $CONTAINER_NAME $IMAGE

# If WeaveDNS is running, we want to automatically tell the scope
Expand Down

0 comments on commit a93f641

Please sign in to comment.