Skip to content

Commit

Permalink
remove proxy status
Browse files Browse the repository at this point in the history
There are two problems with obtaining the proxy status via the normal
proxy endpoint...

1. when TLS is enabled, this requires using TLS at the client end

2. the status URL is mixed in with the docker remote API, which is
rather unclean

There is limited value to having some status output from the proxy,
since all the output is constant.

So instead we log the version and command line args.

We still want a way to wait for the proxy to start up, and log a nice
error if it dies. We do this by polling the docker logs for a startup
message.

Fixes weaveworks#877. Fixes weaveworks#876.

Undoes weaveworks#756, weaveworks#800, weaveworks#854.
  • Loading branch information
rade committed Jun 8, 2015
1 parent 235acc1 commit 3dd679c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 57 deletions.
4 changes: 4 additions & 0 deletions prog/weaveproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"

"code.google.com/p/getopt"
. "github.com/weaveworks/weave/common"
Expand Down Expand Up @@ -48,6 +49,9 @@ func main() {
InitDefaultLogging(true)
}

Info.Println("weave proxy", version)
Info.Println("Command line arguments:", strings.Join(os.Args[1:], " "))

p, err := proxy.NewProxy(c)
if err != nil {
Error.Fatalf("Could not start proxy: %s", err)
Expand Down
28 changes: 1 addition & 27 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package proxy

import (
"bytes"
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"regexp"
"strings"

"github.com/fsouza/go-dockerclient"
. "github.com/weaveworks/weave/common"
Expand Down Expand Up @@ -94,9 +91,6 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
proxy.serveWithInterceptor(&startContainerInterceptor{proxy.client, proxy.WithDNS, proxy.WithIPAM}, w, r)
case execCreateRegexp.MatchString(path):
proxy.serveWithInterceptor(&createExecInterceptor{proxy.client, proxy.WithIPAM}, w, r)
case strings.HasPrefix(path, "/status"):
fmt.Fprintln(w, "weave proxy", proxy.Version)
fmt.Fprintln(w, proxy.Status())
default:
proxy.serveWithInterceptor(&nullInterceptor{}, w, r)
}
Expand All @@ -106,24 +100,6 @@ func (proxy *Proxy) serveWithInterceptor(i interceptor, w http.ResponseWriter, r
newClient(proxy.dial, i).ServeHTTP(w, r)
}

// Return status string
func (proxy *Proxy) Status() string {
var buf bytes.Buffer
fmt.Fprintln(&buf, "Listen address is", proxy.ListenAddr)
fmt.Fprintln(&buf, "Docker address is", proxy.DockerAddr)
switch {
case proxy.TLSConfig.Verify:
fmt.Fprintln(&buf, "TLS verify")
case proxy.TLSConfig.Enabled:
fmt.Fprintln(&buf, "TLS on")
default:
fmt.Fprintln(&buf, "TLS off")
}
fmt.Fprintln(&buf, "DNS", OnOff(proxy.WithDNS))
fmt.Fprintln(&buf, "IPAM", OnOff(proxy.WithIPAM))
return buf.String()
}

func (proxy *Proxy) ListenAndServe() error {
listener, err := net.Listen("tcp", proxy.ListenAddr)
if err != nil {
Expand All @@ -132,11 +108,9 @@ func (proxy *Proxy) ListenAndServe() error {

if proxy.TLSConfig.enabled() {
listener = tls.NewListener(listener, proxy.TLSConfig.Config)
Info.Println("TLS Enabled")
}

Info.Printf("Listening on %s", proxy.ListenAddr)
Info.Printf("Proxying %s", proxy.DockerAddr)
Info.Println("proxy listening")

return (&http.Server{Handler: proxy}).Serve(listener)
}
17 changes: 0 additions & 17 deletions site/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,6 @@ proxy port.

## <a name="troubleshooting"></a>Troubleshooting

The command

weave status

reports on the current status of various weave components, including
the proxy:

````
...
weave proxy git-03ede29e7ee4
Listen address is :12375
Docker address is unix:///var/run/docker.sock
TLS off
DNS off
IPAM off
````

Information on the operation of the proxy can be obtained from the
weaveproxy container logs with

Expand Down
5 changes: 2 additions & 3 deletions site/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ what went wrong the last time; whether it is attempting to connect or
is waiting for a while before connecting again.

There may also be further sections for the
[IP address allocator](ipam.html#troubleshooting),
[weaveDNS](weavedns.html#troubleshooting), and
[proxy](proxy.html#troubleshooting).
[IP address allocator](ipam.html#troubleshooting), and
[weaveDNS](weavedns.html#troubleshooting).

### <a name="list-attached-containers"></a>List attached containers

Expand Down
28 changes: 18 additions & 10 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,12 @@ http_call() {
http_call_ip $CONTAINER_IP "$@"
}

# Wait until container $1 on IP $2, port $3 is alive enough to respond
# to its status call
wait_for_status_ip() {
# Wait until container $1 is alive enough to respond to "GET /status"
# http request on its docker-assigned IP, port $2
wait_for_status() {
container_ip $1 "$1 container has died." "$1 container has died." || return 1
while true ; do
http_call_ip $2 $3 GET /status >/dev/null && return 0
http_call_ip $CONTAINER_IP $2 GET /status >/dev/null && return 0
if ! container_id $1 >/dev/null 2>&1 ; then
echo "$1 container has died." >&2
return 1
Expand All @@ -575,9 +576,18 @@ wait_for_status_ip() {
done
}

wait_for_status() {
container_ip $1 "$1 container has died." "$1 container has died." || return 1
wait_for_status_ip $1 $CONTAINER_IP $2
# Wait until container $1 outputs a line containing $2 in its log
wait_for_log() {
while true ; do
if docker logs $1 2>/dev/null | grep -q "$2" ; then
return 0
fi
if ! container_id $1 >/dev/null 2>&1 ; then
echo "$1 container has died." >&2
return 1
fi
sleep 1
done
}

# Call $1 for all containers, passing container ID, all MACs and all IPs
Expand Down Expand Up @@ -940,7 +950,7 @@ case "$COMMAND" in
-e PROCFS=/hostproc \
--entrypoint=/home/weave/weaveproxy \
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS)
wait_for_status_ip $PROXY_CONTAINER_NAME 127.0.0.1 $PROXY_PORT
wait_for_log $PROXY_CONTAINER_NAME "proxy listening"
echo $PROXY_CONTAINER
;;
connect)
Expand All @@ -960,8 +970,6 @@ case "$COMMAND" in
http_call $CONTAINER_NAME $HTTP_PORT GET /status || res=1
echo
http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status 2>/dev/null || true
echo
http_call_ip 127.0.0.1 $PROXY_PORT GET /status 2>/dev/null || true
[ $res -eq 0 ]
;;
ps)
Expand Down

0 comments on commit 3dd679c

Please sign in to comment.